Other Parts Discussed in Thread: HALCOGEN,
Tool/software:
Hi,
We want to support firmware upgrades using the CAN bootloader. Therefore the Firmware status field at location 0x10000 should be accessible through bootloader and application.
Based on the bootloader demo I managed to get the following working:
Bootloader:
- halcogen flag for ECC on flash is OFF.
- bl_link.cmd takes care of ECC
- STATUS Flag of firmware upgrade located at flash location 0x10000
Application:
- halcogen flag for ECC on flash is OFF.
- sys_link.cmd takes care of ECC
- application start at 0x10020
When the application code is all running from flash, the application works but accessing the Firmware status field crashes the application.
So from other forum posts I understand I need to move the flash driver to RAM.
I only copied the Fapi_UpdateStatusProgram function into a separate bl_flash.c fil, similar to what the bootloader isdoing.
Then I move the code into RAM using the following linker file:
--retain="*(.intvecs)"
/* USER CODE BEGIN (1) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Memory Map */
MEMORY
{
VECTORS (X) : origin=0x00010020 length=0x00000020 fill=0xFFFFFFFF
FLASH0 (RX) : origin=0x00010040 length=0x0012FFC0 fill=0xFFFFFFFF
STACKS (RW) : origin=0x08000000 length=0x00002000
RAM (RW) : origin=0x08002000 length=0x0002D000
/* USER CODE BEGIN (2) */
#if 1
ECC_VEC (R) : origin=(0xf0400000 + (start(VECTORS) >> 3))
length=(size(VECTORS) >> 3)
ECC={algorithm=algoL2R5F021, input_range=VECTORS}
ECC_FLA0 (R) : origin=(0xf0400000 + (start(FLASH0) >> 3))
length=(size(FLASH0) >> 3)
ECC={algorithm=algoL2R5F021, input_range=FLASH0 }
#endif
/* USER CODE END */
}
/* USER CODE BEGIN (3) */
ECC
{
algoL2R5F021 : address_mask = 0xfffffff8 /* Address Bits 31:3 */
hamming_mask = R4 /* Use R4/R5 build in Mask */
parity_mask = 0x0c /* Set which ECC bits are Even and Odd parity */
mirroring = F021 /* RM57Lx and TMS570LCx are build in F021 */
}
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Section Configuration */
SECTIONS
{
.intvecs : {} > VECTORS
#if 1
flashAPI:
{
.\HALCoGen\source\Fapi_UserDefinedFunctions.obj (.text,.data)
.\HALCoGen\source\bl_flash.obj (.text,.data)
--library= "c:\ti\Hercules\F021 Flash API\02.01.01\F021_API_CortexR4_BE.lib" (.text,.data)
} palign=8 load = FLASH0, run = RAM, LOAD_START(apiLoadStart), RUN_START(apiRunStart), SIZE(apiLoadSize)
#endif
.text : {} > FLASH0 /*Initialized executable code and constants*/
#if 1
.const : {} palign=8 load=FLASH0, run = RAM, LOAD_START(constLoadStart), RUN_START(constRunStart), SIZE(constLoadSize)
#endif
.cinit : {} > FLASH0 /*Initialized global and static variables*/
.pinit : {} > FLASH0
.data : {} > RAM
.bss : {} > RAM /*Uninitialized Global and static variables */
.sysmem : {} > RAM
FEE_TEXT_SECTION : {} > FLASH0
FEE_CONST_SECTION : {} > FLASH0
FEE_DATA_SECTION : {} > RAM
/* USER CODE BEGIN (4) */
/* USER CODE END */
}
In Sys_main.C I added:
extern unsigned int apiLoadStart;
extern unsigned int apiLoadSize;
extern unsigned int apiRunStart;
extern unsigned int constLoadStart;
extern unsigned int constLoadSize;
extern unsigned int constRunStart;
/* Copy the flash APIs to SRAM*/
//_copyAPI2RAM_(&apiLoadStart, &apiRunStart, &apiLoadSize);
memcpy(&apiRunStart, &apiLoadStart, (uint32)&apiLoadSize);
/* Copy the .const section */
//_copyAPI2RAM_(&constLoadStart, &constRunStart, &constLoadSize);
memcpy(&constRunStart, &constLoadStart, (uint32)&constLoadSize);
On the XL2-TLS57012 board, the red led lights up after firmware upgrade.
Any ideas on what goes wrong with moving the code from flash to ram?