Skip to main content
Associate II
October 27, 2023
Question

Preventing SRAM2 erase during __HAL_RCC_BACKUPRESET_FORCE

  • October 27, 2023
  • 3 replies
  • 1439 views

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

This topic has been closed for replies.

3 replies

TDK
October 27, 2023

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;
 }
"If you feel a post has answered your question, please click ""Accept as Solution""."
KaiS_Author
Associate II
October 30, 2023

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

TDK
October 30, 2023

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."