2018-10-02 03:43 AM
I'm using STM32L4S5 to develop an IAP application following the example provided on STM32L4CubeV1.11.0 under STM32L476G-EVAL directory.
Following the code bellow, before jumping to the Application region, we have to check if the content of the first application addresse is in the RAM region (0x20000000 ->0x20017FFF ).
if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
{
/* Jump to user application */
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
JumpToApplication = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
JumpToApplication();
}
In our case, the RAM region in the STM32L4S5 is between 0x20000000 ->0x2002FFFF. So we have changed the check condition to :
#define RAM_START_ADDR SRAM_BASE
#define RAM_END_ADDR (RAM_START_ADDR + SRAM1_SIZE_MAX )
if ( ( (*(__IO uint32_t*)APP_START_ADDR) > RAM_START_ADDR ) && ( (*(__IO uint32_t*)APP_START_ADDR) < RAM_END_ADDR ) )
Does this implementation carry no risk ?
Best Regards
Mehdi.
2018-10-02 05:50 AM
0x20030000 would be a valid address for the stack, as it is aligned and predecrements
The test is really trying to see if the address looks like RAM, rather than being 0xFFFFFFFF in the erased condition. You explicitly test if either for the first two vectors contain the the blank/erased state