cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5A9: Unable to set RTC_CR WUTIE and WUTE bits

AidanBrowne
Associate

Hello,

We are using the RTC wakeup timer and I have noticed that sometimes the WUTIE and WUTE bits are not being set. We are using HAL_RTCEx_SetWakeUpTimer_IT() HAL function to enable the timer. In stepping through the HAL code, it sets the RTC_CR_WUTIE and RTC_CR_WUTE bits but does not check they are actually set, so I assume it is expected to set the bits.

I have read through the reference manual (RM0456) and existing errata. There is no existing errata w.r.t the RTC unit that applies to this situation.

Any insight would be appreciated.

Thanks,

Aidan

 

3 REPLIES 3
Gyessine
ST Employee

hello @AidanBrowne

Can you debug your project and add breakpoints at the point when the interrupt occurs?
Sometimes, the bit is cleared immediately after it is set.
You might have reviewed the register bits after they were cleared.
If you check the HAL_RTCEx_SetWakeUpTimer_IT function, you see that the WUTE bit is cleared.

 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock,
                                              uint32_t WakeUpAutoClr)
{
.....

  assert_param(WakeUpAutoClr <= WakeUpCounter);
  __HAL_LOCK(hrtc);
  hrtc->State = HAL_RTC_STATE_BUSY;


  /* WUTE bit is getting cleared here  */
  CLEAR_BIT(RTC->CR, RTC_CR_WUTE);

  /* Clear flag Wake-Up */
  WRITE_REG(RTC->SCR, RTC_SCR_CWUTF);
.....

 and in "HAL_RTCEx_DeactivateWakeUpTimer" for WUTIE bit

CLEAR_BIT(RTC->CR, (RTC_CR_WUTE | RTC_CR_WUTIE));

 Hope that helps you
Gyessine

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.

AidanBrowne
Associate

Hello,

Thanks for replying. I discovered the issue by stepping through the function and reviewing the register contents directly. 

When I stepped over line 640, the bits were still 0, resulting in the timer not expiring eventually etc:

...

MODIFY_REG(RTC->CR, RTC_CR_WUCKSEL, (uint32_t)WakeUpClock);

/* Configure the Interrupt in the RTC_CR register and Enable the Wakeup Timer*/
SET_BIT(RTC->CR, (RTC_CR_WUTIE | RTC_CR_WUTE));


/* Change RTC state */
hrtc->State = HAL_RTC_STATE_READY;

...

I am wondering if there is a configuration item/setting that prevents the bits from being written to on the Cortex M33 ?

Incidently I have run the same code on the Stm32l4S7 part (Cortex M33) that we are also using, and I do not see the same behavior.

Thx in advance,

Aidan

Gyessine
ST Employee

Hello @AidanBrowne 
I am glad that you found a solution.
I recommend posting your new question in a new thread so it can be handled separately.
If one of the answers here provides a solution to your problem, mark it as a solution so it can serve as a reference for other users in the community.
Best regards,
Gyessine

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.