diff --git a/README.md b/README.md index 57a9791..0cc739d 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,13 @@ Configuration: TIM time base must be started before using `sta::delayUs` by calling `sta::initHAL`. When using the startup system task this is handled automatically. +Steps to enable delayUs: +* Include sta/devices/stm32/delay.hpp in the file where the delayUs function is called +* Enable a timer TIM in .ioc file with the settings: Slave Mode=Disable, Trigger Mode=Disable, Clock Source=Internal Clock, all other channels =Disable) +* Define STA_STM32_DELAY_US_TIM in App/Inc/sta/config.hpp as the timer handle (can be found in Core/Inc/tim.h). For TIM1, this would be htim1 +* Do not use this timer for delays of over 1000 us; we have delayMs for that + + ## Interfaces diff --git a/include/sta/devices/stm32/delay.hpp b/include/sta/devices/stm32/delay.hpp index 6fbd3c5..81b3bb1 100644 --- a/include/sta/devices/stm32/delay.hpp +++ b/include/sta/devices/stm32/delay.hpp @@ -44,7 +44,7 @@ namespace sta * * @param us Microseconds */ - void delayUs(uint32_t us); + void delayUs(uint16_t us); #endif // STA_STM32_DELAY_US_TIM diff --git a/include/sta/devices/stm32/init.hpp b/include/sta/devices/stm32/init.hpp index 7fee75f..cd34558 100644 --- a/include/sta/devices/stm32/init.hpp +++ b/include/sta/devices/stm32/init.hpp @@ -5,6 +5,7 @@ #ifndef STA_CORE_STM32_INIT_HPP #define STA_CORE_STM32_INIT_HPP +#include namespace sta { diff --git a/src/devices/stm32/delay.cpp b/src/devices/stm32/delay.cpp index 8f51d73..dba0891 100644 --- a/src/devices/stm32/delay.cpp +++ b/src/devices/stm32/delay.cpp @@ -62,10 +62,11 @@ namespace sta return (updateFreq >= 1000000); } - void delayUs(uint32_t us) + void delayUs(uint16_t us) { // Check if the specified timer is usable for microsecond delays. STA_ASSERT(isValidDelayUsTIM()); + STA_ASSERT(us < 1000); __HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0); while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul);