added a delay check and updated README

This commit is contained in:
Iveta 2024-04-20 15:58:36 +03:00
parent 7cc6108a40
commit 3fe276f19d
4 changed files with 11 additions and 2 deletions

View File

@ -85,6 +85,13 @@ Configuration:
TIM time base must be started before using `sta::delayUs` by calling `sta::initHAL`. TIM time base must be started before using `sta::delayUs` by calling `sta::initHAL`.
When using the startup system task this is handled automatically. 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 ## Interfaces

View File

@ -44,7 +44,7 @@ namespace sta
* *
* @param us Microseconds * @param us Microseconds
*/ */
void delayUs(uint32_t us); void delayUs(uint16_t us);
#endif // STA_STM32_DELAY_US_TIM #endif // STA_STM32_DELAY_US_TIM

View File

@ -5,6 +5,7 @@
#ifndef STA_CORE_STM32_INIT_HPP #ifndef STA_CORE_STM32_INIT_HPP
#define STA_CORE_STM32_INIT_HPP #define STA_CORE_STM32_INIT_HPP
#include <sta/devices/stm32/hal.hpp>
namespace sta namespace sta
{ {

View File

@ -62,10 +62,11 @@ namespace sta
return (updateFreq >= 1000000); return (updateFreq >= 1000000);
} }
void delayUs(uint32_t us) void delayUs(uint16_t us)
{ {
// Check if the specified timer is usable for microsecond delays. // Check if the specified timer is usable for microsecond delays.
STA_ASSERT(isValidDelayUsTIM()); STA_ASSERT(isValidDelayUsTIM());
STA_ASSERT(us < 1000);
__HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0); __HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0);
while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul); while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul);