cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader dual bank model

FDigi
Associate III

Hi everyone!

I’m developing a bootloader for a STM32L476RG MCU. My actual boot works fine (it erases my flash area before start writing the new application). However, if something wrong happens in the middle of an upgrade, it’s not possible return for my old application, so I want to create a bootloader model that saves a backup during my upgrade in other part of my flash (I have space enough) and after upgrade is successful, change automatically the jump to this new application area, and vice-versa.

My first model of this works like showed below:

void flash_jump_to_app(void)

{

  /* Function pointer to the address of the user application. */

  fnc_ptr jump_to_app;

  uint32_t start_address;

  start_address = appheader.EnderecoMSP ? FLASH_APP_1_ADDRESS : FLASH_APP_0_ADDRESS;

  start_address |= 0x200; // vector offset

  jump_to_app = (fnc_ptr)(*(volatile uint32_t*) (start_address+4u));

  HAL_DeInit();

  /* Change the main stack pointer. */

  __set_MSP(*(volatile uint32_t*)start_address);

  jump_to_app();

}

EnderecoMSP is a variable that I write in an specific flash area every time I concluded a successful upgrade, so I can manage where to jump. After my boot jumps for the application area, I created a conditional on my void SystemInit(void) function:

VectorOffset = appheader.EnderecoMSP ? 0x86200 : 0x0C200;

SCB->VTOR = FLASH_BASE | VectorOffset; /* Vector Table Relocation in Internal FLASH */

In a first moment I thought it worked, but I realized that if I erase my first area (bank 1, app starting at address 0xC200) it seems to get lost.

Someone have any tip for me ? Or in a case of this model is unusable, is there a similar boot template that I can follow?

Thank you very much!

0 REPLIES 0