2015-01-13 08:25 AM
I use #define micros() SysTick->VAL + HAL_GetTick()*1000
is it true ?2015-01-13 08:35 AM
I use #define micros() SysTick->VAL + HAL_GetTick()*1000
is it true ?
HAL_GetTick() depends on interrupts functioning, and there's likely a potential race hazard here. Why not use a free running 32-bit counter?2015-01-13 09:20 AM
I want to make a general library for stm32 micro
I found the way .h #ifndef _GENERAL_LIB_H #define _GENERAL_LIB_H #ifdef __cplusplus extern ''C'' { #endif #include ''stm32f4xx_hal.h'' uint32_t millis(void); uint32_t micros(void); void delay_us(uint32_t delay); #define delay_ms(delay) HAL_Delay(delay) #ifdef __cplusplus } #endif #endif .c #include ''general_lib.h'' ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// uint32_t millis(void) { return HAL_GetTick(); } ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// uint32_t micros(void) { uint32_t clock1 = (SystemCoreClock/1000); uint32_t clock2 = (SystemCoreClock/1000000); return ((clock1-SysTick->VAL)/clock2 +(HAL_GetTick()*1000)); } ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// void delay_us(uint32_t delay) { uint32_t d2; d2= micros(); while(micros() - d2 < delay); }