If you want/need to develop STM32 MCUs in Linux... (not for running Linux on the MCU)
- Mint Linux 18.3 64bit (or equivalent distro)
- STM32F446RE board (or equivalent board)
- J-Link debugger
- Get Basic Tools
- Get ARM-GCC Compiler
- Get JLink Package
- Get OpenJDK
- Get STM32CubeMX
- Generate an Example
- Compile the Example
- Get VSCode and some useful extentions
- Set Tasks.json for make/clean
- Set Launch.json for debugging
- Tips for Windows Users
- Conclusion
$ sudo apt update
$ sudo apt install build-essential
$ sudo apt install git
$ sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
$ sudo apt update
$ sudo apt install gcc-arm-embedded
$ arm-none-eabi-gcc -v
Tips:
Download J-Link Software and Documentation pack for Linux, DEB Installer, 64-bit from https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack
Currently the version is 6.30a
$ sudo dpkg -i JLink_Linux_V630_x86_64.deb
To test it, connect your eval board and JLink to your PC and...
$ JLinkExe -device STM32F446RE -speed 1000 -if swd
// If JLinkExe starts without issue...
$ connect
// See the result and exit.
> exit
Tip: After installing, reboot may require.
STM32CubeMX requires 32bit JRE.
$ sudo apt install openjdk-11-jre:i386
STM32CubeMX is a util that can be used for biler-plating based on hardeware (>>>).
ST doesn't provide an open link for the util but we need to request.
After the request, ST will send an email to us.
After download, extract the zip file and run its installer as below.
$ sudo ./SetupSTM32CubeMX-4.27.0.linux
Tip
- After installing JRE, please use a new terminal for STM32CubeMX installation.
To have a basic code set, we have to run STM32CubeMX.
I designed a minimal setup with the util and the design includes:
- STM32F446RE
- 8MHz xtal
- A pin for LED
- A pair of UART
- Full speed USB and its stack.
- FreeRTOS
The Test_USB_CDC4.ioc file in this repo is the configuration for the project.
To use the configuration:
- Run STM32CubeMX (The binary can be found from /usr/local/STMicroelectronics/STM32Cube)
- Load the configuration
- Go to Project => Settings and check it is Makefile based.
- Go to Project => Generate Code then the code can be generated.
Now we can just compile the example generated by STM32CubeMX.
$ cd $PROJECT-ROOT (where the Makefile is)
$ make
If the compilation seems good, now install VSCode and some extensions from (>>>).
Must have extensions are:
- C/C++
- C++ Intellisense
- Cortex-Debug
- Vim (might be good for vim users but not for everyone)
Onde installation is done, open the folder where the project is.
To generate a Tasks.json,
- Press CTRL+Shift+P.
- Then type task.
- Lastly click Tasks: Configure Task.
Above action generates a folder(.vscode) and a file(Tasks.json) under .vscode.
By filling the json file, we can invoke make and make clean with shortcuts.
{
"version": "2.0.0",
"tasks": [
{
"label": "make",
"command": "make",
"args": [
"VERBOSE=1"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "clean",
"command": "make",
"args": [
"clean"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
With this configuration, we can use CTRL+SHIFT+B to open the task dialog and run make or clean.
The detail can be found from MS' document (>>>).
To generate a launch.json,
- Press CTRL+Shift+P.
- Then type launch.
- Lastly click Debug: Open launch.json.
Above action generates a file(launch.json) under .vscode.
By filling the json file, we can invoke the arm-none-eabi-gdb and JLink GDB server.
{
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"executable": "./build/THE_EXECUTABLE_NAME.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"device": "STM32F446RE",
"interface": "swd",
}
]
}
With this configuration, we can use F5 to start a debugging session.
Two things need to be adjusted based on your project:
- executable: THE_EXECUTABLE_NAME should ba updated.
- device: the depends on the target MCU.
The detail can be found from the extension's website (>>>).
First of all, install bash and make. I prefer MSYS2 (>>>).
Almost same things can be done to have the same environment except:
- System Environment and the Path should have ARM-GCC's location (C:\Program Files (x86)\GNU Tools ARM Embedded\VERSION_CAN_DIFF\bin)
- System Environment and the Path should have JLink's location (C:\Program Files (x86)\SEGGER\JLink_VERSION_CAN_DIFF)
- System Environment and the Path should have MSYS2's location (C:\msys64\usr\bin)
- System Environment and the MSYS2_PATH_TYPE should have its value as inherit
Also in the MSYS2 terminal, enter these to get make
$ pacman -Syuu
$ pacman -S tar git tree vim base-devel
So far we followed this short manual to set up STM32 MCU development environment in Linux.
In the manual,
- Downloaded the compiler, IDE, and SDK
- Learned how to make your own project by STM32CubeMX
- Compiled and debugged the project
As software changes everyday, the setup can be changed as well. However the basic step might be not very different.