2025-07-10 4:38 AM - edited 2025-07-11 2:01 AM
Hello,
In my project, I want to hold boot params in BKPSRAM so "Application project" can also write and read this section easily. If boot is needed, "Application project" will set boot params as required and after that it will use "NVIC_System_Reset".
Therefore, I tried to write and read some parameters in this area. I can see the datas is written successfully in "BKPSRAM_BASE_S" section while debugging but when I restart the debug session, BKPSRAM section is all fill with zeros. I know that I am missing something but did not find it.
- STM32N655 custom board.
#define BKP_SRAM_START_ADDRESS ((uint32_t)BKPSRAM_BASE_S)
#define BOOT_PARAMS_PTR ((BootParameters_t*)BKP_SRAM_START_ADDRESS)
/* USER CODE BEGIN Init */
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_RAMCFG_CLK_ENABLE();
__HAL_RCC_BKPSRAM_MEM_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
HAL_PWREx_EnableBkupRAMRetention();
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
SystemIsolation_Config();
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_HPDMA1_Init();
MX_XSPI2_Init();
/* USER CODE BEGIN 2 */
MX_EXTMEM_MANAGER_Init();
s_boot_params.o_boot_mode = TRUE;
memcpy(&s_boot_params.ab_version[0], k_BOOTLOADER_VERSION, 4);
/* Write to backup ram */
memcpy((void*) BOOT_PARAMS_PTR, &s_boot_params, sizeof(BootParameters_t));
/*Read from backup ram */
// memcpy(&s_boot_params, (void*) BOOT_PARAMS_PTR, sizeof(BootParameters_t));
Update-1: Same problem as in this topic https://community.st.com/t5/stm32-mcus-products/stm32h743-backup-ram-not-saved/td-p/273468
Update-2: I tested my code on STM32N6570-DK and BKPSRAM is retained but I did not figure out the problem on my custom board.
VDD and VBAT connection is managing with internal switch and VDD is always on in my case. (RM,Page:355)
Any help appreciated.
Best Regards.
Solved! Go to Solution.
2025-07-16 5:16 AM
I also found something else but I do not know what is going on inside of mcu. If I do not use MPU init and write datas inside of BKPSRAM, some of the values are get lost.
I fixed this issue with using MPU. I opened the MPU initialization and added BKPSRAM area section.
2025-07-15 11:43 PM
Reminder!
2025-07-16 3:07 AM
I found the problem but I did not find what cause that. If I do not initialize "Memory Protection Unit", BKPSRAM area is retained.
My question is that BKPSRAM area(0x3C000000UL) is not included in MPU initialization and it can still access and make changes on this area. Why does MPU initialization access all memory areas?
Please, explanation with resources from manuel.
/* USER CODE BEGIN 1 */
// MPU_Config();
/* USER CODE END 1 */
/* Enable the CPU Cache */
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
/* MCU Configuration--------------------------------------------------------*/
/* MPU Configuration--------------------------------------------------------*/
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
SystemIsolation_Config();
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_RAMCFG_CLK_ENABLE();
__HAL_RCC_BKPSRAM_MEM_CLK_ENABLE();
RCC_S->MEMLPENSR = RCC_MEMLPENSR_BKPSRAMLPENS_Msk;
PWR_S->DBPCR = PWR_DBPCR_DBP;
PWR_S->BDCR2 |= PWR_BDCR2_BKPRBSEN;
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_HPDMA1_Init();
MX_XSPI2_Init();
/* USER CODE BEGIN 2 */
MX_EXTMEM_MANAGER_Init();
void MPU_Config(void) {
MPU_Region_InitTypeDef MPU_InitStruct = { 0 };
MPU_Attributes_InitTypeDef MPU_AttributesInit = { 0 };
uint32_t primask_bit = __get_PRIMASK();
__disable_irq();
/* Disables the MPU */
HAL_MPU_Disable();
/** Initializes and configures the Region 0 and the memory to be protected
*/
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.BaseAddress = 0x341FA600;
MPU_InitStruct.LimitAddress = 0x341FFFFF;
MPU_InitStruct.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
MPU_InitStruct.AccessPermission = MPU_REGION_ALL_RW;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
MPU_InitStruct.DisablePrivExec = MPU_PRIV_INSTRUCTION_ACCESS_DISABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Attribute 0 and the memory to be protected
*/
MPU_AttributesInit.Number = MPU_ATTRIBUTES_NUMBER0;
MPU_AttributesInit.Attributes = INNER_OUTER(MPU_NOT_CACHEABLE);
HAL_MPU_ConfigMemoryAttributes(&MPU_AttributesInit);
/* Enables the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
/* Exit critical section to lock the system and avoid any issue around MPU mechanism */
__set_PRIMASK(primask_bit);
}
2025-07-16 5:16 AM
I also found something else but I do not know what is going on inside of mcu. If I do not use MPU init and write datas inside of BKPSRAM, some of the values are get lost.
I fixed this issue with using MPU. I opened the MPU initialization and added BKPSRAM area section.
2026-03-19 12:59 PM
Hi @B.Kaya
I believe I have the same problem. Could you please tell what MPU configuration did you use for BKPSRAM? No caching?
2026-03-20 1:48 AM - edited 2026-03-20 2:24 AM
There is yet again bunch of N6 oddities.
First off, Backup RAM is 8 KB, but RISAF area for that is 4 KB:
When defining full 8 KB Backup RAM area in CubeMX MMT and let it automatically do RISAF configuration and generate SystemIsolation_Config, then that will fail in assert because RISAF23_LIMIT_ADDRESS_SPACE_SIZE is 4KB (minus 1) not 8 KB (minus 1). Assert is valid based on RM table 24, but tool creates bad code.
Okay, so I used first 4 KB.
I tried simply writing to Backup RAM and reading it back. It reads zeroes. So write is not effective. I enabled all the clocks and accesses and all kind of modes like you have in the code above. Tried with and without cache. Thing that made it work was not configuring RISAF23 region (and skipping system isolation completely). I tried playing with secure and privilege attributes also, didn't help. Other RAMs have same attributes and work without issus.
But that was not enough. Written data still did not persist over resets.
I have MPU configured (by MMT) over Backup RAM area and it is made non-cacheable with attributes. Unfortunately this doesn't seem to have effect, because only when I added manual cache flush (clean) and invalidate operations, it started working like expected.
I noticed somebody else struggling with Backup SRAM and MPU on another MCU: Solved: Re: STM32H743: Backup RAM not saved - STMicroelectronics Community
PS.
One alternative to avoid disabling whole RISAF or applying custom changes to generated code is to set filtering on the Backup RAM area: