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.