cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in stm32h7 rtc. Cube 1.8.0

amartol
Associate

STM32CubeH7 Firmware Package V1.8.0 in function HAL_RTCEx_SetWakeUpTimer_IT bit RTC_FLAG_WUTF on register ISR not cleared, wkup timer not runned properly.

2 REPLIES 2
Imen.D
ST Employee

Hello @amartol​ and welcom

Let me first welcome you to the Community 🙂

About the missing clear of WUTF flag, all RTC API starting WakeUp Timer do clear the flag internally.

So, there should be not need to add addition clear, as the WTUF Falg is cleared when enabling the service.

When your question is answered, please close this topic by choosing Select as Best.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
amartol
Associate

Hello, @Imen DAHMEN​ !

My code works well as Cube version 1.5.0. Wakeup interrupt didn’t work in version 1.8.0 until I clear the WUTF flag manually.

Code on version 1.8.0 (wkup interrupt not work):

HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
{
  uint32_t tickstart;
 
  /* Check the parameters */
  assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
  assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
 
  /* Process Locked */
  __HAL_LOCK(hrtc);
 
  hrtc->State = HAL_RTC_STATE_BUSY;
 
  /* Disable the write protection for RTC registers */
  __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
 
  /* Clear WUTE in RTC_CR to disable the wakeup timer */
  CLEAR_BIT(RTC->CR, RTC_CR_WUTE);
 
  /* Poll WUTWF until it is set in RTC_ICSR to make sure the access to wakeup autoreload
  counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in
  calendar initialization mode. */
#if defined(RTC_ISR_INITF)
  if (READ_BIT(RTC->ISR, RTC_ISR_INITF) == 0U)
#endif /* RTC_ISR_INITF */
#if defined(RTC_ICSR_INITF)
    if (READ_BIT(RTC->ICSR, RTC_ICSR_INITF) == 0U)
#endif /* RTC_ICSR_INITF */
    {
      tickstart = HAL_GetTick();
 
#if defined(RTC_ICSR_WUTWF)
      while (READ_BIT(hrtc->Instance->ICSR, RTC_FLAG_WUTWF) == 0U)
#endif /* RTC_ICSR_WUTWF */
#if defined(RTC_ISR_WUTWF)
        while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0U)
#endif /* RTC_ISR_WUTWF */
        {
          if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
          {
            /* Enable the write protection for RTC registers */
            __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
 
            hrtc->State = HAL_RTC_STATE_TIMEOUT;
 
            /* Process Unlocked */
            __HAL_UNLOCK(hrtc);
 
            return HAL_TIMEOUT;
          }
        }
    }
 
  /* Configure the Wakeup Timer counter */
  hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
 
  /* Clear the Wakeup Timer clock source bits and configure the clock source in CR register */
  {
    uint32_t CR_tmp = hrtc->Instance->CR;
    CR_tmp &= (uint32_t)~RTC_CR_WUCKSEL;
    CR_tmp |= (uint32_t)WakeUpClock;
    hrtc->Instance->CR = CR_tmp;
  }
 
#if !defined(DUAL_CORE)
  /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
  __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
#endif
 
  __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
 
  /* Configure the Interrupt in the RTC_CR register */
  __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc, RTC_IT_WUT);
 
  /* Enable the Wakeup Timer */
  __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
 
  /* Enable the write protection for RTC registers */
  __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
 
  hrtc->State = HAL_RTC_STATE_READY;
 
  /* Process Unlocked */
  __HAL_UNLOCK(hrtc);
 
  return HAL_OK;
}

Code on old version 1.5.0, work properly (flag WUTF clear on line 43):

HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
{
  uint32_t tickstart;
 
  /* Check the parameters */
  assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
  assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
 
  /* Process Locked */
  __HAL_LOCK(hrtc);
 
  hrtc->State = HAL_RTC_STATE_BUSY;
 
  /* Disable the write protection for RTC registers */
  __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
 
  /*Check RTC WUTWF flag is reset only when wake up timer enabled*/
  if((hrtc->Instance->CR & RTC_CR_WUTE) != 0u)
  {
    tickstart = HAL_GetTick();
 
    /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */
    while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 1u)
    {
      if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
      {
        /* Enable the write protection for RTC registers */
        __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
 
        hrtc->State = HAL_RTC_STATE_TIMEOUT;
 
        /* Process Unlocked */
        __HAL_UNLOCK(hrtc);
 
        return HAL_TIMEOUT;
      }
    }
  }
  /* Disable the Wake-Up timer */
  __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
 
  /* Clear flag Wake-Up */
  __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
 
  tickstart = HAL_GetTick();
 
  /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
  while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0u)
  {
    if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
    {
      /* Enable the write protection for RTC registers */
      __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
 
      hrtc->State = HAL_RTC_STATE_TIMEOUT;
 
      /* Process Unlocked */
      __HAL_UNLOCK(hrtc);
 
      return HAL_TIMEOUT;
    }
  }
 
  /* Configure the Wakeup Timer counter */
  hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
 
  /* Clear the Wakeup Timer clock source bits in CR register */
  hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
 
  /* Configure the clock source */
  hrtc->Instance->CR |= (uint32_t)WakeUpClock;
 
#if !defined(DUAL_CORE)
  /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
   __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
#endif
 
   __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
  /* Configure the Interrupt in the RTC_CR register */
  __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
 
  /* Enable the Wakeup Timer */
  __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
 
  /* Enable the write protection for RTC registers */
  __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
 
  hrtc->State = HAL_RTC_STATE_READY;
 
  /* Process Unlocked */
  __HAL_UNLOCK(hrtc);
 
  return HAL_OK;
}