cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to Backup SRAM on STM32H7S78-DK

mbrossett
Associate III

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();
}

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

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

 

View solution in original post

6 REPLIES 6
mbrossett
Associate III

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

 

mbrossett_0-1727470312750.png

 

Pavel A.
Evangelist III

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

 

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);
}

that only enables and disables access to the control registers

Nope

 

Thanks I’ll try that on Monday. 

Yep that did it. Thank you for reviewing the code and quickly finding my mistake!