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

CCS create .hex file with multiple vector tables?

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



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

CCS create .hex file with multiple vector tables?
PostPosted: Fri Dec 20, 2019 10:00 am     Reply with quote

For my bootloader project, I create the bootloader as one .hex file, and the application as a second .hex file.

For manufacturing, I want to give them one .hex file that will contain both.

I can manually merge and create a file and use a tool I wrote to fix the CRC line at the end:

;CRC=XXXX

...but I wondered if there was a trick to get the compiler to do it.

When I build the application file, I use #build/#org statements to cause it to skip the bootloader area of flash and relocate the vector table, something like this:
Code:
#BUILD (RESET=APP_A_ADDRESS)            // Set A Reset vector location.
#BUILD (INTERRUPT=APP_A_ADDRESS+0x8)    // Set A Interrupt vector lopcation.
#ORG 0x0, APP_A_ADDRESS-1 {}            // Don't use Bootloader partition.
#ORG APP_B_ADDRESS, FLASH_SIZE-1 {}     // Don't use B partition.

The bootloader project basically uses defaults (vector table at 0) though I did add an #org that blocks out the application area, so it prevents the build from being too large.

I did some experiments trying to move these into separate files and build them together using multi-unit compile, but it is not getting me the result I want.

Does anyone know if this is even possible?
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Fri Dec 20, 2019 1:31 pm     Reply with quote

You can #import the second set of code.
Honestly easiest way in general is just to load both sequentially in
the programming software, then export the result.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 20, 2019 2:51 pm     Reply with quote

