cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing OTA firmware update (ota0 and ota1 slots in flash memory ) with STM32L562VETQ

WAdel.1
Associate II

hi all,

I'm using STM32L562VETQ.

I'm new to such topics but i want to implement OTA firmware update in which i want to divide the flash into 2 sections (ota0 and ota1).

*The process in short is as following:

1- The MCU image/firmware (.bin file) will be uploaded to a server

2- A modem will download that image (.bin file) and send it over UART to the MCU (piece by piece)

3- The MCU will receive those pieces and will flash them -using the "HAL_FLASH_Program()" function- to the target OTA section (if the current running ota section is ota0 then the target will be ota1 and vice versa)

*The question is:

1- What should i do in the linker-script file to divide the memory into two sections? and should i do that? or it's okay to leave the flash as one block and just determine the starting address of the new-image when flashing it?

2- After flashing, How can i transfer the control-flow to the new flashed-image ? should i use pointer-to-function and manually call the reset-handler of the flashed image ? or is there any built-in function to do so ?

*Additional info:

1- here is the linker-script

/* Entry Point */
ENTRY(Reset_Handler)
 
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM);	/* end of "RAM" Ram type memory */
 
_Min_Heap_Size = 0x200 ;	/* required amount of heap  */
_Min_Stack_Size = 0x400 ;	/* required amount of stack */
 
/* Memories definition */
MEMORY
{
  RAM	(xrw)	: ORIGIN = 0x20000000,	LENGTH = 192K
  ROM	(rx)	: ORIGIN = 0x8000000,	LENGTH = 512K
}

and here's what i have done (not sure if it's correct to do that but i have changed the size of the flash to 256k and its origin will varies based on the image that i want to compile -either ota0 image or ota1- )

/* Entry Point */
ENTRY(Reset_Handler)
 
/* OTA sections addresses */
_OTA0_ADDRESS = 0x8000000;
_OTA1_ADDRESS = 0x8040000;
 
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM);	/* end of "RAM" Ram type memory */
 
_Min_Heap_Size = 0x200 ;	/* required amount of heap  */
_Min_Stack_Size = 0x400 ;	/* required amount of stack */
 
/* Memories definition */
MEMORY
{
  RAM	(xrw)	: ORIGIN = 0x20000000,	LENGTH = 192K
  ROM	(rx)	: ORIGIN = _OTA0_ADDRESS,	LENGTH = 256K
}

2- Also here's an image of the flash memory for the MCU that i'm using (ota0 in bank1 and ota1 in bank2):


_legacyfs_online_stmicro_images_0693W00000dK3BSQA0.png

0 REPLIES 0