An STM32 microcontroller is traditionally programmed through its JTAG interface. That interface, when used with actual, works-for-a-living professional development software, will let you flash code into your MCU but also debug with breakpoints and even analyze your code’s variables in real time as it executes. That’s how we roll.
JTAG is both a protocol and several physical interfaces. STM32 microcontrollers usually support the SWD physical interface, short for Serial Wire Debug.
1.1. The Programming Hardware
ST’s own Nucleo development boards come with an on-board SWD interface, which is implemented using a second STM32. As you can imagine, that’s a lot of extra hardware. Of course, there’s no such thing on the Maple Mini. Do not be mistaken : the USB connector is here to let you use the MCU’s own USB device peripheral.
So how do you program it ?
The Maple Mini does expose all the pins of the STM32F103. This includes its SWD pins. All you need to do is connect a standalone JTAG probe to those pins. There are various options but because I’m a simple man, I use the official ST-Link/V2 probe. At around 25 Euros it’s not the cheapest… but it is official.
All joking aside, this cute little toy is just a self-contained, standalone version of the probe that’s present on all Nucleo boards, so if you really don’t want to spend 25 Euros or find the probe’s aesthetic questionable, you can just buy any Nucleo-64 board instead. They cost around 10 Euros and you can cut the probe from the rest of the board. Then it’d look like this :
Whichever option you pick, you will need to read its documentation in order to find out which signals come out of which pins on which connectors. For the standalone probe, that’s actually very easy : it uses a standard JTAG 2 x 10 pins connector.
For the sake of ergonomics and avoiding time-consuming human errors, it’s best to construct an SWD cable that will go from your probe to your target module. If you’re not there yet, you can start by using individual wire straps, so-called “Dupont wires” :
However, if you’re going to build a prototype board around a Maple Mini, you will need to add pin headers for the SWD interface. I strongly suggest you place them in a single row.
A very useful trick to learn regarding Dupont wires : while they are built as individual wires, it’s possible to buy empty shells with any number of pins from 2 to 20, and with either one or two rows of pins. Don’t waste time crimping your own terminals onto your own cables unless you need long cables : just remove the single-pin shells from your Dupont wires and use the “naked” wires to build the cable you want. It’ll look something like this :
I’m sure you’ve already figured out it’s a lot easier to handle a single big connector than a bunch of loose wires.
1.2. The SWD Interface
Although it’s always some form of a JTAG interface, STM32 MCU’s usually provide several programming interface options. It mostly boils down to how many pins of your MCU you want to dedicate to it. On small MCU’s like the STM32F103, you’ll want use as few pins as possible. Each pin you’re using for debugging is one less pin your application can use, so why limit your options ? On such a small chip, you will not see any benefit from using the higher pin-count JTAG interfaces.
The relevant option is therefore Serial Wire Debug (SWD). It only uses two pins to carry the JTAG protocol. I’ve circled them in red on this pinout diagram, they are PA13 and PA14.
To work properly, your ST-Link/V2 probe will need two other wires :
- “VAPP” (Application Voltage) is your MCU’s 3.3 V power supply rail. The probe needs it in order to adapt its own I/O voltage and not fry your MCU. Connect it to one of the Maple Mini’s 3.3 V pins.
- The ground. I don’t I need to explain why you need the ground.
1.3. The Programming Software
Since we’re using a standard JTAG interface and a probe that has its own drivers, it’s possible to use any professional IDE to code, compile, flash and debug code on the Maple Mini. As long as that IDE can target ARM Cortex-M microcontrollers, of course. The options are listed at https://www.st.com/en/microcontrollers-microprocessors/stm32f1-series.html#tools-software
The cheapest option, which is cheapest by virtue of being free, is ST’s very own tool, STM32CubeIDE, which everyone shortens to just “Cube”. Cube is an Eclipse-based IDE that integrates device configuration tools. Cube is also way outside the scope of this article.
If you do not have Cube installed on your PC, then install it. I’m only bringing it up here because its device configuration tool will require you to configure your MCU’s JTAG interface to match the hardware connection you’re actually going to use. Makes sense, right ?
It’ll look like this :
You’ll know it when you see it.
And you’re all set ! Next step : a little bit of soldering.