2024-09-27 01:50 PM - edited 2024-09-27 02:09 PM
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();
}
Solved! Go to Solution.
2024-09-27 02:40 PM
But you disable the backup access in line 12, before write in line 17 ??
2024-09-27 01:52 PM - edited 2024-09-27 02:11 PM
I did also verify the BKPRAMEN bit is being set. And the MPU and cache are both disabled.
2024-09-27 02:40 PM
But you disable the backup access in line 12, before write in line 17 ??
2024-09-27 02:57 PM
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);
}
2024-09-27 03:03 PM
> that only enables and disables access to the control registers
Nope
2024-09-27 03:11 PM
Thanks I’ll try that on Monday.
2024-09-28 08:49 AM
Yep that did it. Thank you for reviewing the code and quickly finding my mistake!