36
36
#include "mbed_error.h"
37
37
38
38
extern void rtc_synchronize (void );
39
+ extern void save_timer_ctx (void );
40
+ extern void restore_timer_ctx (void );
39
41
40
42
/* Wait loop - assuming tick is 1 us */
41
43
static void wait_loop (uint32_t timeout )
@@ -161,8 +163,7 @@ void hal_deepsleep(void)
161
163
// Disable IRQs
162
164
core_util_critical_section_enter ();
163
165
164
- // Save the timer counter value in order to reprogram it after deepsleep
165
- uint32_t EnterTimeUS = us_ticker_read ();
166
+ save_timer_ctx ();
166
167
167
168
// Request to enter STOP mode with regulator in low power mode
168
169
#if TARGET_STM32L4
@@ -187,6 +188,7 @@ void hal_deepsleep(void)
187
188
#else /* TARGET_STM32L4 */
188
189
HAL_PWR_EnterSTOPMode (PWR_LOWPOWERREGULATOR_ON , PWR_STOPENTRY_WFI );
189
190
#endif /* TARGET_STM32L4 */
191
+
190
192
// Verify Clock Out of Deep Sleep
191
193
ForceClockOutofDeepSleep ();
192
194
@@ -199,12 +201,7 @@ void hal_deepsleep(void)
199
201
* deep sleep */
200
202
wait_loop (500 );
201
203
202
- // Reprogram the timer counter value saved before the deepsleep
203
- TIM_HandleTypeDef TimMasterHandle ;
204
- TimMasterHandle .Instance = TIM_MST ;
205
- __HAL_TIM_SET_COUNTER (& TimMasterHandle , EnterTimeUS );
206
- __HAL_TIM_CLEAR_FLAG (& TimMasterHandle , TIM_FLAG_CC1 );
207
- __HAL_TIM_ENABLE_IT (& TimMasterHandle , TIM_IT_CC1 );
204
+ restore_timer_ctx ();
208
205
209
206
#if DEVICE_RTC
210
207
/* Wait for RTC RSF bit synchro if RTC is configured */
@@ -216,6 +213,7 @@ void hal_deepsleep(void)
216
213
rtc_synchronize ();
217
214
}
218
215
#endif
216
+
219
217
// Enable IRQs
220
218
core_util_critical_section_exit ();
221
219
}
0 commit comments