cancel
Showing results for 
Search instead for 
Did you mean: 

Jumping to a memory location..bootloader C code

stenasc
Senior
Posted on March 30, 2013 at 22:15

Hi,

In our system, I have to be able to update the application code. Therefore I believe I need to copy the application to memory location 0x8000000 and then jump to this location...basically a small bootloader of sorts. I've  tried the following method to jump to the required address, but with no success. First of all, can I do this on the stm32 family and if so, Has anyone got any code snippet that will do the job or has the stm32f051 require some additional requirements in order to reboot?

void (*fptr)(void) = (void (*)(void))0x8000000;

fptr();

Man Thanks

Bob

1 REPLY 1
Posted on March 30, 2013 at 22:36

The 32-bit word stored at 0x08000000 is the initial stack pointer (SP)

The word at 0x08000004 is the address for the Reset_Handler function, which typically calls SystemInit(), and then the C Run Time startup code, which in turn calls main(). The address stored here is ODD, indicating that it points to THUMB code, not 32-bit ARM code. As you can't relocate the vector table on the M0, the memory at 0x08000000 is mapped/shadowed at ZERO. I believe you have to copy the new vector table to the base of RAM (0x20000000) and then map that at ZERO, to replace the FLASH base one of the boot loader. Suggest a review of the IAP examples, and binary template

http://www.st.com/web/en/catalog/tools/PF258152

int main(void)
{
uint32_t i = 0;
/* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/
/* Copy the vector table from the Flash (mapped at the base of the application
load address 0x08003000) to the base address of the SRAM at 0x20000000. */
for(i = 0; i < 48; i++)
{
VectorTable[i] = *(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));
}
/* Enable the SYSCFG peripheral clock*/
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Remap SRAM at 0x00000000 */
SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);
/***************** Add your application code here ***************************/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..