2025-10-21 12:57 PM - last edited on 2025-10-21 1:50 PM by mƎALLEm
Edited by a ST moderator to follow the community rules especially for code sharing. So please use </> to share your code
Hello,
I am using the STM32WBA, and I am interested in persisting data to start after waking up from standby mode.
I am unable to keep the data in memory. Here is how I am configuring the linker script and main.c.
Can you please help me with how to keep the data when waking up? I am configuring a pot for wakeup GPIO_PIN_13.
My goal is for the MCU to wake up, perform some actions, and go back to sleep repeatedly.
STM32WBA55CGUX_FLASH.ld
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
BKPSRAM (xrw) : ORIGIN = 0x40024000, LENGTH = 2K
}
## after .bss: ##
.bss_bkpsram (NOLOAD) :
{
. = ALIGN(4);
KEEP(*(.bss_bkpsram))
. = ALIGN(4);
} > BKPSRAM
main.c
typedef struct
{
uint32_t magic_number;
uint16_t device_id;
} PersistentState_t;
__attribute__((section(".bss_bkpsram"))) volatile PersistentState_t g_persistent_state;
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess ();
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SBF) != RESET)
{
g_persistent_state.device_id++;
}
else
{
g_persistent_state.magic_number = 0xCAFEFEED;
g_persistent_state.device_id = 0x0001;
}
__HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_FLAG2);
HAL_PWREx_EnableStandbyIORetention (PWR_GPIO_C, GPIO_PIN_13);
HAL_PWR_EnableWakeUpPin (PWR_WAKEUP_PIN2_HIGH_1);
HAL_PWR_EnterSTANDBYMode ();
Best regards
2025-10-21 4:36 PM
The STM32WBA doesn’t appear to have ram in the backup domain like some other STM32 chips. However, SRAM1 and SRAM2 can have retention enabled in standby using theses functions…
HAL_PWREx_EnableSRAM1ContentStandbyRetention()
HAL_PWREx_EnableSRAM2ContentStandbyRetention()
You will need to change the BKPSRAM address in your linker script as the address you have used is in the nonsecure peripheral region. Otherwise your linker script looks ok to me.
2025-10-21 4:42 PM
To use SRAM2 as standby ram use address 0x2007 0000 in your linker script.