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
Solved! Go to Solution.
2025-10-24 10:05 AM - edited 2025-10-24 10:24 AM
I understand.
2025-10-24 10:21 AM
I understand. Thank you for all your help