improve sleep_us for low values
This commit is contained in:
parent
252363cf02
commit
7b0af9afe0
4
global.c
4
global.c
|
@ -101,10 +101,12 @@ void led_toggle(void)
|
|||
|
||||
void sleep_us(uint32_t duration)
|
||||
{
|
||||
if (0 == 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
|
||||
return;
|
||||
}
|
||||
|
||||
duration -= 5; // 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
|
||||
|
|
Loading…
Reference in New Issue