Some notes on using the bootloader code...

General discussion on mikroBasic.
Post Reply
Author
Message
Jack Flanders
Posts: 337
Joined: 17 Apr 2008 02:53
Location: Fantasy Land

Some notes on using the bootloader code...

#1 Post by Jack Flanders » 28 Apr 2008 18:39

Me: ever so slightly less of a newby today. :D

I just tried out the bootloader from the mikroBasic example code in the directory:
(found on my machine at:
C:\Program Files\Mikroelektronika\mikroBasic\Examples\EasyPIC4\extra examples\Bootloader\P18\32K)

My hardware is a '4520 chip in a Sparkfun development board I had purchased just prior to finding out about mikroElektronika. I have a Microchip ICD2 for burning code. Eventually everything worked out but of course, I managed to stumble along the way to the finish line! Possibly some of my notes may help other newbys.

1. First you need to find the bootloader code. It's in the install directory for mikroBasic. My chip has 32K of program memory so I chose the 32K directory as shown above. Go to the directory that has the right code for you and *MAKE A BACKUP*. Why? Because in the next step, you are going to modify and compile it. If something goes wrong, it might be nice to be able to see their original code.

2. Open the project file in the directory of choice. Read the notes and look at the code. There's a few lines that show how to set the baud rate based on the crystal frequency you are using. Edit the line:
Susart_Init(51)
and replace "51" with the right constant for your crystal. My board runs at 20MHz so I used 129 as shown in the code example.

Before compiling, don't make my mistake. Edit the project file (Project/edit project... Shift+Ctrl+E) and set the config values to what you need. I didn't do this :oops: and I think the wrong oscillator value got defaulted to. When the code ran, the chars output from the uart were garbage. Consistant garbage but garbage none the less. Being consistant was a clue that the clock was at the wrong frequency. The one change I made was to select HS oscillator mode.

3. Compile the code and burn it into your target system.

4. Now close the bootloader project, open your project with the code you want to run in your PIC and compile that code.

Click on Tools/mikroBootloader to open the window with the bootloader controls. Here's where things get interesting and where it may look like abject failure even though everything is correct. To proceed, plug in your RS232 cable. This assumes your target system has a working RS232 interface such as a MAX232 chip or some equivalent. Plug the other end of the cable into your PC and make sure you know what the COM port number is.

In the mikroBootloader control panel, click on SETUP PORT. Choose the right port and 9600 baud rate then close the dialog box. Click on CONNECT and notice a quick succession of messages that indicate no comms were established:

Msg: Waiting for response from PIC..
Timeout expired.
Disconnected.

Now remember that you need to restart your target hardware first and then connect. The notes say you have 5 seconds to do this. On my system, I would estimate the time to be around 1 second, maybe less. Why this was not 5 seconds, I don't know. But it makes connecting to the target system... interesting.

5. Since I could not at first connect, I decided to check the output of the target 232 port. I used "Brays RS232 Terminal Program". Resetting the target system showed two lines of the character "g" (can't remember if it is "g" or "G") then nothing. Those two lines don't take long to show up and then the target seeing no bootloader action starts the application program which is non-existant at this point.

(Here is how I found the config settings were wrong by the way. No "g" was showing up; instead, I got something like "0", "252", and "255" or similar repeating).

Ok, time to get synchronized. Close Brays terminal program, open the bootloader dialog, put the mouse on the connect button, alt-tab to MPLAB, type sequence of keys to release the reset pin on via the ICD2 device, quickly alt-tab back to the bootloader and click on connect: BINGO! Connected.

Open hex file, start bootloader. When done, reset target system and see blinking LED!!! Yay.

Now that I don't need the ICD2, I will install a reset switch I can press with my left hand just a bit ahead of clicking on connect with my right hand and make the connecting work a little better.

I hope this helps anyone having troubles getting started with the bootloader. Having a real reset pushbutton on the target system will definitely help.

If any of the local guru's see anything above that needs correcting, please respond. Have fun!

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Some notes on using the bootloader code...

#2 Post by zristic » 05 May 2008 07:48

Thanks Jack, this is useful indeed.

User avatar
milan
mikroElektronika team
Posts: 1013
Joined: 04 May 2006 16:36
Contact:

#3 Post by milan » 07 May 2008 13:09

Hi,

we released new version of mikroBasic :

http://www.mikroe.com/forum/viewtopic.php?t=14795

nad we made bootloaders much simpler.

Now, you don't need step2, you can set baudrate directly.

saim45
Posts: 1
Joined: 01 Aug 2013 08:11

Re: Some notes on using the bootloader code...

#4 Post by saim45 » 01 Aug 2013 09:02

Bootloader is a piece of code that is executed once the system is booted. It is 512 byte long code which resides on 1st sector of booting device .
saim45

Post Reply

Return to “mikroBasic General”