Now that you know what an STM32 is and what it looks like, it’s time to get your hands on one and get it to do stuff. Ambitious stuff. Like blinking an LED. Dizzying heights of human achievement.
Unless you’re already far too knowledgeable to be reading this page, or someone offered you a very unusual birthday present, you don’t own an STM32 yet. This is problematic because it’s very hard to program a device you don’t have. Luckily, this is easily remedied provided you have a few euros lying around.
1. The Nucleo Option
ST offers all sorts of development tools for their products, much like all their competitors. Unlike most of them, though, they also target “the little people”, you and me, and not just big engineering companies. As part of that strategy, they offer the very good yet extremely cheap Nucleo range of development boards, similar to Arduino boards. It’s a set of three designs adapted to MCU’s of different complexity, with prices between ten and thirty euros. Yeah, they aren’t turning a profit on those.
(Left to right : Nucleo 32, Nucleo 64 and Nucleo 144.)
The Nucleo 32 is the size of an Arduino Nano and shares most of its pinout. It’s so small you could easily fit one in an actual product, or at least a prototype. The trade-off is you’re limited to very few I/O pins, but there’s still a lot to go around.
The Nucleo 64 is the size of a credit card and can take Arduino shields, with a big caveat : Arduino’s are 5V devices, STM32 are 3.3V devices. More on that later. Moreover, it has additional connectors which bring out all of the microcontroller’s I/O pins.
The Nucleo 144 is the bad boy of the bunch : it can take Arduino Mega shields, with the same caveat regarding signal voltages, and has additional connectors to bring out all possible I/O pins. It’s designed for the largest STM32 devices and has peripherals such as Ethernet and USB.
If you intend to follow the tutorials and examples on my website, it’ll be easiest for you to use the same Nucleo. I mostly use two : the Nucleo-F303K8 (Nucleo 32) and the Nucleo-H745ZI-Q (Nucleo 144)
One thing those boards all have in common is that you don’t need any other hardware to get started : they carry their own programming and debugging probe. Such probes used to be very expensive standalone tools, but not anymore.
2. Custom Boards
You don’t have to have a Nucleo if you already have another type of STM32 board. However, using a board other than something designed by ST means the tools provided by ST don’t know about it. This will add extra steps to your journey. Nothing complicated, though, just lots of boring steps over flat terrain.
You will absolutely require a JTAG or SWD probe. If your board doesn’t carry its own, you have a choice between:
- ST-LINK probes, which are made by ST and exist in all sorts of flavor including modules and isolated versions. In a pinch, you can also use a Nucleo 64 or 144 on-board ST-LINK, as those can act as discrete probes.
- J-LINK probes, which are third-party probes made by Segger. Significantly more expensive, but they are not limited to ST microcontrollers. They are also faster.
It’s worth noting that Segger offers, for free, a J-LINK firmware for ST-LINK probes. You can find the firmware, terms and conditions at https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/ (do make sure to check the board compatibility list)
In my humble opinion, the ST-LINK works fine for any scenario. Only consider J-LINK if you happen to have one already, or it’s the end of the year and you’ve got some left-over budget to burn.
A probe and possibly a custom JTAG or SWD cable you may have to build take care of the hardware side of things. On the software side, since your board is unknown to ST, you’ll have to manually enter everything about its microcontroller, notably its pin multiplexing and how the internal peripherals and clocks are setup. That’s the boring part I mentioned.
3. “CubeIDE”
For your software development needs, ST provides a range of free software development tools under the “Cube” brand. Lately, they have been consolidated into a single tool : the STM32CubeIDE, though you can call it “CubeIDE”. If you’re new to software development, IDE stands for Integrated Development Environment. You can (and should) download it from the official page right now. Seriously, right now, because it’ll take a while to install it. It’s a big tool. You may also want to install git and create a github account if you haven’t already : that way you will be able to download and use my code very easily.
I’m not going to post screenshots here to tease you into it. The main reason is that STM32CubeIDE, which I’ll henceforth call Cube for simplicity, is a very complex tool. This ain’t no amateur grade gadget like the Arduino “IDE”. Do not let the price tag fool you : Cube is made for doing serious work and building complex projects in environments where time is money.
And most importantly, Cube supports all Nucleo boards, saving you time.
It’s important to note that CubeIDE, like almost every free IDE provided by a chip manufacturer, is built on Eclipse. That means any experience you may have on other IDE’s built on Eclipse will serve you well with CubeIDE. It also means your should install the EGit plugin pretty much immediately after you start CubeIDE for the first time. EGit is the “git integration for Eclipse” plugin.
To install EGit, go to the Help menu and open the Eclipse Marketplace, where you can search for it:
Now that you’ve got a board and the means to program it, I’ll discuss creating a simple project. For the sake of simplicity, that will target a Nucleo module : if you have a custom board, you’re probably skilled enough to extrapolate from that. See you then !