How do I specify flash location of code+data (Bootloader)

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

How do I specify flash location of code+data (Bootloader)

Postby Jesse Gordon » Fri Apr 29, 2022 3:21 am

Good day!

I'm using PIC18F47K42, XC8, MPLABX

What I'm intending to do is have a simple bootloader coded in either assembly or fully self-contained simple C at the top of main() (or in a function called first thing from main()) which I wish to reside reside in, let's say, 0x0000-0x03FF (boot block.)

Then all the rest of everything else I want at or above 0x0400.

Is there a pragma or something I can put before and after my bootloader code to plant it in 0-3ff and everything else above 3ff?

Yes, I do know that the reset vector is in the boot block, and so will be the default interrupt vectors, and will need forwarder GOTOs at those, or perhaps on this model I can change IVTBASE to a new vector above 3ff on the fly.

And yes, I do know that this is not normally how bootloaders are done, and I have done them the normal way but I would really enjoy trying it this way this time if I might be able.

It is a multi-file project with a handful of .h and .c files and a fair number of functions.

Thank you very much,

Jesse

UPDATE: I'm thinking this may not work. I tried void bootloader(void) __at(0) and it complains that it overlaps segment "reset vec." I'll probably have to do it the old fashioned way, but if any of you have ideas I'm still certainly happy to hear them!
Jesse Gordon
 
Posts: 1
Joined: Sun Feb 20, 2022 2:49 am

Re: How do I specify flash location of code+data (Bootloader

Postby JPortici » Tue Jun 07, 2022 1:13 pm

This is how i do bootloader projects for 8bit parts.
There are two distinct projects, one for the bootloader and one for the application.
Let's say the application start at 0x2000, then the bootloader project will have the rom range 0-1fff (in the project configuration, XC8, linker, memory model)
Going to the application is just an
Code: Select all
asm("ljmp 0x2000")


Then, the application project is built with the codeoffset option set at 2000 (in project configuration, linker, additional options)
Then, in the application project i add as a loadable project the bootloader.
Compiling and executing (even debugging) just works. compiling will produce two hex files, the one for the application and the combined bootloader-application hex.

Regarding interrupts, if you are using the IVT you don't have to do anything. you can even run interrupts in the bootloader and interrupts in the application without thinking about it, as when you enter the application IVTBASE is adjusted accordingly.
If you are not using the IVT, i also add in the bootloader project a small *.s file containing exactly this
Code: Select all
psect HiVector,class=CODE,delta=1,abs
org 0x08
    goto 0x2008

psect LoVector,class=CODE,delta=1,abs
org 0x18
    goto 0x2018

end
JPortici
 
Posts: 5
Joined: Tue Jul 19, 2016 9:40 am
PIC experience: Professional 1+ years with MCHP products


Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 10 guests

cron