cancel
Showing results for 
Search instead for 
Did you mean: 

Backup SRAM using CubeMX

Mark Shoe
Senior
Posted on January 17, 2018 at 11:30

The STM32F4 has 4 Kbytes of backup SRAM.

They seems not to be accesable at a certain adress

The HAL lib has also a driver for it. But the functions are not enabled default. 

The library stm32f4xx_hal_sram is needed for the functions. There are even examples in the example directory.

But how to tell CubeMX to include these libraries, i can include myself but they are gone when a new project is generated again.

3 REPLIES 3
Mark Shoe
Senior
Posted on January 18, 2018 at 14:17

Not that hard after all:

sram_t *sram = (uint32_t *) BKPSRAM;

and not sure if needed:

__BKPSRAM_CLK_ENABLE();

HAL_PWR_EnableBkUpAccess();

Varadharajan V
Associate III
Posted on March 05, 2018 at 08:19

It would be fine if cubemx has facility to enable and will generate all the required config like RTC Init

Other wise we have to add the code in between USER Code Begin and User Code End so that Cubemx will not erase on next time same project is generated

But for each project we need to do this other wise Backup SRAM wont be enabled and our code will fail in field

I'm using this the following code inside HAL_RTC_MspInit() function after RTC Enable

void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)

{

if(rtcHandle->Instance==RTC)

{

/* USER CODE BEGIN RTC_MspInit 0 */

/* USER CODE END RTC_MspInit 0 */

/* RTC clock enable */

__HAL_RCC_RTC_ENABLE();

/* USER CODE BEGIN RTC_MspInit 1 */

__HAL_RCC_BKPSRAM_CLK_ENABLE(); // additional code for Backup RAM enable

HAL_PWR_EnableBkUpAccess(); 

// additional code for Backup RAM enable

HAL_PWREx_EnableBkUpReg(); 

// additional code for Backup RAM enable

/* USER CODE END RTC_MspInit 1 */

}

}

after adding those codes, then we can use like non volatile area otherwise its become volatile

Varadharajan V
Associate III
Posted on March 05, 2018 at 08:20

Better cubemx developers consider this and can provide facility inside RTC config dialog