bootloader and USB Connection

General discussion on mikroC.
Author
Message
trirath
Posts: 22
Joined: 03 Jul 2008 05:28

bootloader and USB Connection

#1 Post by trirath » 20 Feb 2009 16:12

Hi All

Please tell me how the step of to do bootloader and how to do let PIC18F4550 Connectionnto Pc via USB.

I tried to search a ton www,Microchip, etc but no web site able to cleared for me.

Anyway,Don't paste link for me.I have read them any more and more than you think.

I like someone who expert and can be teach me just like a baby.

w7ami
Posts: 111
Joined: 21 Aug 2008 00:08
Location: Idaho

#2 Post by w7ami » 24 Feb 2009 20:22

I'm not an expert but I will try to help you.

Step 1. Go to Microchip's webpage and download MCHPFSUSB 2.3 and install it on your PC. I know you didn't want a link but here it is anyway.

http://www.microchip.com/stellent/idcpl ... m=en534494

Once it is installed navigate to the following directory on your PC

C:\Microchip Solutions\USB Device - Bootloaders

Note that there are two different bootloaders available. Since I am more familiar with the HID Bootloader lets use than one. If you want to use the vendor class bootloader you should be able to make the switch once you understand how the HID bootloader works. The most important difference between the two is the size of the bootloader itself. The vendor class is 0x800 bytes and the HID bootloader is 0x1000 bytes. This will impact several settings you will need to make in MikroC when you set up your project.

Step 2. Since you are using the 18F4550 you will use the code in the "Firmware for PIC18 Non-J Devices" folder. If you need to change the bootloader in any way then you must also download the student version of the C18 compiler. It has a 60 day license which should be enough time to compile what you need. Once the licence expires code optimization is turned off and your resulting files will be too large to fit into the space reserved for it on the PIC. Changes that you might need to make would include the configuration fuses if you use a different oscillator configuration than what Microchip uses on their board. Note that you are very limited in the changes you can make to the bootloader. It is very close to the maximum size already and its easy to make it too large. If this happens you will get a compilier error.

Step3. Use the pre compiled bootloader or compile your own and use your normal PIC loader to put the code on the PIC. Check to see if the bootloader is running on your PIC. The bootloader alternately flashes two LEDs when it is working. If you don't have the LEDs on your board you can connect your board to the USB port on your PC and then run HIDbootloader.exe and it will tell you if it is able to connect to the bootloader that you have installed on your PIC. On Microchip's version of the bootloader you must hold pin RB4 low while you reset the PIC

This should get you started. If you can get the bootloader installed and working on your PIC you are half way there.

blips
Posts: 30
Joined: 11 Nov 2007 22:28

#3 Post by blips » 04 Mar 2009 00:57

I followed your instructions and got the boot loader up and running.

But I am having trouble in the microC config, in order to give a correct hex output.
How do you set up the project in microC? f.x. a program það blinks PORTB when the clock is an 8 MHz xtal.. a.k.a the easypic4 board.

w7ami
Posts: 111
Joined: 21 Aug 2008 00:08
Location: Idaho

#4 Post by w7ami » 04 Mar 2009 02:28

Very good. Getting the bootloader up and running is a major part of the battle.

The next step is to get your project running on your PIC without the bootloader. If it doesn't work without the bootloader you have no hope of making it work with the bootloader.

For information on setting up the project see this link...
http://www.mikroe.com/forum/viewtopic.p ... =usb+clock

Since you are using an 8 MHz crystal you will need to use Set _PLL_DIV2_1L. This will divide your 8 MHz crystal down to the 4 MHz input required by the PLL.

You will need to load your hex code over the top of the bootloader at first until you know you have hex code that works. Don't worry it is easy to reload the bootloader once your projecct is working and you are ready for the next steps.

Once you have verified that your project hex code is good you will need to make a few simple changes so that your code will work with the bootloader.

First, at the top of your project rename your main function main_thread and add the following code so that it looks like this...

Code: Select all

void main()  org 0x1000 {

   main_thread();
   
}

void main_thread() {

  INSERT YOUR CODE HERE

}

Then open the P18F4550.mlk file and edit the section under //ROM MEMORY so that it looks like this...

Code: Select all

//ROM MEMORY
#pragma    SetRomSize(32767)
//#pragma    SetPage(PAGE0, 0x000008, 0x7FFF)

//ROM MEMORY for Boot Loader
#pragma    SetPage(PAGE0, 0x001008, 0x7FFF)
#pragma    SetPage(PAGE1, 0x001000, 0x7FFF)
I commented out the original SetPage line rather than deleting it so that it is easy to revert back by simply un commenting the orginal line and commenting out the two new lines. That makes it easy to switch back and forth as needed.

With these changes made you are now ready to compile your project again. When you have compilied it open the code with a text editor and it will look like this at the top

Code: Select all

:1000000000EF08F0FFFFFFFFFFFFFFFFFFFFFFFF15
:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0
:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0
:10003000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0

<lines deleted to keep down the size of the post no need to >
, actually delete them in your code >

