cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX RTC config issues

TDJ
Lead

Trying to to set up RTC alarm for STM32U5G9 I come across this CubeMX issues:

There is no option to disable Calendar date and time setup. Needless to say, probably it does not make any sense to set up date and time on every board reset if it has (as it should) some RTC battery backup.
It is not a big deal until one configures RTC alarm, function "return" statement can be added in MX_RTC_Init() 'user code' section before date/time gets reconfigured.
However, this is not an option when RTC alarm is configured because code execution needs to reach this part resetting time and date along the way.

Another reason for that is the lack of 'user code' between date/time setup and alarm setup sections in generated code. Otherwise, label and goto statement could be used to skip date/time setup.

I find lack of an option to disable date/time config very annoying. Probably this feature was never implemented because originally CubeMX was meant only to generate "quick and dirty" demo code so it did not matter.

TDJ_1-1735906003846.png

TDJ_2-1735907337800.png

 

2 REPLIES 2
Sarra.S
ST Employee

Hello @TDJ

A solution I can think of, is to use the backup registers to store a flag indicating whether the RTC has been initialized; 

So, the code first checks if the RTC is already running by reading a specific flag from the backup register (`RTC_BKP_DR1`). If the flag is set (e.g., `0x1234`), it means the RTC has been initialized previously, and the function returns early to skip the date/time setup. If not -the RTC is not initialized- the code proceeds to initialize the RTC and set the date and time then configures the RTC alarm. 

The flag indicating that the RTC has been initialized should be in the backup domain, so it will be retained at reset. 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @Sarra.S I tried to explain why the approach you suggested is not doable if an RTC alarm is also configured. Simply, there is no way to place code in the 'user code' section that will conditionally or unconditionally skip the date/time config and go straight to RTC alarm config. There is not 'user code' section between date/time setup and RTC alarm config where execution could jump to.