delay_us_systick.c 360 B

12345678910111213141516
  1. /**
  2. * Delay
  3. * no interrupt, clk = sysclk/8
  4. * не проверял пока.
  5. */
  6. inline void _delay_us(uint32_t us) {
  7. if (us > 0xFFFFFFUL) {
  8. us = 0xFFFFFFUL;
  9. }
  10. us *= (STM32_HCLK/8);
  11. SysTick->LOAD = us;
  12. SysTick->VAL = 0;
  13. SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;
  14. while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
  15. SysTick->CTRL = 0;
  16. }