• AVR Freaks

code offset with MPLAB X IDE and C18 compiler.

Author
Guest
Super Member
  • Total Posts : 80502
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
2014/04/30 05:56:44 (permalink)
0

code offset with MPLAB X IDE and C18 compiler.

I am unclear how to offset my program code using the MPLAB X IDE and the C18 compiler. I want to locate my bootloader code at memory address range 0x000-0x300, and I want to offset my application code by 0x400. I seem to have seen something about using the --CODEOFFSET linker directive, but I am not sure how to use that in the linker file. Does anyone have any suggestions on how I can accomplish this.
 
Thank You
#1

2 Replies Related Threads

    jswanson
    Super Member
    • Total Posts : 367
    • Reward points : 0
    • Joined: 2003/11/07 12:44:05
    • Status: offline
    Re: code offset with MPLAB X IDE and C18 compiler. 2014/05/02 09:31:05 (permalink)
    +1 (1)
    Hi,
    I find the easiest way is:
     
    copy the start up file c018iz.c (or whatever you are using) from C18's startup directory to your project file and add it to your project.
    edit the line:
    #pragma code _entry_scn=0x000000
    to 
    #pragma code _entry_scn=0x000400
     
    Next copy the linker file eg 18f45k80_g.lkr to your project and add that to your project.
    Edit the linker and comment out the default start up file so it will use the local copy:
     
    //FILES c018i.o
    FILES clib.lib
    FILES p18f45k80.lib
     
    If you are writing a bootloader, you will need to have a fixed place for the interrupt vectors so get the bootloader code to vector them to a fixed location and then add the following:
     
    #pragma code highVector=0x0408
    void HighVector(void) {
    _asm
    goto high_isr
    _endasm
    }
    #pragma code lowVector=0x0418
    void LowVector(void) {
    _asm goto low_isr _endasm
    }
    #pragma code // Return to default code section
    #endif
     
    Then....
     
    #pragma interrupt high_isr
    void high_isr(void)
    {
    ...
    }
    #2
    Guest
    Super Member
    • Total Posts : 80502
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    Re: code offset with MPLAB X IDE and C18 compiler. 2014/05/02 10:03:48 (permalink)
    0
    Thank you for the reply. 
    That is exactly what I did after exploring the microchip DS33014L document. One additional thing I did have to do: I had to explicitly protect the bootloader memory area in the linker file to prevent it from being filled with application code. for example;  CODEPAGE NAME=bootloader   START=0x000         END=0x3FF  PROTECTED
     
    I appreciate your reply and I thank you for the assistance.
    #3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5