Several forum posts answer this topic. The newer and
better answers (expanding on Ttelmah's reply) are in
the first two below:

Yet Another Bootloader Question -
http://www.ccsinfo.com/forum/viewtopic.php?t=55676

#import to combine bootloader with application code -
http://www.ccsinfo.com/forum/viewtopic.php?t=55241

Combining 3 .hex files into one.
http://www.ccsinfo.com/forum/viewtopic.php?t=55206

1 hexfile containing all : bootloader, program, eeprom -
http://www.ccsinfo.com/forum/viewtopic.php?t=38730

Creating a combined HEX file -
http://www.ccsinfo.com/forum/viewtopic.php?t=29606
jeremiah



Joined: 20 Jul 2010
Posts: 1320

View user's profile Send private message

PostPosted: Fri Dec 20, 2019 7:27 pm     Reply with quote

Just to give kind of a minimal example:
Bootloader:
Code:

#include <24fj64ga004.h>
#FUSES NODEBUG
#use delay(crystal=8000000)

// Define start of application
#define APPLICATION_START 0x800
#define APPLICATION_STOP  (getenv("PROGRAM_MEMORY")-1)

// Add IVT jump table
#INT_DEFAULT FAST
void isr_relocate(){
   jump_to_isr(APPLICATION_START+4);
}

//prevent bootloader from putting code in application space
#org APPLICATION_START, APPLICATION_STOP {}

void main(void)
{
   #asm
      BRA APPLICATION_START
   #endasm
   while(TRUE);
}




Application
Code:

#include <24fj64ga004.h>
#FUSES NONE  //NO FUSES!
#use delay(clock=8000000)  //Make sure #use delay doesn't put any FUSES either

// Define start of application
#define APPLICATION_START 0x800

// Tell compiler to put code in application space
#build(reset=APPLICATION_START,interrupt=APPLICATION_START+4)

// Tell compiler not to use bootloader space
#org 0,APPLICATION_START-1{}

void main(void)
{

   while(TRUE);
}


Combined using IMPORT:
Code:

#include <24fj64ga004.h>
#FUSES NODEBUG
#use delay(crystal=8000000)

// Define start of application
#define APPLICATION_START 0x800
#define APPLICATION_STOP  (getenv("PROGRAM_MEMORY")-1)

// Add IVT jump table
#INT_DEFAULT FAST
void isr_relocate(){
   jump_to_isr(APPLICATION_START+4);
}

//Import default application and reserve all of the application space
#import(HEX,FILE=application.hex,RANGE=APPLICATION_START:APPLICATION_STOP)

void main(void)
{
   #asm
      BRA APPLICATION_START
   #endasm
   while(TRUE);
}




Here are the respective hex files:
Bootloader:
Code:

Program Memory
   000000: 00040206 00000000
   000006: 00000808
   000008: 0000080C 00000810 00000814 00000818
   000010: 0000081C 00000820 00000824 00000828
   000018: 0000082C 00000830 00000834 00000838
   000020: 0000083C 00000840 00000844 00000848
   000028: 0000084C 00000850 00000854 00000858
   000030: 0000085C 00000860 00000864 00000868
   000038: 0000086C 00000870 00000874 00000878
   000040: 0000087C 00000880 00000884 00000888
   000048: 0000088C 00000890 00000894 00000898
   000050: 0000089C 000008A0 000008A4 000008A8
   000058: 000008AC 000008B0 000008B4 000008B8
   000060: 000008BC 000008C0 000008C4 000008C8
   000068: 000008CC 000008D0 000008D4 000008D8
   000070: 000008DC 000008E0 000008E4 000008E8
   000078: 000008EC 000008F0 000008F4 000008F8
   000080: 000008FC 00000900 00000904 00000908
   000088: 0000090C 00000910 00000914 00000918
   000090: 0000091C 00000920 00000924 00000928
   000098: 0000092C 00000930 00000934 00000938
   0000A0: 0000093C 00000940 00000944 00000948
   0000A8: 0000094C 00000950 00000954 00000958
   0000B0: 0000095C 00000960 00000964 00000968
   0000B8: 0000096C 00000970 00000974 00000978
   0000C0: 0000097C 00000980 00000984 00000988
   0000C8: 0000098C 00000990 00000994 00000998
   0000D0: 0000099C 000009A0 000009A4 000009A8
   0000D8: 000009AC 000009B0 000009B4 000009B8
   0000E0: 000009BC 000009C0 000009C4 000009C8
   0000E8: 000009CC 000009D0 000009D4 000009D8
   0000F0: 000009DC 000009E0 000009E4 000009E8
   0000F8: 000009EC 000009F0 000009F4 000009F8
   000200: 00FEA000 00FE8000 00064000 0022780F
   000208: 00227FF0 00B7A020 00000000 00A8E081
   000210: 00EF2744 00EFA32C 003702F5 0037FFFF
   000218: 00FE4000

Configuration Words
   00ABFC: FF00FAD5 FF003F7F



Application:
Code:

Program Memory
   000800: 000409FC 00000000
   0009FC: 0022780F 00227FF0
   000A00: 00B7A020 00000000 00A8E081 00EFA32C
   000A08: 0037FFFF 00FE4000



Combined:
Code:

Program Memory
   000000: 00040206 00000000
   000006: 00000808
   000008: 0000080C 00000810 00000814 00000818
   000010: 0000081C 00000820 00000824 00000828
   000018: 0000082C 00000830 00000834 00000838
   000020: 0000083C 00000840 00000844 00000848
   000028: 0000084C 00000850 00000854 00000858
   000030: 0000085C 00000860 00000864 00000868
   000038: 0000086C 00000870 00000874 00000878
   000040: 0000087C 00000880 00000884 00000888
   000048: 0000088C 00000890 00000894 00000898
   000050: 0000089C 000008A0 000008A4 000008A8
   000058: 000008AC 000008B0 000008B4 000008B8
   000060: 000008BC 000008C0 000008C4 000008C8
   000068: 000008CC 000008D0 000008D4 000008D8
   000070: 000008DC 000008E0 000008E4 000008E8
   000078: 000008EC 000008F0 000008F4 000008F8
   000080: 000008FC 00000900 00000904 00000908
   000088: 0000090C 00000910 00000914 00000918
   000090: 0000091C 00000920 00000924 00000928
   000098: 0000092C 00000930 00000934 00000938
   0000A0: 0000093C 00000940 00000944 00000948
   0000A8: 0000094C 00000950 00000954 00000958
   0000B0: 0000095C 00000960 00000964 00000968
   0000B8: 0000096C 00000970 00000974 00000978
   0000C0: 0000097C 00000980 00000984 00000988
   0000C8: 0000098C 00000990 00000994 00000998
   0000D0: 0000099C 000009A0 000009A4 000009A8
   0000D8: 000009AC 000009B0 000009B4 000009B8
   0000E0: 000009BC 000009C0 000009C4 000009C8
   0000E8: 000009CC 000009D0 000009D4 000009D8
   0000F0: 000009DC 000009E0 000009E4 000009E8
   0000F8: 000009EC 000009F0 000009F4 000009F8
   000200: 00FEA000 00FE8000 00064000 0022780F
   000208: 00227FF0 00B7A020 00000000 00A8E081
   000210: 00EF2744 00EFA32C 003702F5 0037FFFF
   000218: 00FE4000
   000800: 000409FC 00000000
   0009FC: 0022780F 00227FF0
   000A00: 00B7A020 00000000 00A8E081 00EFA32C
   000A08: 0037FFFF 00FE4000

Configuration Words
   00ABFC: FF00FAD5 FF003F7F



compiled using 5.078

Note that for simplicity I choose APPLICATION _STOP as the end of program memory, but in reality you can't have the application on the last page since the fuses reside there. The actual math would require calculating the address of the start of the last page and setting APPLICATION_STOP to that minus 1.

Important tips for the bootloader:
1. use #int_default with jump_to_isr() to generate the IVT jump table....not really documented well by CCS but that's how
2. You either need to #org out the application space or #import in a default application to reserve that space from the bootloader

Important tips for application:
1. use #FUSES NONE to avoid overwriting the fuses
2. in the #use delay() use "clock=" instead of other options to avoid having it also adjust the fuses
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Dec 30, 2019 3:28 pm     Reply with quote

Ttelmah wrote:
You can #import the second set of code.
Honestly easiest way in general is just to load both sequentially in
the programming software, then export the result.


Ah, I didn't know it could do that. I'll go check for command line options. Thanks!
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Dec 30, 2019 3:33 pm     Reply with quote

jeremiah wrote:
Just to give kind of a minimal example:


Most helpful. Thanks.

I still want to be able to manually build the application separately, so I am going to play with this and make a third project that uses #import to pull in the first two. Maybe.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
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