Microchip USB Bootloader?

General discussion on mikroC.
Author
Message
pierred35
Posts: 13
Joined: 15 Nov 2009 10:56

Re: Microchip USB Bootloader?

#31 Post by pierred35 » 08 Sep 2011 11:02

Hi gcp6ca,
Thanks a lot for your answer. I have progress yesterday night and I'm sure I not so far from the goal.
So :
- download and intall Microchip's latest Application Libraries: OK
- put the Firmware "USB Device - HID - HID Bootloader - C18 - PIC18F4550.hex" in my PIC: OK
- open the PC software is "HIDBootLoader" v2.90: OK, my pic is recognise by the software: good
- base on on of your template for 18F4553, I've tried to build the most simple programm as possible: make blinking a led on PORTE.0 just to see if I've well understand exactly how bootloader works.
My programm is: http://demo.ovh.com/fr/67f0fdc5537e8620 ... 4aae77b51/
I trie to load it in the pic using the bootloader, I have a message that tells me the operation success and I need to reset the PIC. When I reset the PIC, it enter again in the bootloader but don't lauch my programm. What is the input pin by default of the PIC that permit to select or not to enter in the bootloader mode? I think my mistake is here...

There is too a strange thing in your template: some asm code is not recognise by mikroBasic Pro and generate an error:

Code: Select all

'Remapping needed to use with boot loader
sub procedure Vectors org 0x1000
'    asm
'       goto   _main                   '0x1000
'       nop
'       nop
'       goto   _interrupt              '0x1008
'       nop
'       nop
'       nop
'       nop
'       nop
'       nop
'       goto   _interrupt_low          '0x1018
'    end asm
end sub
If you know why? or if there is a mistake somewhere?

Thanks a lot for your help. Have a good day and best regards.

Last remark: all your last comment is very usefull. It could be a good idea to integrate it in the .doc file of your libstock file for help everybody.

gcp6ca
Posts: 28
Joined: 20 Feb 2011 15:29

Re: Microchip USB Bootloader?

#32 Post by gcp6ca » 08 Sep 2011 14:26

Do not comment out or modify the Vectors procedure because it is used to redirect the Reset, Interrupt and Interrupt_Low functions. Bootloader redirect Reset from 0x0 to 0x1000, Interrupt from 0x8 to 0x1008 and Interrupt_Low from 0x18 to 0x1018.

This part of the code has no use unless you are using the custom bootloader in the template download:

Code: Select all

'Check if the reset button is pressed; if it is then goto the begging of the bootload and since it is 0 the microcontoller will go into boot loader mode
if (PORTE.0 = 0) then
              EEPROM_Write(255,85)       'Causes entry to boot loader once    <-- No effect on Microchip's original bootloader
              delay_ms(5)
              Reset()
end if
Microchip's original bootloader (and my custom one) check if RB4 is pressed on startup (logic low) and enter bootloader mode if it is pressed, otherwise it will go to your code. Make sure there is a pull-up on RB4 because Microchip's bootloader does not enable internal pull-ups at startup.

Also your configuration settings are wrong but it does not really matter because the bootloader software does not overwrite the settings (unless you select the option). When you use USB which needs 48MHz to operate, you can only run MCU at 16MHz, 24MHz, 32MHz and 48MHz which is selected from "System Clock Postscaler Option". If you choose to overwrite the bootloader configuration, you just need to make sure your "PLL Prescaled Selection" is correct and "Oscillator Selection" is HSPLL. Microchip's bootloader is configured to use 12MHz and I changed my custom one to use 8MHz.

I attached your project that I modified and a custom bootloader that uses 20MHz crystal.
Attachments
Project.zip
(176.99 KiB) Downloaded 327 times

pierred35
Posts: 13
Joined: 15 Nov 2009 10:56

Re: Microchip USB Bootloader?

#33 Post by pierred35 » 09 Sep 2011 12:54

Dear gcp6ca,
Thanks a lot for your answer: it was very useful. I've modified my board to add a pull-up resistor on RB4 and now, the bootloader works perfectly. I have load the .hex file you gave me for the "1stboot project" and it's OK.