:100FF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF01
:101000006FEC1CF0FFD7FFFF02C0DCF101C0DBF189
:1010100000C0DAF1E9CFCFF1EACFD0F1E1CFD1F1E1
:10102000E2CFD2F18CEC1DF0016AF2B4012A01503A
:10103000010A05E1010E246ECE0ED66EF294016A0D
:10104000A1B2012A0150010A0BE12550010A03E176
:1010500054EC14F005D0A60EB26E150EB36EA1922C
:10106000CFC1E9FFD0C1EAFFD1C1E1FFD2C1E2FFA8
:10107000DCC102F0DBC101F0DAC100F01100818CAB
Now you need to add the following line at the top of the hex file on a line by itself.
:020000040000FA so that your code looks like this...

Code: Select all

:020000040000FA
:1000000000EF08F0FFFFFFFFFFFFFFFFFFFFFFFF15
:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0
:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0
:10003000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0 
Save the modified hex and you are ready to load it onto your PIC with the bootloader.

And now for the final steps.

Reload the bootloader code onto your PIC, hold pin RA.6 low and then plug in the USB cable. Next run the bootloader program that Microchip included. It should be located here...
"C:\Microchip Solutions\USB Device - Bootloaders\HID - Bootloader\HIDBootLoader.exe"

If it says "Device Attached" you are ready to click the open Hex File button and navigate to your modified hex code and select your hex file. Then click "Program/Verify" and your code will be loaded onto the PIC. Remove your jumper and click "Reset Device" and your project should come up running.

Goog Luck, Terry



[/code]

trirath
Posts: 22
Joined: 03 Jul 2008 05:28

Trirath

#5 Post by trirath » 05 Mar 2009 11:18

Many thank w7ami.I just see a light from you.
I have a stupid quotation like this.

1) If we no need to use USB Port of PIC,Is this bootloader no need too?
(Becuase i alway run my program work properly without USB Bootloader)
2) What differrent between bootloader of 16F877A(Founded in WWW) and USB bootloader for PIC 18F 4550?And Why?
3) Since i start learning with 16F877A i never use bootloader, am i wrong?
Many thank again

w7ami
Posts: 111
Joined: 21 Aug 2008 00:08
Location: Idaho

#6 Post by w7ami » 06 Mar 2009 20:18

1) If we no need to use USB Port of PIC,Is this bootloader no need too?
You certainly don't need to bother with the USB bootloader I described. Bootloaders can be a good way to send firmware updates to an end user. They can use the bootloader to install the firmware via a USB or serial port with out the need for a PIC programmer. Mikroelectronica provides a working serial bootloader example if you want to try serial bootloaders for some reason.
3) Since i start learning with 16F877A i never use bootloader, am i wrong?
No you are not wrong. This is a great way to learn PIC programming. I didn't start to use a bootloader until an application I created required the ability for the end user to change firmware without the use of a PIC programmer. I can send him the hex code and have him install it. He doesn't need a programmer and he doesn't need to send the boards back to me to be updated.

Terry

trirath
Posts: 22
Joined: 03 Jul 2008 05:28

#7 Post by trirath » 07 Mar 2009 08:41

Hi w7ami,
I finished bootloader thank for all.
I tried to follow your to modify P18F4550.mlk
also added as below on top of editor and changing existng void main(void) to be void main_thread() just like you comment.


void main() org 0x1000 {
main_thread();
}
void main_thread() {
INSERT YOUR CODE HERE
}

After,complier in MikroC massage show "Undeclared Identifier [main_thread] in expresion Massage no24.

remind ,Exisitng program work properly.

Thank you
trirath

trirath
Posts: 22
Joined: 03 Jul 2008 05:28

#8 Post by trirath » 07 Mar 2009 11:26

Hi w7ami,

It work!,i forget declared it to be prototype first.
Oncething,
1) what is :020000040000FA
2) i founded some program show me
"Routine exceeds page boudaries 4096" How to fixed?
If i know this program is too bigger sides.But i still concern.because i used to them for the first 16F877A complier around 1.5K but if i complier for 18F4550(Before modify 18F4550.mlk) will get around 3K.also 18F4550 is 32 K Program memory.

Thank you
trirath




Thank you.

w7ami
Posts: 111
Joined: 21 Aug 2008 00:08
Location: Idaho

#9 Post by w7ami » 07 Mar 2009 18:50

Congratulations on getting it running!
1) what is :020000040000FA
This indicates that the compiler is generating I32HEX format .hex files and that is what the bootloader is expecting to deal with. It would be nice if MikroC had a switch that would add this automatically when you needed it instead of having to modify the hex by hand. I guess I should write a VB app to do that for me I just haven't had the time yet. For more info try searching for ":020000040000FA" on the Microchip Developers Forums. http://www.microchip.com/forums/
There is a lot of good info on these forums about Microchip PICs.
2) i founded some program show me
"Routine exceeds page boudaries 4096" How to fixed?
If i know this program is too bigger sides.But i still concern.because i used to them for the first 16F877A complier around 1.5K but if i complier for 18F4550(Before modify 18F4550.mlk) will get around 3K.also 18F4550 is 32 K Program memory.
I'm not sure what is happening here. This might be a good topic for a new thread.

