38 #define TM_DELAY_H 100
92 #include "stm32fxxx_hal.h"
106 #ifndef DELAY_MAX_CUSTOM_TIMERS
107 #define DELAY_MAX_CUSTOM_TIMERS 5
111 #ifndef LIB_ALLOC_FUNC
112 #define LIB_ALLOC_FUNC malloc
116 #ifndef LIB_FREE_FUNC
117 #define LIB_FREE_FUNC free
157 extern __IO uint32_t TM_Time;
158 extern __IO uint32_t TM_Time2;
184 __STATIC_INLINE
void Delay(__IO uint32_t micros) {
185 #if !defined(STM32F0xx)
186 uint32_t start = DWT->CYCCNT;
189 micros *= (HAL_RCC_GetHCLKFreq() / 1000000);
192 while ((DWT->CYCCNT - start) < micros);
195 micros *= (SystemCoreClock / 1000000) / 5;
207 __STATIC_INLINE
void Delayms(uint32_t millis) {
217 #define TM_DELAY_Time() (TM_Time)
224 #define TM_DELAY_SetTime(time) (TM_Time = (time))
232 #define TM_DELAY_Time2() (TM_Time2)
240 #define TM_DELAY_SetTime2(time) (TM_Time2 = (time))
__STATIC_INLINE void Delay(__IO uint32_t micros)
Delays for amount of micro seconds.
Definition: tm_stm32_delay.h:184
Custom timer structure.
Definition: tm_stm32_delay.h:133
TM_DELAY_Timer_t * TM_DELAY_TimerAutoReloadCommand(TM_DELAY_Timer_t *Timer, uint8_t AutoReloadCmd)
Sets auto reload feature for timer.
TM_DELAY_Timer_t * TM_DELAY_TimerStop(TM_DELAY_Timer_t *Timer)
Stops custom timer from counting.
uint8_t CNTEN
Definition: tm_stm32_delay.h:137
TM_DELAY_Timer_t * TM_DELAY_TimerCreate(uint32_t ReloadValue, uint8_t AutoReloadCmd, uint8_t StartTimer, void(*TM_DELAY_CustomTimerCallback)(struct _TM_DELAY_Timer_t *, void *), void *UserParameters)
Creates a new custom timer which has 1ms resolution.
void(* Callback)(struct _TM_DELAY_Timer_t *, void *)
Definition: tm_stm32_delay.h:143
void TM_DELAY_TimerDelete(TM_DELAY_Timer_t *Timer)
Deletes already allocated timer.
struct _TM_DELAY_Timer_t TM_DELAY_Timer_t
Custom timer structure.
TM_DELAY_Timer_t * TM_DELAY_TimerAutoReloadValue(TM_DELAY_Timer_t *Timer, uint32_t AutoReloadValue)
Sets auto reload value for timer.
TM_DELAY_Timer_t * TM_DELAY_TimerReset(TM_DELAY_Timer_t *Timer)
Resets custom timer counter value.
uint32_t CNT
Definition: tm_stm32_delay.h:142
TM_DELAY_Timer_t * TM_DELAY_TimerStart(TM_DELAY_Timer_t *Timer)
Starts custom timer counting.
uint32_t ARR
Definition: tm_stm32_delay.h:141
__STATIC_INLINE void Delayms(uint32_t millis)
Delays for amount of milli seconds.
Definition: tm_stm32_delay.h:207
void TM_DELAY_1msHandler(void)
User function, called each 1ms when interrupt from timer happen.
uint32_t TM_DELAY_Init(void)
Initializes delay functions.
void * UserParameters
Definition: tm_stm32_delay.h:144
uint8_t AREN
Definition: tm_stm32_delay.h:136