There is still something I don't understand. When I tried to compile the template you post, mB generate an error code on the assembly section (see attached file). Do you know why? and how did you do to avoid that?

A other point, if I understand well, the configuration settings is loaded with the bootloader and can't be modify later that mean if I want to use the bootloader on different board with different speed resonator, I need to build a different bootloader to adapt it to the frequency of the resonator?! We can't use the same bootloader for all speed resonator what seams to be logic.

Thanks again for your help and your complete answer. Have a good day.
Attachments
1stboot problem.JPG
1stboot problem.JPG (122.32 KiB) Viewed 7176 times

gcp6ca
Posts: 28
Joined: 20 Feb 2011 15:29

Re: Microchip USB Bootloader?

#34 Post by gcp6ca » 09 Sep 2011 21:21

If you are using the Bootloader hex file I provided then you do not need an external interrupt because it enables the internal pull-up just before checking RB4.

I am not sure why you are getting that error message because I compiled with no problems. Are you using the latest version of mikroBasic (it v5.01)? If you still have the problem the comment out the lines and check the "Functions sorted by Address" in statistic and you should see the assembler labels for the "main", "interrupt" and "interrupt_low" (see the attached image).

Microchip expects you to re-compile the bootloader if you are using different settings, they create a solution for the demo boards they provide. In the end it does not matter because for USB you need 48MHz (system clock can be changed to 16MHz, 24MHz, 32MHz or 48MHz).

If you want to change non-system clock related configuration setting without recompiling the bootloader (you need to pay for the optimizations from MPLAB C18 - you can also use evaluation version):
  • 1) Program the default bootloader using ICSP
    2) Make a blank program with your configurations
    3) Use bootloader to program it and select program configurations
    4) Read the PIC using ICSP
    5) You now have a bootloader with your configuration settings
PIC18F4550 seems like an old MCU to use; I don't know how limited your project is but if you can switch 3.3V the PIC18F46J50 family or PIC18F47J53 family would be a good option because it can use an internal oscillator for USB. They have a lot advanced features because its design is based on PIC24 series MCUs. If would also save money because the microcontrollers are cheaper and you save money on the crystals and capacitors you would not longer need (internal accuracy is not the same as a crystal but it is still pretty good because it is being used by USB). The one downside is that they have no internal EEPROMs.
Attachments
Functions.png
Functions.png (30.67 KiB) Viewed 7173 times

pierred35
Posts: 13
Joined: 15 Nov 2009 10:56

Re: Microchip USB Bootloader?

#35 Post by pierred35 » 27 Sep 2011 12:48

Dear gcp6ca,
Thanks for your last answer. At the end, I've tried as you told me to comment some line, compile the program and check the "Functions sorted by Address" in statistic: the problem was here. I've change the name of the variable in sub procedure Vectors and I can now compile the entire program with no problem. Hope the fact that deleting the underscore in the beginning of the variable doesn't change nothing for the rest.

My code :

Code: Select all

'Remapping needed to use with boot loader
sub procedure Vectors org 0x1000
    asm
       goto   _main                   '0x1000
       nop
       nop
       goto   1stboot_interrupt       '0x1008
       nop
       nop
       nop
       nop
       nop
       nop
       goto   1stboot_interrupt_low   '0x1018
    end asm
end sub
I will continue to do some tests. Thanks again and have a good day.
Attachments
Modif_asm name.JPG
Modif_asm name.JPG (23.71 KiB) Viewed 7130 times

Tomy
Posts: 47
Joined: 25 Jun 2007 16:50

Re: Lucky Luc PICBOOT.rar

#36 Post by Tomy » 25 Jan 2013 15:13

I contacted Lucky Luc, but no reply after long time.
I want to ask if someone still have Lucky Luc PICBOOT.rar ?
If yes, please share it with us, thank you very much.

ruch.ph
Posts: 38
Joined: 22 May 2014 10:32

Re: Microchip USB Bootloader?

#37 Post by ruch.ph » 31 Oct 2014 03:48

Hi,

I just want to know where this MLK file can be located.

The one that I am seeing from this thread looks like the one below:

Code: Select all

