2023-10-27 02:13 AM - edited 2023-10-27 02:14 AM
Hello,
I am trying to find the most elegant way to prevent SRAM2 (and any other memory) from being wiped when moving to LSE as a clock source by calling HAL_RCCEx_PeriphCLKConfig due to its call to __HAL_RCC_BACKUPRESET_FORCE.
I am using an u5* Series MCU and I looked through the manuals but could not find a definite way of simply preventing this wiping of data.
Best regards,
Kai S
2023-10-27 07:19 AM
Backup SRAM is wiped only if the RTC clock source is changed. If you're changing it, there is no preventing this. If you don't have to change it, then don't and it won't be reset.
/* Reset the Backup domain only if the RTC Clock source selection is modified from default */
tmpregister = READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL);
if ((tmpregister != RCC_RTCCLKSOURCE_NO_CLK) && (tmpregister != pPeriphClkInit->RTCClockSelection))
{
/* Store the content of BDCR register before the reset of Backup Domain */
tmpregister = READ_BIT(RCC->BDCR, ~(RCC_BDCR_RTCSEL));
/* RTC Clock selection can be changed only if the Backup Domain is reset */
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();
/* Restore the Content of BDCR register */
RCC->BDCR = tmpregister;
}
2023-10-30 03:52 AM
Hi TDK,
thank you for your answer. If there is no way of preventing this erase, what is the recommended way of either using SRAM2 without it being wiped? What would be the best way to avoid using it alltogether?
Best regards
2023-10-30 06:43 AM
It feels like the expected usage is to set the RTC clock once, and not change it. That's certainly how most programs operate.
It feels like this may be a tamper detection thing rather that directly due to RTC clock being reset, but I don't have the time to dig into it.