For some time now I’ve been observing what’s happening among beginner embedded programmers. Actually, not only among them, but also in what embedded programming learning materials are passing on to future juniors. I have some serious reservations.
Problems beginners face
I have a few observations. Based on my experience, I’ve identified 6 problems that beginners run into. Some of them are clearly the fault of how knowledge is conveyed in widely available courses and tutorials.
Here’s a list of six problems that I consider the most serious on the path of a beginner embedded programmer. Let me describe them to you and give a solution for each one.
1. I’m following the tutorial and it doesn’t work!
If we run into trouble – we go to some forum or discussion group. Most often such a request for help looks like this: “Help, it doesn’t work. I’m doing everything like here *LINK* and it doesn’t run”.
Know that? For sure 🙂
I’m skipping the quality of the instructions themselves, because often that’s also the problem. For example, someone forgot to enable a required interrupt, or a cable was plugged in wrong.
It’s worse when the tutorial is outdated. It may happen that the libraries used in the course are obsolete. The examples won’t work with the latest software stack.
Such a tutorial is outdated and shouldn’t exist. I also realize that once a tutorial is written, it’s hard to constantly check and update it. Especially the free ones – because there’s no motivation to make fixes.
Solution: Let’s use reliable sources. Ones where the author continuously takes care that the course is up to date. For example this course (the course content is conducted in Polish).
2. Programming/debugging doesn’t work for me!
I see this mistake extremely often, because I run an electronics store. Most often it appears with Chinese boards that don’t have a built-in programmer.
Similarly, there are no ready-made examples that would take this programmer into account in the code. Tutorials also don’t mention that the debugging pins need to be set appropriately.
Another issue is counterfeits, which happen in Chinese boards. For example in the BluePill, i.e., a board with the STM32F103 which we love because it’s cheap.
In a Chinese programmer there is the same F103, which can also be counterfeit and not work fully correctly.
Solution: Use original boards from ST. For example: Nucleo, Discovery. There, the ST-Link is a sure thing. It’s also properly wired. Additionally, creating a project in CubeMX based on Nucleo, and not on the MCU, will always correctly configure the debug pins.
3. I’d like to do many things at once
A genre classic. We can blink one LED. The problem appears when we need to blink two, and at different rates. How do you do two delays at once?
Second situation. We have to implement debounce for buttons. 20-30 milliseconds is enough. We throw in a delay, handle 5 buttons and what? It doesn’t work very smoothly…
Additionally, when pressing one button, sometimes we miss the reaction to the second. How to live?
Solution: Learn right away to write correct code without using delays! This can’t be “something extra”. It’s the foundation of writing programs for microcontrollers. I recently showed such a simple method with a software timer on LIVE.
4. …which leads to “just use an RTOS”
Someone politely suggested that you should get interested in an RTOS. “It will do everything for you,” they say. Yeah, but…
An RTOS, i.e., a real-time operating system, is a great tool, but a very complex one. A beginner programmer will not be able to simply take a system and add it to a project. There is no magic button in the IDE “add RTOS”.
A young learner, not knowing how such systems work, will become even more discouraged from programming microcontrollers.
Such advice for someone who doesn’t know how to blink two LEDs at once is very harmful. Let’s not do that.
There’s one more problem with RTOSes. Tutorials about them are based on printing to the console and blinking LEDs. That works great in these simple examples where individual RTOS components are discussed.
It’s worse when you add I2C, ADC, DMA, and other components to the project. Suddenly the project becomes complicated and brings a lot of weird problems. It turns out that using that RTOS isn’t as simple as it seemed.
Solution: If you actually want to use an RTOS, learn it first. And learn it well. Ideally, someone should show you how to build a real project. Learning with LEDs and printing is one thing, but actually using the system is a completely different story. My students follow this whole path in the course STM32 for Beginners (the course content is conducted in Polish).
5. Working with DMA
When moving from AVR to ARM, we get a brilliant tool (or maybe rather a peripheral?) called DMA – Direct Memory Access.
It’s a microcontroller block that allows working with memory without CPU involvement.
The problem is that it’s hard for us to grasp that something is happening “in the background” outside the processor. We’re used to sequential code execution, so we often don’t know how to work with DMA.
The only thing we send to DMA is an operation “request”. We don’t handle the memory operation itself, so we can do something else in the meantime, and DMA will notify us when it’s finished.
The first mistake I see is waiting in a loop for DMA to finish the transfer. For example, we request sending data to an OLED and we wait in place until that data is sent via DMA. We don’t do that. After requesting the transfer, we go do something else.
The second mistake is replacing a function, e.g. one that transmits over I2C, with a DMA version. For example, we have an OLED with paging and we have to send 8 pages of a buffer.
Normally, without DMA, we send one after another. The CPU actively participates in the sending, so a simple for loop does the job here.
Blindly replacing transmission with a DMA transmission in such a place breaks the program! Because we have 8 transfer requests to DMA in a row. With minimal time gaps. DMA hasn’t managed to send the first page to the OLED yet, and we already tried to shove all 8 in.
The CPU will bounce off DMA because it’s busy, and what’s the effect? The OLED doesn’t work!
Solution: You need to learn how DMA works and how to interact with it. Let’s switch to the mindset that we request the transfer and wait for a sign-signal from DMA that it can accept the next chunk of data.
6. I’m looking for a library for…
Finally, searching for libraries. We’re lazy and we like ready-made solutions. Besides, it’s good to use something that has already been written before.
Arduino has accustomed us to the fact that everything is ready there. Often such libraries are written by amateurs and may contain hidden delays! The Arduino IDE itself also makes it harder to peek inside libraries, and we don’t know what they actually do. And they can do all sorts of weird things!
Another problem is that there simply aren’t as many libraries for bare STM32 as for Arduino.
And finally… what if you have a chip for which there is no library even for Arduino?
Solution: Learn to write libraries based on documentation. This will give you more freedom, and also understanding of ready-made libraries.
Secondly – learn how to correctly port libraries from other microcontrollers – e.g. Arduino. You don’t always have to write everything from scratch.
I teach these two approaches to libraries in my course STM32 for Beginners (the course content is conducted in Polish).
Where to learn this?
Most generally available courses and tutorials introduce these mistakes and problems. With each successive one, they get repeated. So where can you learn how to deal with them?
I decided that I would break with the repeated wrong patterns and create a course that solves all of the above problems. The STM32 for Beginners course will allow you to learn programming the RIGHT way.
If you learn to program correctly, your projects will be much better.
You will also land your first job, if that’s what you’re looking for. Maybe you’re looking for a better job than you have right now?
Until Friday 19.02 at 20:00 you have a chance to enroll in the course and change your programming once and for all.
All details about the course and participation in it can be found on the course page: https://kursstm32.pl (the course content is conducted in Polish).




0 Comments