Merge pull request #134 from qjones81/timer-fix

Fix microsecond timer delay code.
This commit is contained in:
Oskar Weigl
2018-03-05 20:38:33 -08:00
committed by GitHub
2 changed files with 7 additions and 5 deletions
+2
View File
@@ -69,6 +69,8 @@
#define TIM_APB1_CLOCK_HZ 84000000
#define TIM_APB1_PERIOD_CLOCKS 4096
#define TIM_APB1_DEADTIME_CLOCKS 40
#define TIM_TIME_BASE TIM14
#define M0_nCS_Pin GPIO_PIN_13
#define M0_nCS_GPIO_Port GPIOC
+5 -5
View File
@@ -187,13 +187,13 @@ uint32_t timeout_to_deadline(uint32_t timeout_ms) {
// @brief: Returns number of microseconds since system startup
uint32_t micros(void) {
uint32_t usTicks = HAL_RCC_GetSysClockFreq() / 1000000;
register uint32_t ms, cycle_cnt;
do {
ms = HAL_GetTick();
cycle_cnt = SysTick->VAL;
} while (ms != HAL_GetTick());
return (ms * 1000) + (usTicks * 1000 - cycle_cnt) / usTicks;
cycle_cnt = TIM_TIME_BASE->CNT;
} while (ms != HAL_GetTick());
return (ms * 1000) + cycle_cnt;
}
// @brief: Busy wait delay for given amount of microseconds (us)
@@ -203,4 +203,4 @@ void delay_us(uint32_t us)
while (micros() - start < (uint32_t) us) {
__ASM("nop");
}
}
}