2025-09-26 7:49 AM
Hi
I am working on an STM32U585 microcontroller with TrustZone enabled and I need to update the RTC time with the HAL_RTC_SetTime function. During the execution of that function, the line
status = RTC_EnterInitMode(hrtc); //stm32u5xx_hal_rtc.creturns HAL_TIMEOUT, so I am unable to update the RTC values.
I have attached several screenshots that show the microcontroller configuration The Project Manager generates both MX_RTC_Init functions for the Secure and NonSecure zones.
The main files of both Secure and NonSecure zone execute the MX_RTC_Init function without any errors, the software starts up correctly, but at some point I am not able to set the RTC Time.
Upon debugging, I noticed that during the execution of RTC_EnterInitMode, the line
SET_BIT(RTC->ICSR, RTC_ICSR_INIT);does not set the INIT bit, which remains at 0.
Thank you in advance for your support. Please let me know if you need any further information.
Best regards,
Eros
Solved! Go to Solution.
2025-10-01 9:01 AM
Hello @erosghignoni
If you need to update the RTC from NonSecure code while the RTC is configured as Secure, you should implement a Secure callable function using the CMSE_NS_ENTRY attribute. This function is defined in the Secure zone and exposes a controlled interface for NonSecure code to request RTC updates. For example, you can create a function like SECURE_SetRTCTime, which takes a pointer to an RTC_TimeTypeDef structure and internally calls HAL_RTC_SetTime to update the RTC. The NonSecure application can then invoke this Secure function via a function pointer, ensuring that all RTC modifications are performed within the Secure context, maintaining the integrity and security of the RTC peripheral.
2025-10-01 9:01 AM
Hello @erosghignoni
If you need to update the RTC from NonSecure code while the RTC is configured as Secure, you should implement a Secure callable function using the CMSE_NS_ENTRY attribute. This function is defined in the Secure zone and exposes a controlled interface for NonSecure code to request RTC updates. For example, you can create a function like SECURE_SetRTCTime, which takes a pointer to an RTC_TimeTypeDef structure and internally calls HAL_RTC_SetTime to update the RTC. The NonSecure application can then invoke this Secure function via a function pointer, ensuring that all RTC modifications are performed within the Secure context, maintaining the integrity and security of the RTC peripheral.
2025-10-27 3:07 AM
Hi @Saket_Om , is it possible to keep the initialisation of RTC in the Non secure app? The Cubemx seems to be allowing it and one of the example code of BLE p2p Trust zone also initialises the RTC in the non-secure app but when i configure it from the CubeMX the RTC init just times out.
2025-10-27 3:44 AM
Hello @nomancy
Please refer to the example below: