AnsweredAssumed Answered

Periodic wakeup interrupt does not raise

Question asked by d.urbano on Nov 12, 2014
Latest reply on Nov 30, 2015 by Schocke.Sebastian
Hi at all,
I'm working on an stm32f4 trying to use the RTC periodic interrupt but it doesn't work; I'm using an RTC with a 32.768KHz external oscillator and a working frequency of 1Hz. The RTC set-up is quite simple:
01.HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc)
02.{
03.  /* Check the RTC peripheral state */
04.  if(hrtc == NULL)
05.  {
06.     return HAL_ERROR;
07.  }
08.   
09.  /* Check the parameters */
10.  assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat));
11.  assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv));
12.  assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv));
13.  assert_param (IS_RTC_OUTPUT(hrtc->Init.OutPut));
14.  assert_param (IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity));
15.  assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType));
16.     
17.  if(hrtc->State == HAL_RTC_STATE_RESET)
18.  {
19.    /* Initialize RTC MSP */
20.    HAL_RTC_MspInit(hrtc);
21.  }
22.   
23.  /* Set RTC state */ 
24.  hrtc->State = HAL_RTC_STATE_BUSY; 
25.        
26.  /* Disable the write protection for RTC registers */
27.  __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
28. 
29.  /* Set Initialization mode */
30.  if(RTC_EnterInitMode(hrtc) != HAL_OK)
31.  {
32.    /* Enable the write protection for RTC registers */
33.    __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
34.     
35.    /* Set RTC state */
36.    hrtc->State = HAL_RTC_STATE_ERROR;
37.     
38.    return HAL_ERROR;
39.  }
40.  else
41.  {
42.    /* Clear RTC_CR FMT, OSEL and POL Bits */
43.    hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL));
44.    /* Set RTC_CR register */
45.    hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity);
46.     
47.    /* Configure the RTC PRER */
48.    hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv);
49.    hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16);
50.     
51.    /* Exit Initialization mode */
52.    hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
53.     
54.    hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE;
55.    hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType);
56.     
57.    /* Enable the write protection for RTC registers */
58.    __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
59.     
60.    /* Set RTC state */
61.    hrtc->State = HAL_RTC_STATE_READY;
62.     
63.    return HAL_OK;
64.  }
65.}
like the interrupt configuration:
01.HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
02.{
03.  uint32_t tickstart = 0;
04.   
05.  /* Check the parameters */
06.  assert_param(IS_WAKEUP_CLOCK(WakeUpClock));
07.  assert_param(IS_WAKEUP_COUNTER(WakeUpCounter));
08.   
09.  /* Process Locked */
10.  __HAL_LOCK(hrtc);
11.   
12.  hrtc->State = HAL_RTC_STATE_BUSY;
13.   
14.  /* Disable the write protection for RTC registers */
15.  __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
16.   
17.  __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
18. 
19.  /* Get tick */
20.  tickstart = HAL_GetTick();
21. 
22.  /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
23.  while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
24.  {
25.    if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
26.    {
27.      /* Enable the write protection for RTC registers */
28.      __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
29.       
30.      hrtc->State = HAL_RTC_STATE_TIMEOUT;
31.       
32.      /* Process Unlocked */
33.      __HAL_UNLOCK(hrtc);
34.       
35.      return HAL_TIMEOUT;
36.    
37.  }
38.   
39.  /* Configure the Wakeup Timer counter */
40.  hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
41. 
42.  /* Clear the Wakeup Timer clock source bits in CR register */
43.  hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
44. 
45.  /* Configure the clock source */
46.  hrtc->Instance->CR |= (uint32_t)WakeUpClock;
47.   
48.  /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
49.  __HAL_RTC_EXTI_ENABLE_IT(RTC_EXTI_LINE_WAKEUPTIMER_EVENT);
50.   
51.  EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
52.   
53.  /* Configure the Interrupt in the RTC_CR register */
54.  __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
55.   
56.  /* Enable the Wakeup Timer */
57.  __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
58.     
59.  /* Enable the write protection for RTC registers */
60.  __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
61.   
62.  hrtc->State = HAL_RTC_STATE_READY;  
63.   
64.  /* Process Unlocked */
65.  __HAL_UNLOCK(hrtc);
66.  
67.  return HAL_OK;
68.}
but however the interrupt does not start. I'm quite sure the problem is in the configuration (I'm using the CubeMX generated API), but I can't understand where is it. Please could anyone help me ?
Regards

Outcomes