global: improve sleep_us for STM32F4

This commit is contained in:
King Kévin 2020-12-10 23:52:48 +01:00
parent 374aaacea5
commit 92c33da652
1 changed files with 3 additions and 3 deletions

View File

@ -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