Without microseconds, you’re just an outsider

As it is, the HAL library comes with a tick at every 1 millisecond, like a “millis” in an Arduino library. It is your application’s timer, allowing you to plan timed, non-blocking tasks, like in a real-time operating system. But no microsecond delay function provided 😦 . And you know, many initialization procedures or protocols of different external peripherals require microsecond delays in data flux.

Of course I started to search for already written code and I came across Domen Jurkovic code on github, but his assembler code didn’t compiled on my toolchain (sure it worked on his toolchain). I continued the search and found on the Mapple library an assembler code that compiled ok on my toolchain and resulted in a function that actually works. I tuned the code to work correctly on my 32MHz clock (look in my repository – link on the right panel).


asm volatile(" mov r0, %[us] \n\t"
"1: subs r0, #5 \n\t"
" bhi 1b \n\t"
:
: [us] "r" (us)
: "r0");

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.