From 92c33da652b48b8e112465e6f7a7a1e8da194be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 10 Dec 2020 23:52:48 +0100 Subject: [PATCH] global: improve sleep_us for STM32F4 --- global.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global.c b/global.c index bd39b73..cfef145 100644 --- a/global.c +++ b/global.c @@ -164,12 +164,12 @@ inline void led_toggle(void) void sleep_us(uint32_t duration) { - if (duration <= 5) { // less than the setup time - for (volatile uint32_t nop = 0; nop < 5 * duration; nop++); // busy loop, approximate, hand tuned for 72 MHz system clock + if (duration <= 4) { // less than the setup time + for (volatile uint32_t nop = 0; nop < 5 * duration; nop++); // busy loop, approximate return; } - duration -= 5; // subtract setup time + duration -= 4; // subtract setup time systick_counter_disable(); // disable SysTick to reconfigure it if (!systick_set_frequency(1000000, rcc_ahb_frequency)) { // set SysTick frequency to microseconds while (true); // unhandled error