Skip to main content
Associate II
September 27, 2024
Solved

Writing to Backup SRAM on STM32H7S78-DK

I am trying to use the backup SRAM but get a hard fault when writing to the memory. I have unlocked the backup domain, enabled the backup regulator, and enabled the clock. What other step am I missing?

 

 

 

// unlock backup domain
HAL_PWR_EnableBkUpAccess(); 

// enable the backup SRAM
if (HAL_OK != HAL_PWREx_EnableBkUpReg())
{
	Error_Handler();
}
__HAL_RCC_BKPRAM_CLK_ENABLE();	

// lock the backup domain
HAL_PWR_DisableBkUpAccess();

// Test read and write to backup SRAM
uint32_t magicNumber = 0xAA55;
uint32_t *pBackupSram = (uint32_t *)(0x38800000);
*pBackupSram = magicNumber;
if (magicNumber != *pBackupSram)
{
	Error_Handler();
}
*pBackupSram = 0;
if (0 != *pBackupSram)
{
	Error_Handler();
}

 

 

 

This topic has been closed for replies.
Pavel A.
Pavel A.Best answer
September 27, 2024

But you disable the backup access in line 12, before write in line 17 ??

 

6 replies

mbrossettAuthor
Associate II
September 27, 2024

I did also verify the BKPRAMEN bit is being set. And the MPU and cache are both disabled. 

 

mbrossett_0-1727470312750.png

 

Pavel A.
Pavel A.Best answer
September 27, 2024

But you disable the backup access in line 12, before write in line 17 ??

 

mbrossettAuthor
Associate II
September 27, 2024

My understanding is that only enables and disables access to the control registers in the backup domain.  

/**
 * @brief Enable access to the backup domain (RCC Backup domain control
 * register RCC_BDCR, RTC registers, TAMP registers, backup registers
 * and backup SRAM).
 * @note After a system reset, the backup domain is protected against
 * possible unwanted write accesses.
 * @retval None.
 */
void HAL_PWR_EnableBkUpAccess(void)
{
 SET_BIT(PWR->CR1, PWR_CR1_DBP);
}
Pavel A.
September 27, 2024

> that only enables and disables access to the control registers

Nope