stm32微秒延时问题
stm32微秒延时问题
不采用freertos情况下,可以使用以下代码,使用sysytick的方式读取:
#define CPU_FREQUENCY_MHZ 72 // STM32系统时钟主频 void delay_us(__IO uint32_t delay) { int last, curr, val; int temp; while (delay != 0) { temp = delay > 900 ? 900 : delay; last = SysTick->VAL; curr = last - CPU_FREQUENCY_MHZ * temp; if (curr >= 0) { do { val = SysTick->VAL; } while ((val < last) && (val >= curr)); } else { curr += CPU_FREQUENCY_MHZ * 1000; do { val = SysTick->VAL; } while ((val <= last) || (val > curr)); } delay -= temp; } }
使用freertos时,systick被占:链接