cancel
Showing results for 
Search instead for 
Did you mean: 

Iam using STM32L412 nucleo board. To achieve low power consumption Iam using standBy mode and RTC Wakeup. On wakeup I found that the data is not retained .

AChan.9
Associate II

Iam using STM32CUBEIDE for setting up the project. While refereing I have found some articles stating that standby mode default sram contents are lost and we need to use the backup mechanism also I found a reference like (http://5.9.10.113/62624874/stm32f4-sram-contents-retain-even-after-power-reset-and-standby) but here Iam unable to get the __HAL_RCC_BKPSRAM_CLK_ENABLE();

& HAL_PWREx_DisableBkUpReg();

HAl functions for STM32L4 device. Please help in to achieve data retension of SRAm for the device.

7 REPLIES 7

There is no BKPSRAM in the 'L4 family. Read the Reference Manual rather than some random web.

0693W00000BdCGrQAN.pngJW

AChan.9
Associate II

Thanks for the response. I have used the default hal function HAL_PWREx_EnableSRAM2ContentRetention() before entering standby mode to set the register as mentioned in reference manual . But still iam not able to preserve the contents and wakeup using RTC . Any other settings required for this?

AChan.9
Associate II

I used a global variable to check the data retension with value as 10 and in wakeup i tried to modify the value to 30 but it each time during wakeup it gives the value 30 and not 50 as expected during next cycle.

AChan.9
Associate II

I wanted to write the above mentioned logic to SRAM for checking data retension . Could you please help me to achieve this Iam unable to get any reference for this

AChan.9
Associate II

Hi Team, Could you please provide a response on the above queries . used BitBasebanding as well but unable to achieve thsi

AChan.9
Associate II

Iam using the following code snippet for checking sram content retension in standby mode but unable to achieve the same. The var value is always getting printed as 60 after wakeup. Iam using STM32Cube IDE with STM32L412RB Nucleo Board:

#define BITBAND_SRAM_REF 0x20000000

#define BITBAND_SRAM_BASE 0x22000000

#define BITBAND_SRAM(a,b) ((BITBAND_SRAM_BASE + (a-BITBAND_SRAM_REF)*32 + (b*4))) // Convert SRAM address

#define BITBAND_PERI_REF  0x42000000

#define BITBAND_PERI_BASE 0x40000000

#define BITBAND_PERI(a,b) ((BITBAND_PERI_BASE + (a-BITBAND_PERI_REF)*32 + (b*4))) // Convert PERI address

#define MAILBOX           0x20004000

#define TIMER             0x40004000 // Mailbox bit 0

#define MBX_B0            *((volatile unsigned int*)(BITBAND_SRAM(MAILBOX,0))) // Mailbox bit 7

#define MBX_B7            *((volatile unsigned int*)(BITBAND_SRAM(MAILBOX,7))) // Timer bit 0

#define TIMER_B0          *((volatile unsigned char*)(BITBAND_PERI(TIMER,0))) // Timer bit 7

#define TIMER_B7          *((volatile unsigned char*)(BITBAND_PERI(TIMER,7)))

#define SOME_ADD *((volatile unsigned int*)(0x20001234))

/* USER CODE BEGIN PV */

char *str ={0};

unsigned int var=50;

static uint8_t tx_buffer[1000];

/* USER CODE END PV */

void test_standby_rtc_sram2(void)

{

   unsigned xnew = 0;

   HAL_PWR_EnableBkUpAccess();

     __HAL_RCC_PWR_CLK_ENABLE();//Enable the power supply clock

   __HAL_RCC_RTC_ENABLE();

   HAL_RTC_Init(&hrtc);

   /* Clear all related wake-up flags */

   __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

   HAL_RTCEx_DeactivateTamper(&hrtc, RTC_TAMPER_1);

   __HAL_RTC_TAMPER_CLEAR_FLAG(&hrtc, RTC_FLAG_TAMP1F);

 HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 5, RTC_WAKEUPCLOCK_CK_SPRE_16BITS,0);

 str="Wakeup from Standby\n\n";

 HAL_UART_Transmit(&huart2,(uint8_t *)str,strlen(str),HAL_MAX_DELAY);

 MBX_B0 = 1;

 SOME_ADD = var;

 xnew = SOME_ADD;

 var= xnew+10;

 SOME_ADD = var;

 sprintf((char *)tx_buffer, "updated var value is:%d\r\n", var);

 HAL_UART_Transmit(&huart2,(uint8_t *)tx_buffer,strlen(tx_buffer),HAL_MAX_DELAY);

/* Display the string */

         char *str = "About to enter the STANDBY MODE\n\n";

         HAL_UART_Transmit(&huart2, (uint8_t *)str, strlen (str), HAL_MAX_DELAY);

                /* Request to enter STANDBY mode with SRAM2 active */

   HAL_PWREx_EnableSRAM2ContentRetention();//Activate the SRAM2 backup domain in standby mode

   HAL_PWR_EnterSTANDBYMode();//Enter standby mode

}

Make sure var is located in SRAM2, and that the startup code does not overwrite it.

JW