Terry

host88
Posts: 23
Joined: 28 Oct 2008 22:36

#10 Post by host88 » 22 Mar 2009 22:52

Thanks for the tutorial w7ami, I've been looking for this.
This thread should be moved to the FAQ.

Thiliniv
Posts: 7
Joined: 08 Apr 2010 12:11

Re: bootloader and USB Connection

#11 Post by Thiliniv » 08 Apr 2010 12:21

Hi,

I downloaded the bootloader " Download Shane Tolmie PIC16F87xA bootloader v9-60." from the following site

http://www.microchipc.com/PIC16bootload ... oadWindows.

I am using serial port to communicate between PIC16F877A MCU and PC. Can you please suggest what are the modifications I need to do in my "mikro C " code.

Further in the bootloader website , they have asked to reserve space for the bootloader. I have no idea , how to do that in "mikro C" . pls help. thanx.

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: bootloader and USB Connection

#12 Post by phil31 » 31 May 2010 00:57

Hi w7ami / Terry and everybody,

i have write a soft who work perfect when i upload with my IC2.

now i plan to add the Microchip USB HID bootloader.
i found this topic : thanks, great help.

i have modified the bootloader to work with my hardware. it work fine, the PC see my board and the bootloader blink the 2 LEDs :)
i use the PIC18F67J50 and MikroBASIC 7.0.0.3
i modify the mlk file like this :

Code: Select all

//------------------------------------------------------ stuff for bootloader
//ROM MEMORY
//#pragma    SetRomSize(131071)
//#pragma   SetPage(PAGE0, 0x000008, 0x1FFFF)

//ROM MEMORY FOR USB BOOTLOADER
#pragma    SetRomSize(131071)
#pragma   SetPage(PAGE0, 0x001008, 0x1FFFF)
#pragma   SetPage(PAGE1, 0x001018, 0x1FFFF)

//INTERRUPTS
//#pragma SetInterrupt(I0,0x000008,0)
//#pragma SetInterrupt(I1,0x000018,1)

//INTERRUPTS FOR USB BOOTLOADER
#pragma SetInterrupt(I0,0x001008,0)
#pragma SetInterrupt(I1,0x001018,1)
//------------------------------------------------------
i try with a simple "blink led" program, without any interrupt, and it work great :D


so i modify yet my soft, i upload, modify the HEX file to I32HEX format..
and nothing work !
this soft is big, with multiple interrupts ( no low interrupts, only hight priority )

Please Terry or anyelse can let me know if something is wrong in my MLK file ?

Thanks, regards

w7ami
Posts: 111
Joined: 21 Aug 2008 00:08
Location: Idaho

Re: bootloader and USB Connection

#13 Post by w7ami » 31 May 2010 01:54

How did you load the .hex file onto the PIC? Using the Microchip bootloader or directly with your PIC programmer? To work you must use the Microchip bootloader program.

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: bootloader and USB Connection

#14 Post by phil31 » 31 May 2010 10:40

my HEX file application ?.. of course with the Microchip bootloader !!
if no, why i try to use it ? ;)


my application work perfectly without the bootloader ..
i do the MLK file modifications and ORG 0x1000 int my application before recompile under MikroBASIC
and modify the hex file ( with :020000040000FA ) before upload with the bootloader ..

all seem to work except when i reset the PIC .. my application don't start !..
the boot SW had pull up .. then the bootloader try to start my application ..


do you see something wrong in my MLK file ?? ( specialy about the interrupt vector .. because with a simple LED blink program, it work perfectly .. )

thanks

EDIT :
i play back with the simple"LED blink" test ..
if i add some interrupt features, like TIMER0, it will not work anymore ..
the LED blink ONLY if all interrupts are OFF : INTCON =%00xxxxxxx and NO interrupt sub procedure in the source file.

i'm download the LED blink code with the USB bootloader ... so
1/ the USB bootloader is working
2/ the ORG0x1000 in my main soft is working ( the LED blink when no interrupt stuff )

==> i think that the problem is with the remaping interrupt vector to x1008...?
Please, what is wrong on my MLK file

w7ami
Posts: 111
Joined: 21 Aug 2008 00:08
Location: Idaho

Re: bootloader and USB Connection

#15 Post by w7ami » 31 May 2010 16:26

This is what I use when I need to compile code for use with a bootloader.

Code: Select all

//ROM MEMORY
#pragma    SetRomSize(32767)
//#pragma    SetPage(PAGE0, 0x000008, 0x7FFF)      // <------------------ add only for non boot loader version

//ROM MEMORY for Boot Loader
#pragma    SetPage(PAGE0, 0x001008, 0x7FFF)    // <------------------ add only for boot loader version
#pragma    SetPage(PAGE1, 0x001000, 0x7FFF)    // <------------------ add only for boot loader version

//INTERRUPTS
#pragma SetInterrupt(I0,0x000008,0)
#pragma SetInterrupt(I1,0x000000,1)

Also don't forget to add the org directive in your code.

Code: Select all

void main() org 0x1000 {

Post Reply

Return to “mikroC General”