STM32 is a family of 32-bit microcontrollers made by STMicroelectronics, widely used in embedded systems development. Most tutorials online cover developing with Keil on Windows; this one covers setting up an STM32 development environment on a Linux server instead.
This article covers installing the STM32 development tools. The tools needed are:
- An editor — writing code always needs one. This article uses VS Code.
- STM32CubeMX, ST’s code-generation tool. Editing generated code is arguably easier than writing everything from scratch.
- A GCC cross-compiler — the code you write needs to be compiled before it can run on the microcontroller.
- A driver. More precisely, something that lets the computer recognize the microcontroller so the compiled code can be transferred to it. This is highly hardware-dependent; this article uses the CH343 driver.
- A debugging tool — writing code always involves debugging. OpenOCD, the Open On-Chip Debugger.
These tools don’t need to be installed in any particular order, so let’s go through them one by one. This article finishes with a hello-world example.
1. Installing the Editor
Use VS Code (Cursor also works). Download it from the official site.
2. Installing STM32CubeMX
STM32CubeIDE is the official integrated development environment from STMicroelectronics, bundling a code editor, compiler, debugger, and other tools. Before downloading, register an account on ST’s website.
Then:
- Visit the STM32CubeIDE official site and download the latest installer: STM32CubeIDE.
- Run the install script. For example, if the downloaded file is named
STM32CubeIDE_1.9.0_linux.tar.gz, extract it and run:
cd STM32CubeIDE_1.9.0_linux
./install.sh
3. Cross-Compilation Tools
2.1. Installing the GCC ARM Embedded Toolchain
STM32CubeIDE uses the GCC ARM Embedded Toolchain to compile by default. Visit the GCC ARM Embedded Toolchain official site: GCC ARM Embedded. Download the Linux build.
tar -xzf gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2
sudo mv gcc-arm-none-eabi-10.3-2021.07 /usr/local
echo 'export PATH=/usr/local/gcc-arm-none-eabi-10.3-2021.07/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
4. Installing the st-link Tool
Once the code is compiled, it needs to be downloaded onto the microcontroller over a serial port.
5. Installing OpenOCD
OpenOCD stands for Open On-Chip Debugger, an open-source debugger for communicating with STM32 microcontrollers. Install it through your package manager.
sudo apt install openocd # ubuntu
sudo dnf install openocd # redhat
6. Blinking an LED Chase
At this point, all the tools are installed. This section verifies the setup with a chasing-LED program — the STM32 equivalent of hello world.
6.1. How it works
A chasing LED display is just a string of LEDs lighting up in sequence. The microcontroller has a set of pins, some of which can be configured as outputs. What you can observe at a pin is, of course, whether it’s high or low. An LED only conducts in one direction, so it needs a high signal at its positive terminal and a low signal at its negative terminal. There are two approaches here.
- Connect the LED’s negative terminal to a low signal and its positive terminal to the microcontroller. When the microcontroller outputs a high signal, then
6.2. Generating the code
Do this with STM32CubeMX. At this point there are four
Power it on and run it.
7. Summary
Setting up an STM32 development environment on a Linux server lets you take full advantage of Linux’s stability and performance, giving STM32 development strong support. Following the steps above, you can easily set up a complete STM32 development environment on a Linux server and start your embedded-development journey.