Skip to content

Commit fc41c05

Browse files
jeromecoutantadbridge
authored andcommitted
STM32F7 : RTC Wake Up Timer issue
1 parent 61ecc3a commit fc41c05

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_rtc_ex.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,33 +1063,54 @@ HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t
10631063

10641064
/* Disable the write protection for RTC registers */
10651065
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1066-
1067-
__HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
1068-
1069-
/* Get tick */
1070-
tickstart = HAL_GetTick();
10711066

1072-
/*Check RTC WUTWF flag is reset only when wake up timer enabled*/
1067+
/*Check RTC WUTWF flag is reset only when wake up timer enabled*/
10731068
if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET)
10741069
{
1075-
/* Wait till RTC WUTWF flag is set and if Time out is reached exit */
1076-
while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
1070+
tickstart = HAL_GetTick();
1071+
1072+
/* Wait till RTC WUTWF flag is reset and if Time out is reached exit */
1073+
while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET)
10771074
{
10781075
if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
10791076
{
10801077
/* Enable the write protection for RTC registers */
10811078
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
10821079

1083-
hrtc->State = HAL_RTC_STATE_TIMEOUT;
1084-
1085-
/* Process Unlocked */
1080+
hrtc->State = HAL_RTC_STATE_TIMEOUT;
1081+
1082+
/* Process Unlocked */
10861083
__HAL_UNLOCK(hrtc);
1087-
1084+
10881085
return HAL_TIMEOUT;
10891086
}
10901087
}
10911088
}
1092-
1089+
/* Disable the Wake-Up timer */
1090+
__HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
1091+
1092+
/* Clear flag Wake-Up */
1093+
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
1094+
1095+
tickstart = HAL_GetTick();
1096+
1097+
/* Wait till RTC WUTWF flag is set and if Time out is reached exit */
1098+
while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
1099+
{
1100+
if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
1101+
{
1102+
/* Enable the write protection for RTC registers */
1103+
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1104+
1105+
hrtc->State = HAL_RTC_STATE_TIMEOUT;
1106+
1107+
/* Process Unlocked */
1108+
__HAL_UNLOCK(hrtc);
1109+
1110+
return HAL_TIMEOUT;
1111+
}
1112+
}
1113+
10931114
/* Configure the Wakeup Timer counter */
10941115
hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
10951116

@@ -1098,15 +1119,12 @@ HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t
10981119

10991120
/* Configure the clock source */
11001121
hrtc->Instance->CR |= (uint32_t)WakeUpClock;
1101-
1122+
11021123
/* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
11031124
__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
1104-
1105-
EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
1106-
1107-
/* Clear RTC Wake Up timer Flag */
1108-
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
1109-
1125+
1126+
__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
1127+
11101128
/* Configure the Interrupt in the RTC_CR register */
11111129
__HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
11121130

0 commit comments

Comments
 (0)