Tool/software: TI C/C++ Compiler
I have a small routine that runs in RAM to copy the firmware image from one FRAM section to another during firmware upgrade. This all works fine until I compile with -O4 (Whole Program Optimizations). I'm using the TI compiler v18.12.1.LTS
Definition in linker command file:
.firmware_copy: load =FRAM, LOAD_START(firmware_copy_load_start),LOAD_SIZE(firmware_copy_load_size) run = RAM, RUN_START(firmware_copy_run_start)
Ram run copy code:
__attribute__((section (".firmware_copy")))
void copy_firmware_ram_run()
{
UINT16 i;
UINT16* to;
UINT16* from;
//UNLOCK the FRAM
uint8_t state = HWREG8(SYS_BASE + OFS_SYSCFG0_L);
uint8_t wp = DFWP | PFWP;
HWREG16(SYS_BASE + OFS_SYSCFG0) = FWPW | (state & ~wp);
to=(UINT16*)&firmw_image_fram_start;
i=((UINT16)&firmw_upgr_shadow_image_fram_size)>>1; //First copy FRAM shadow (We're using WORD operations)
from=(UINT16*)&firmw_upgr_shadow_image_fram_start;
while (i--) *to++=*from++;
i=((UINT16)&firmw_upgr_shadow_image_ram_size)>>1; //Now copy RAM shadow
from=(UINT16*)&firmw_upgr_shadow_image_ram_start;
while (i--) *to++=*from++;
WDTCTL = 0xDEAD; //force reset by writing to the watchdog without the required password
}
FRAM run firmware invloking code:
void upgrade_firmware()
{
__disable_interrupt(); // Disable global interrupts
WATCHDOG_STOP();
//copy the firmware copy code from FRAM into RAM
memcpy((UINT16*)&firmware_copy_run_start, (UINT16*)&firmware_copy_load_start, (UINT16)&firmware_copy_load_size);
copy_firmware_ram_run(); //run it from RAM
//never returns here....
}
When I compile with -O3 it works, symbols are referenced properly in the MAP file and it all works ok:
00000058 firmware_copy_load_size
0000de00 firmware_copy_load_start
000022d4 firmware_copy_run_start
When I compile with -O4, the linker I assume gets rid of the LOAD section and places everyting in RAM
00000000 firmware_copy_load_size
00002000 firmware_copy_load_start
00002000 firmware_copy_run_start
Any ideas on why this is and any solution if possible? I'm running our of FRAM and would be gread if I could use -O4.
Regards
Reto