2025-10-07 7:04 PM
This works fine in an app without SM but when I run this from a non-secure app together with SM, the last step fails. This is the code:
// Enable access to RTC and backup domain
HAL_PWR_EnableBkUpAccess();
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
{
// Reset the backup domain (equivalent to LL_RCC_ForceBackupDomainReset)
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();
// Ensure LSE is OFF and NOT in bypass mode
CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON | RCC_BDCR_LSEBYP);
// Set drive strength for startup (must be done while LSE is OFF)
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_MEDIUMHIGH);
// Enable LSE
__HAL_RCC_LSE_CONFIG(RCC_LSE_ON);
// Wait until LSE is ready, with timeout
if (SYSTIMER_WaitFlag(&RCC->BDCR, RCC_BDCR_LSERDY, true, 20000000))
{
}
else
{
// Disable LSE
__HAL_RCC_LSE_CONFIG(RCC_LSE_OFF);
// LSE activation error, handle as appropriate
status = HAL_TIMEOUT;
}
// Select LSE as RTC clock source
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
}When entering this code, the BDCR register in RCC is 0 so completely clear, nothing is enabled. I noticed that when I repeat the process, the __HAL_RCC_BACKUPRESET_FORCE() (i.e. setting of the VSWRST bit) doesn't have any effect but that's not the issue. I can enable LSEON and LSERDY is being set so the LSE is working but the last step, setting RTCSEL to 1 to select the LSE as RTC clock is not working at all no matter what I try. RTC_SECCFGR is 0x0808 so LSESEC is 0 and RCC_PRIVCFGR is 0x0.
I am stumped, this has worked perfectly fine without SM. I couldn't find any configuration options for SM that relate to this.
2025-10-08 10:52 AM
After consulting the SM manual UM3254 things are (a bit) clearer. Chapter 6.1.1.2 (Peripherals) doesn't list the RTC under "Secure Manager reserved resources" but chapter 6.6 (Tamper) has this:
"The Secure Manager locks the RTC/Tamp clock source to LSI." And the LSI is allocated to the secure domain so the bits related to the LSI always return 0. So my conclusion is that you can't use the RTC in a way that would keep on running when the device is powered off since the LSI will stop (not powered by VBAT). Is this correct?
2025-10-08 1:28 PM
Hello @Christian Keydel ,
The LSI is in VBAT domain, so keeps RTC running when VBAT is on.
Just the same a LSE.
The difference between the 2 is the precision. You cannot use LSI to have a precise measure of time.
This limitation in Secure Manager will be removed in a future release.
Best regards
Jocelyn
2025-10-09 9:44 AM
Hello @Jocelyn RICARD ,
Thank you for your reply. I am running the latest version of Secure Manager and have two issues:
@Jocelyn RICARD wrote:The LSI is in VBAT domain, so keeps RTC running when VBAT is on.
Just the same a LSE.
Sorry this is not what I am seeing - I have VBAT with a charged supercap and when I set the RTC to host time, power down and power up the next day and read the RTC I am getting date and time from yesterday when I powered down (I did this today). And it also shows in the H573 reference manual in chapter 10.4, Figure 40:
Only the LSE is in the backup domain but the internal RC oscillators are not, they are in the Vdd domain.
The second issue is that I can't switch to LSE since I cannot write to RTCSEL bits in the BDCR register in RCC. As the SM manual says: "The Secure Manager locks the RTC/Tamp clock source to LSI."
These two issues together mean that I cannot have a functioning RTC when I use Secure Manager (not even an inaccurate one which I could help with calibration).
2025-10-09 11:02 AM
Hello @Christian Keydel ,
my bad, I was not aware of this characteristic on H5 (LSI is in VBAT domain on U5 for instance). We learn every day !
As a consequence, you are right, with this release it is not possible to have such use case.
Best regards
Jocelyn
2025-10-09 11:19 AM
Hello @Jocelyn RICARD,
Can you say whether a future release of Secure Manager will allow to use LSE with RTC? Since we need an RTC for security events logging, this has a direct impact on our hardware design. We can live with "best effort" timestamps for the first release but will eventually have to have a functioning RTC that keeps the time when powered down.
Thanks,
Christian