The article's Delay function unfortunately has a rollover bug. If the counter rolls over in the middle of a delay, the delay will return early. It's a nefarious bug because it only occurs every 50 days, and only if the program is delaying. Also, while it's probably ok in this usage since it's a 32-bit cpu, it would be better to use atomic access intrinsics or a critical section and memory barriers rather than volatil…
Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
11–20 of 20 posts
Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#12I found quadcopters to be a great way to get into embedded development. There are a couple posts on my blog [0] [1] related to getting Rust running on a quadcopter controller, although I never actually got my code controlling the drone in flight. The lesson I learned was that if I was going to do it again I'd definitely choose a board with an exposed debugger port, as I spent a lot of time repurposing one of the moto…
Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#13I thought, the Peripheral library is deprecated for STM32. Is there any reason to use it besides the STM32 CUBE framework?. Because, the later seems to support more STM32 product lines.
The new cube library can be more complex.
Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#14CMSIS is the most bizarre API i've ever seen. This kind of mixing ALLCAPS_WithUnderscores_AndCamelCase is like criminal. Also _Min_Heap_Size. And that is the reason i would never use it and i've always looked for alternatives. Now i've ended up using Ivory/Tower eDSL framework where just about everything is equally complicated - as building a spaceshuttle.
I think that the ALLCAPS parts come from acronyms in most cases. Like, NVIC = Nested Vector Interrupt Controller. The naming can get a little bit confusing, but it seems fairly consistent.
Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#15I thought, the Peripheral library is deprecated for STM32. Is there any reason to use it besides the STM32 CUBE framework?. Because, the later seems to support more STM32 product lines.
Stm32 cube mx is the newest version of the framework, but the old peripheral driver library is a bit simpler and easier to use! It is more low level and a light layer over the hardware. The new cube library can be more complex.
Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#16The article's Delay function unfortunately has a rollover bug. If the counter rolls over in the middle of a delay, the delay will return early. It's a nefarious bug because it only occurs every 50 days, and only if the program is delaying. Also, while it's probably ok in this usage since it's a 32-bit cpu, it would be better to use atomic access intrinsics or a critical section and memory barriers rather than volatil…
What I would do in this particular case is make a note of the limitations in the function block comment. There are always trade-offs in embedded code so I think it is fair to say that yes this code does not handle rollover, FYI.
Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#17The article's Delay function unfortunately has a rollover bug. If the counter rolls over in the middle of a delay, the delay will return early. It's a nefarious bug because it only occurs every 50 days, and only if the program is delaying. Also, while it's probably ok in this usage since it's a 32-bit cpu, it would be better to use atomic access intrinsics or a critical section and memory barriers rather than volatil…
The dislike for volatile coming from people in higher systems is pretty tiring and unwarranted.
Volatile is a perfectly fine tool on low level mcus.
Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#18Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#19The article's Delay function unfortunately has a rollover bug. If the counter rolls over in the middle of a delay, the delay will return early. It's a nefarious bug because it only occurs every 50 days, and only if the program is delaying. Also, while it's probably ok in this usage since it's a 32-bit cpu, it would be better to use atomic access intrinsics or a critical section and memory barriers rather than volatil…
>Also, while it's probably ok in this usage since it's a 32-bit cpu, it would be better to use atomic access intrinsics or a critical section and memory barriers rather than volatile to make the counter variable "ISR safe". The dislike for volatile coming from people in higher systems is pretty tiring and unwarranted. Volatile is a perfectly fine tool on low level mcus.
It can be argued that the only kind of variable that can be shared safely between an ISR and the rest of the code is a volatile sig_atomic_t, but that is an argument from analogy and not from first principles, as the C abstract machine has no concept of ISR. The same goes for the argument that you should use atomic intrinsics, plausible, but still just an analogy.
(Just in case anyone was wondering if C as a language is close to the metal: no, it is not.)
Re: Quadcopter Programming Part 2: Using the CMSIS Library and First Takeoff
#20Just ordered one myself after reading your post, look forward to working on this platform!