here's why I bought an STM32 development board
I recently purchased an STM32 development board -- specifically a Nucleo-F411RE development board to learn bare metal programming and here's why.
To understand why, first some context. A few months ago I landed a job in an industry I've been dreaming of getting into for a very long time; I landed a job as junior embedded systems programmer. Well not entirely because the person who recommended me for the role told me it was a software engineer job and in the part of the world I live, usually that's a web development job.
I applied anyway because I needed to start putting my skills to use while being paid. To keep this brief, when I got to the place for my interview, was informed about the kind of work the company is into and I knew immediately I had to do my best to get in no matter what! If you're reading then good news because I did and underwent training for a few months to rebuild my C programming skills and was subsequently put into a new team; the embedded team, a ragtag team of two (for now) of myself writing firmware using an Olimex as a development board and my team leader, a highly competent and smart electrical engineer (this is going somewhere I promise).
Anyway I was and still am very excited because I get to do something I've been dreaming about for a very long time and that's working as close to the hardware as possible. This was about two months ago and so far I've been having a blast. Everything is as I expected and even more; I've had and will have very frustrating moments where I questioned everything I knew, moments I've felt on top of the world after overcoming crazy challenges and more. When working with an 8-bit microcontroller, the ATmega32U4, on a daily with only 32Kb of flash and a measly 2.5Kb of RAM, you adapt quickly or sink and looking back I've noticed significant improvements in my optimization skills (still have a really long way to go however). To put how small that flash is in context, the very first image when you look up ATmega32U4 is about 8x larger in size that the entire flash available for the microcontroller itself!
Anyway back to topic; if I'm already doing work that sounds challenging and already doing bare metal programming as my daily work, why buy another board and not just stick to what I use at work? The reason is simple really; I'm having a blast and want to explore more architectures outside of what I do outside of work. Let me explain.
a "black+white = grayish" comparison
First some details about the microprocessor on Nucleo board. The Nucleo-F411RE houses a very powerful chip, an STM32F4R11RE (which I'll refer to as the STM32 henceforth)... well relative to the ATmega32U4. To put this into perspective, let's take a look at the specs of the ATmega32U4 (it gets pretty technical here but I'll keep everything simple).
The ATmega32U4 has a humble 2.5Kb of RAM and 32Kb of flash memory as I stated above. It's an 8-bit microcontroller which means it operates on data natively at 8-bits; basically a series of 8 individual ones and zeroes. This means it can easily work on numbers between 0 and 255 without breaking a sweat and while it can do bigger numbers like 16-bit or 32-bit it has to do extra work. Think of it like lifting a chair that's 16kg or 32kg but you can comfortably carry a hard limit of 8kg.
Your best bet is to get someone to help you or you can find a way to dismantle the chair to carry it in parts. Not the best analogy but that's what I can come up with bare with me. With that it comes with a maximum frequency of 16MHz, which allows it to perform up to 16 million instructions a second and synchronize its internal operations, it's a solid and complex microcontroller with tons of capabilities. Mind you this is a very naive oversimplification of these terms but it's still accurate enough.
Now to put into perspective how much more powerful the STM32F411RE is, it comes with 512Kb of flash (that's 16x that of the ATmega32U4), 128Kb of SRAM (that's ~52x the RAM) and a jaw dropping frequency of 100MHz (that's 6x faster than the ATmega32U4 hands down). On top of that, it's a 32-bit ARM Cortex-M4 chip. If that's not impressive enough, the STM32's microprocessor runs laps around the ATmega32U4. A task that would take the ATmega32U4, four instructions to execute, would take the STM32 just one! What would take two for the STM32 would take about eight. Hopefully that paints the idea of how powerful it is. Obviously there are more powerful microprocessors out than that run laps around the STM32 but that's for another day.
Why not just make all microcontrollers as powerful as the STM32 then, you might be saying. Well it usually comes down certain tradeoffs that are not easy to dismiss. I'll cover that in another post some day and come back to update this section when I do. The point is the STM32 is extremely powerful like a beefed up ATmega32U4.
get to it buddy, what's the big idea?
I bought the Nucleo board on Amazon and it arrived a few days ago before writing this. Up top I mentioned I was having a blast and wanted to explore more architectures but that's not the whole truth. I'll get easy ones of the way.
The first reason I bought this is because I'm having lots of fun programming on the Olimex. The fact that I can write code and see it have some impact on the hardware is such a joy to me and I'll never get over it. I can write a single line of code that will toggle an LED, code that can exchange data between two peripherals all without needing an operating system handling any of it is just magical. For this reason I wanted to explore the same idea on another architecture, one with a larger word size that enables so much more than the limited but incredibly useful 8-bit microcontroller.
The second and probably main reason is I want to prepare myself for the wider industry. If you investigate industries that rely on embedded systems like automotive and many more, they rely on 32-bit and higher architectures. 8-bit computing like the ones on the ATmega32U4 is still in use don't get me wrong but mostly by hobbyists and for small projects. One of the biggest companies relying on these 8-bit microcontrollers is Arduino for their Arduino Uno boards and although they have 32-bit boards, the 8-bit boards are greater in number and in higher circulation.
Ideally this is a good thing but from my research and even work I do, most people using Arduino boards are either prototyping a device which they'll then switch off to a higher word size microprocessor or are just getting started. This is because the 8-bit boards are very limiting if you want to do complex stuff and Arduino libraries already carry a lot of baggage; a tradeoff that makes working with them very simple. If you visited the page I linked to the Olimex, you'll notice it's based on Arduino designs which means technically Arduino code can run on the board but I don't rely on Arduino libraries at all. In fact I have to write any functionality I need from scratch based on data sheets (contains important information about the microcontroller) and libraries that define registers for me.
My goal is to keep sharpening my skills for the fast-moving embedded systems industry. I want to make sure I’m not just comfortable on 8-bit chips, but also confident with 32-bit architectures when the time comes. That way, if our team ever decides to take on projects with more powerful microcontrollers, I’ll already be prepared to contribute right away. foresight
This last one's not really a reason but an opportunity, second chance, whatever you call it, that I realized when I got this board. Essentially when I started out as a junior embedded systems programmer some months ago, I made plans to write posts about the new concepts I'm learning to document and share my progress. Unfortunately timelines get in the way and company interests have me moving fast so I couldn't keep up with that idea. I wanted to share all these new and exciting things I was learning and working on but I couldn't. Now, however, that's can change because as I learn the ins and outs of the STM32, I'll revisit and act on that idea by documenting and sharing everything I'm learning. I'll compare and contrast things between both the 8-bit and 32-bit processors and this post is the first in a series of posts.
so, what now?
Right now, I've managed to set up an environment where I'm comfortable writing code. Typically I'm working in neovim and practically live in the terminal. With how powerful the STM32 is, it comes with more complexities than the ATmega32U4. I've only looked at some examples and from what I've seen, the ATmega32U4 has made things very easy when it comes working with chips at this level of computing. In future posts I'll share the main differences and what I mean.
In preparation, I've downloaded several official documents for the STM32 that I'll using as a sources of reference and truth as I learn and practice on the microprocessor. The documents are the reference manual which contains how to work with the myriad registers available, the data sheet which tells you “what this specific device is”, how much flash, how many timers, pin mapping, electrical limits and more and the programmer's manual which is about the ARM Cortex-M core itself, not STM32. It explains instructions, exception handling, registers like NVIC, SysTick and many more. I don't understand everything I just listed but have a fair idea what they are and that's the point of learning and documenting.
I'll commit about an hour everyday learning how to work with this microprocessor well past when I am as confident with it as I'm getting with the ATmega32U4. I'll do my absolute best to share all my findings and lessons in posts like this in the future without fail. The goal is not perfection but consistency over time.
To wrap up, my first goal is to do the hello world of embedded programming, blink an LED every second (something I can do with my eyes closed on the ATmega32U4). It doesn't sound exciting but compounding effect and learning a new architecture is the way to go. That'll be the topic for my next post on this series.
Thank you for reading and I encourage you to share, someone as interested might be lurking on your timeline or in your mutuals :)