//ROM MEMORY
#pragma    SetRomSize(32767)
#pragma    SetPage(PAGE0, 0x000808, 0x7FFF)
#pragma    SetPage(PAGE1, 0x000800, 0x830)
But what I am seeing from the C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for PIC\Defs directory is an XML file that looks like this:

Code: Select all

<ROM>
<MIN_ADDR>0x0</MIN_ADDR>
<MAX_ADDR>0xffff</MAX_ADDR>
</ROM>
Any idea?

Thanks,
Ruch

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Microchip USB Bootloader?

#38 Post by janni » 31 Oct 2014 14:07

ruch.ph wrote:Any idea?
Yeah, you're comparing files from two different compilers - the old mC and mC PRO. There isn't as much freedom for user intervention in mC PRO, if that's what you're after.

ruch.ph
Posts: 38
Joined: 22 May 2014 10:32

Re: Microchip USB Bootloader?

#39 Post by ruch.ph » 03 Nov 2014 01:57

Janni,

thanks for your reply.

What would be the alternative if the #pragma above is not available in the PRO version? I believe that ME team encouraged users to use the PRO version, so old MC is not supported anymore.

I have tried the code below and it looks like that the addresses are re-mapped in the disassembly code.

Code: Select all

void Vectors() org 0x800 {
     asm {
         goto   _main                   //main fxn remapped to 0x800
         nop
         nop
         goto   _interrupt              //high interrtupt remapped to0x808
         nop
         nop
         nop
         nop
         nop
         nop
         goto   _interrupt_low          //low interrupt remapped to 0x818
     }
}
I would like to ask for your insight if the snippet above is safe to use / no known issues, whatsoever.

Thanks,
Ruch

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Microchip USB Bootloader?

#40 Post by janni » 03 Nov 2014 11:44

ruch.ph wrote:What would be the alternative if the #pragma above is not available in the PRO version? I believe that ME team encouraged users to use the PRO version, so old MC is not supported anymore.
Indeed. As for interrupt vectors addresses in *.mlk file, they're now defined like

Code: Select all

<!-- interrut vector table. -->
	<IVT>
		<INT>
			<ADDRESS>0x000008</ADDRESS>
			<ILEVEL>0x0000</ILEVEL>
			<NAME>High Priority Interrupt</NAME>
		</INT>
		<INT>
			<ADDRESS>0x000018</ADDRESS>
			<ILEVEL>0x0001</ILEVEL>
			<NAME>Low Priority Interrupt</NAME>
		</INT>
	</IVT>
but if one changes these addresses, compiler inserts lots of NOPs from address 0 to first interrupt vector. And the reset vector stays at address 0 (attempts to change code start address result in compiler error) :( .
I have tried the code below and it looks like that the addresses are re-mapped in the disassembly code.

Code: Select all

void Vectors() org 0x800 {
     asm {
         goto   _main                   //main fxn remapped to 0x800
         nop
         nop
         goto   _interrupt              //high interrtupt remapped to0x808
         nop
         nop
         nop
         nop
         nop
         nop
         goto   _interrupt_low          //low interrupt remapped to 0x818
     }
}
Yes, this works (provided one remembers to place it after main or add a prototype of main, about which I lately forgotten - spoiled by mP and mB :oops: ). Safer version of vector table is filled with jumps to reset vector instead of NOPs

Code: Select all

   asm {
        goto _main
        goto 0
        goto _interrupt
        goto 0
        goto 0
        goto 0
        goto _interrupt_low
   }
And instead of including a call to the vector table, like gcp6ca did in the post you're referring to

Code: Select all

//ASM Command to avoid optimization which ensures Vectors will be remapped correctly
     asm { goto Skip_Vectors }
     Vectors();
     asm { Skip_Vectors: }
one may use

Code: Select all

#pragma funcall main Vectors
informing linker to keep Vectors function though it's not called directly.

ruch.ph
Posts: 38
Joined: 22 May 2014 10:32

Re: Microchip USB Bootloader?

#41 Post by ruch.ph » 06 Nov 2014 03:16

Hi janni,

Thank you! My initial tests shows that your solution works!

I must say that the #pragma funcall directive is much easier to the eye than the asm goto call. :)

Best Regards,
Ruch

Post Reply

Return to “mikroC General”