Skip to main content
Explorer II
February 5, 2025
Solved

Implementing STM32L4S5ZIT6 Bootloader with a Memory Marker

  • February 5, 2025
  • 2 replies
  • 676 views

Hello,


I am working on the development of a bootloader for the STM32L4S5ZIT6, and I need help to implement a feature where the bootloader is triggered after receiving a user request in the main application (the main app saves a marker in memory).

Here is what I am trying to achieve:

  1. The main application saves a marker (a magic number) in memory.
  2. After jumping to the bootloader, the bootloader checks for the presence of this marker.
  3. If the marker is found, the bootloader proceeds to execute (e.g., triggering a firmware update).
  4. If the marker is not found, the bootloader jumps back to the main application.

My question

 

 

  • Is SRAM backup (BKPSRAM) the best place to store the marker? If so, could anyone provide me with the exact address of BKPSRAM for the STM32L4S5ZIT6 (I couldn't find it in the user manual)?
  • If BKPSRAM isn't suitable, can you propose another solution for saving the marker in a persistent memory region that survives resets?

I tried using SRAM to store a marker, then I perform a reset. What I don't understand is that the data is not cleared with the code below. Could you please clarify this for me

__attribute__((section(".backup_sram"))) volatile uint32_t marker;

int main(void)
{
 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 if(marker == 0x12345678U)
	 marker = 0x00000000;

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();

 /* Enable SRAM2 retention in Standby mode */
 //HAL_PWREx_DisableSRAM2ContentRetention();

 marker = 0x12345678U;

 HAL_NVIC_SystemReset();


 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}

/****** Linker script ************/

MEMORY
{
 RAM 		(xrw) : ORIGIN = 0x20000000, LENGTH = 640K
 RAM2 		(xrw) : ORIGIN = 0x10000000, LENGTH = 64K
 RAM3 		(xrw) : ORIGIN = 0x20040000, LENGTH = 384K
 SHARED_MEMORY (xrw) 	 : ORIGIN = 0x2003FF9C, LENGTH = 100 /* SRAM2 */
 FLASH 		(rx) : ORIGIN = 0x8000000, LENGTH = 2048K
}

/* Sections */
SECTIONS
{
 .backup_sram :
 {
 . = ALIGN(4);
 *(.backup_sram)
 . = ALIGN(4);
 } > SHARED_MEMORY

 

I would greatly appreciate any help or suggestions.

Thank you very much!

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello,

    According to the product datasheet, SRAM2 retains the data after reset.

    mALLEm_0-1743588301866.png

    Regarding the backup SRAM, it is designed to retain its content even after reset, as long as the backup domain is powered.

     

    2 replies

    mƎALLEmAnswer
    Technical Moderator
    April 2, 2025

    Hello,

    According to the product datasheet, SRAM2 retains the data after reset.

    mALLEm_0-1743588301866.png

    Regarding the backup SRAM, it is designed to retain its content even after reset, as long as the backup domain is powered.

     

    ZAYNAuthor
    Explorer II
    April 2, 2025

    Hello,

    Thank you for your feedback.

    Yes, I used this memory to implement this feature, It' work perfectly.

    Thank you.