Showing results for 
Search instead for 
Did you mean: 

CubeMX seems to generate wrong code for RTC_OUT2

Peter Allnutt
Associate III

Target is the Nucleo G474RE board and I've tried both the CubeIDE (1.3.1) embedded CubeMX and the standalone CubeMX (5.6.0) in both cases if you enable the Calibration option and set it to "Calibration 1Hz routed to OUT2" then the signal comes out of the wrong pin. It appears on PC13 (the Nucleo's User Button) not PB2. PB2 is the pin highlighted on the CPU graphic however.


PC13 is used by the RTC for a timestamp output. Sure you're not confusing that output with RTC_OUT2?

Seems to be an issue with CubeMX using PC13 for the RTC even if you've not told it to.

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

PC13 is RTC_OUT1, PB2 is RTC_OUT2 which is what I want to use and have selected in CubeMX. Because my project is based on ST's Nucleo board CubeMX knows I can't use RTC_OUT1 as it's the User Push Button and won't let me select that as an option but the code it produces still outputs the signal on RTC_OUT1.

As I said CubeMX highlights the correct pin but the code it produces uses the other pin. Should I be reporting this issue some other way? I do find the non conventional 'forums' here impossible to follow at times.

Khouloud ZEMMELI
ST Employee

Hello @Peter Allnutt​ 

Could you please share more info ,Where in the code the PC13 is used instead of PB2 ? because I cannot reproduce the issue and it's Ok on my side.



Read out and check/post the relevant RTC registers content.


Peter Allnutt
Associate III

I can confirm this problem has gone away, I'm guess now it's the Repository that's used for the template code and it's been fixed in there. I'm now using G4_V1.3.0. Not sure what I used before but probably G4_1.2.0.

Using both the HAL and LL options configures the alternate pin correctly. With the HAL the signal is immediately visible on the scope, not so with the LL library. I'm happy that I need to turn the signal on ( call to LL_RTC_EnableOutput2() ) but the template initialisation code produces a call LL_RTC_CAL_SetOutputFreq() to set the signal format. However it does this without first disabling the register write protection. The call therefore has no effect. It should either be removed or the functionality corrected.

  /** Enable Calibration
  /* USER CODE BEGIN RTC_Init 2 */
  LL_RTC_DisableWriteProtection( RTC );
  LL_RTC_EnableWriteProtection( RTC );
  /* USER CODE END RTC_Init 2 */

First call to LL_RTC_CAL_SetOutputFreq() doesn't do anything. To enable the output frequency and subsequently the signal I think you need to do the USER CODE bit.