2018-01-17 02:30 AM
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.
2018-01-18 05:17 AM
Not that hard after all:
sram_t *sram = (uint32_t *) BKPSRAM;
and not sure if needed:
__BKPSRAM_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
2018-03-04 11:19 PM
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
2018-03-04 11:20 PM
Better cubemx developers consider this and can provide facility inside RTC config dialog