CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Quick Bootloader Question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

Quick Bootloader Question
PostPosted: Tue Jan 16, 2007 10:28 am     Reply with quote

I use the Mechanic Bootloader maily because it is the one I used for all my projects. I'm now going to try and use it with CCS on a 18F2580.

The instructions are here, but I'm not sure I understand the ORG instruction and how I should use it.

The bootloader software resides in the upper 256 words of program memory (336 words for 18Fxxx devices), with the rest of the microcontroller code space being available for your program. Because the loader resides in the upper part of program memory, it needs a way to 'jump' to the start of the bootloader code when power is first applied, or when the microcontroller is reset. To do this, it uses the first four program words (called the reset vector) to execute a jump to the bootloader code. When you program the target microcontroller using MicroCode Loader, program instructions that occupy the first four locations are automatically relocated by the bootloader. If the bootloader did not relocate these instructions, the important 'jump to bootloader' would get overwritten and the bootloader software would not start next time power was applied or the microcontroller was reset. Therefore, your program needs to be modified to support this process. It's a very simple change, with some examples shown below.

Assembler Programs
ORG 0x000
MOVLW 0x00
MOVWF PCLATH
GOTO StartOfProgram

ORG 0x0004
StartOfProgram
; your program goes here

For 18Fxxx(x) devices, use something like:
ORG 0x0000
GOTO StartOfProgram

ORG 0x0008
StartOfProgram
; your program goes here
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 12:33 pm     Reply with quote

After tons of reading, this is what I came up with. Can anyone confirm?

My boot loader uses the TOP 336 Words so in the top of my main program i do this.....

#org 0x7D60, 0x7FFF //32096 to 32767
#build(reset=0x1,interrupt=0x5)

Var Defs
Functions

Main ()
While ()
{
Do Something
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 1:55 pm     Reply with quote

If you have the bootloader in top of the memory then you don't need the #build statement, the default values are good (and yours are wrong).

Add the DEFAULT keyword to the #org statement to ensure all compiler generated functions (delay, rs232, etc) are placed in your new memory segment.

Code:
#org 0x7D60, 0x7FFF DEFAULT   //32096 to 32767

Var Defs
Functions

Main ()
While ()
{
  Do Something
}

To test this configuration compile your bootloader and study the list file (*.lst), except for the jump at address 0x0000-0x0004 there should be no code located outside your defined memory region.
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 2:00 pm     Reply with quote

#org 0x7D60, 0x7FFF {} //32096 to 32767

I thought this told the compiler not to put anything there, since that is where the loader resides?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 3:17 pm     Reply with quote

rwskinner wrote:
#org 0x7D60, 0x7FFF {} //32096 to 32767

I thought this told the compiler not to put anything there, since that is where the loader resides?
I misread your original question, my example code is to be used by the bootloader.
The #org you are showing now is for use by the application and ensures the program will not use the bootloader memory locations. I don't know your bootloader (can't find a link using Google) but I assume you can omit the #build statement for the application too.
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 3:27 pm     Reply with quote

It states that I must reserve the upper 336 words of memory for nothing but the loader. The 4 first four bytes need to be relocated in my application.

I tried what I had and it seems to work, but since I'm sending out 300 of these devices I can't afford any gotchas.

The Loader is "microcode mcloader"

http://www.mecanique.co.uk/code-studio/loader/index.html

So this is what I put in my programs header file....

Code:
#include <18F2580.h>

#FUSES HS,NOWDT,NOLVP,NOWDT 

//Uses MicroCode's MCLoader

#org 0x7D60, 0x7FFF {}  //Make 32096 to 32767 reserved
//Reserve 336 words or 672 bytes in upper memory

#build(reset=0x1, interrupt=0x5)               
#use delay(clock=20000000)


By the way, thanks for the response. I appreciate it.
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

PostPosted: Wed Jan 17, 2007 2:12 pm     Reply with quote

[quote="ckielstra"]
rwskinner wrote:
#org 0x7D60, 0x7FFF {} //32096 to 32767

I don't know your bootloader (can't find a link using Google) but I assume you can omit the #build statement for the application too.


You are correct, the boot loader appears to work fine with just the ORG statement. Using the build statement was causing CRC errors on the communication ports, most likely because of interrupts not behaving properly.

I'll continue testing it. Thanks again !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group