mbed

Fork of mbed-dev by mbed official

Revision:
168:9672193075cf
Parent:
167:e84263d55307
Child:
175:b96e65c34a4d
diff -r e84263d55307 -r 9672193075cf targets/TARGET_STM/us_ticker_32b.c
--- a/targets/TARGET_STM/us_ticker_32b.c	Wed Jun 21 17:46:44 2017 +0100
+++ b/targets/TARGET_STM/us_ticker_32b.c	Thu Jul 06 15:42:05 2017 +0100
@@ -44,14 +44,16 @@
 void us_ticker_set_interrupt(timestamp_t timestamp)
 {
     TimMasterHandle.Instance = TIM_MST;
+    // disable IT while we are handling the correct timestamp
+    __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
     // Set new output compare value
     __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
-    // Enable IT
-    __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
     // Check if timestamp has already passed, and if so, set the event immediately
     if ((int32_t)(timestamp - TIM_MST->CNT) <= 0) {
         LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
     }
+    // Enable IT
+    __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
 }
 
 void us_ticker_disable_interrupt(void)