cancel
Showing results for 
Search instead for 
Did you mean: 

Graphical way to not add HAL_RTCEx_SetWakeUpTimer_IT(…) call to MX_RTC_Init(void) ?

Nick Alexeev
Associate III

I enabled the RTC wakeup interrupt in STM32cubeIDE graphical configer. The IDE added code to the MX_RTC_Init(void) which enables the interrupt and starts the timer. It’s the call to HAL_RTCEx_SetWakeUpTimer_IT(…) , and it’s not in the USER CODE block.

  /** Enable the WakeUp
  */
  if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x1000, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN RTC_Init 2 */

  /* USER CODE END RTC_Init 2 */

I’m concerned that RTC interrupt may interfere with my own initialization, so I’d start the timer from my main() at a much later stage. I can call HAL_RTCEx_DeactivateWakeUpTimer(…) in the USER CODE to disable the timer. But is there graphical config – is there the Cube way – to tell the IDE not to add the HAL_RTCEx_SetWakeUpTimer_IT(…) call to MX_RTC_Init(void) ?

[I’m using the graphical configer in the IDE and the MX interchangeably. But if the standalone MX has better options, please let me know. ]

5 REPLIES 5
Andrew Neil
Super User

What IDE & MX versions are you using,  what Host platform, and what target?

How to write your question to maximize your chances to find a solution

 

Note that the latest IDE (v2.0.0) no longer has the MX part integrated:

https://community.st.com/t5/stm32cubeide-mcus/cubeide-2-0-does-not-open-ioc-files/m-p/857301/highlight/true#M39483

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Super User

No way to remove only that call, but plenty of options to initialize RTC how you want:

  • Enclose it in __disable_irq() and __enable_irq() in user code to prevent IRQ from firing while you disable it.
  • Tell CubeMX not to generate MX_RTC_Init and implement your own. (Do Not Generate Function Call)
If you feel a post has answered your question, please click "Accept as Solution".

@Andrew Neil wrote

What IDE & MX versions are you using, what Host platform, and what target?


STM32CubeIDE version: 1.16.0 build: 21983_20240628_1741 (UTC)
It contains STM32cubeMX version: 6.12.0-RC9 build: 20240628-1431 (UTC)
I’m on Windows 10.
The target is STM32G474 on a custom PCB. There is a 32.768 kHz crystal and a backup battery. The hardware seems to be working nominally. I was able to run a wake up on RTC interrupt example from this ST article: How to configure the RTC to wake up the STM32 periodically from Low Power modes

 


@TDK wrote:

No way to remove only that call, but plenty of options [...]


There’s a USER CODE block immediately after the call to HAL_RTCEx_SetWakeUpTimer_IT(…) . I can add a HAL_RTCEx_DeactivateWakeUpTimer(…) call to the USER CODE block. Would that be an okay solution?

  /** Enable the WakeUp
  */
  if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x1000, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN RTC_Init 2 */
  if (HAL_RTCEx_DeactivateWakeUpTimer(&hrtc) != HAL_OK) Error_Handler();  // Disable the RTC during the rest of initialization.  It will be re-enables in the main loop.
  /* USER CODE END RTC_Init 2 */

Hello @Nick Alexeev 

Could you please try to use the latest version of STM32CubeMX 6.16.0.

THX

Ghofrane

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.

> There’s a USER CODE block immediately after the call to HAL_RTCEx_SetWakeUpTimer_IT(…) . I can add a HAL_RTCEx_DeactivateWakeUpTimer(…) call to the USER CODE block. Would that be an okay solution?

Sure, that'll deactivate the wakeup. It really depends on what you mean by your own setup and what you don't want to interfere with.

Generally, in my own code, I'll see if the RTC is already initialized on startup and skip MX_RTC_Init all together.

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