
"We are software engineers and as such we code, yeah we like to write code"
In a few words the vast majority of our trainings are text base, because are mainly focus on increasing your abilities as a embedded software engineer, get use to the terminal and command line program execution. Don't worry you soon will find this is a much better and faster way to do things related to code.
You have two option to work with Linux and Windows but in both you will need a terminal. Regarding linux and its many flavor, Arch version are the one we will use, mostly because its powerful package manager and easy way to install all the required software. Choose any Arch distro you want but here are some recommendations:
The main tools
The best compiler, a nice code editor, a fancy terminal and a powerful shell plus some other nice to have tools will make us unstoppable.
Linux Users
After a fresh linux installation and before anything else, install the linux base devel package
pacman is the program we use in arch linux to install all our software, or most of them
$ sudo pacman -Syu base-develThe later one shall install most of the build tools we need, including the compiler and make, but not gdb
$ sudo pacman -S gdbthe most popular source code manager is also a must
$ sudo pacman -S gittree, to display beautiful directory list in cli
$ sudo pacman -S treePrior to continue it is needed to install an arch linux utility that will allow us to install extra packages, it is called paru
$ git clone https://aur.archlinux.org/paru.git
$ cd paru
$ makepkg -si
$ cd ..
$ rm -r paruAnd last but not least the code editor, we gonna pick VS Code because it is really fancy and has a tons of plugins you can use, there is a open source version on the arch offcial repo, but we gonna choose the microsoft license version because it is easy to install the plugins and themes. Hope you don’t mind to be spy by Microsoft.
$ paru -S visual-studio-code-binPython already comes with any linux distribution but not its packager manager, called pip ( well sometimes it does )
$ sudo pacman -S python-pipOk, we need another compiler if want our C program to run in our microcontroller, we choose the official GNU ARM compiler, becuase among other things is free as in free beer. Open a terminal and type the following
$ sudo pacman -Syu arm-none-eabi-gcc arm-none-eabi-gdb arm-none-eabi-newlibOnce we have our program compiled we need somehow transfer it to the on-chip memory, and for that, it is necessary OpenOCD
$ sudo pacman -Syu openocdSince openocd needs to access our USB port we need to run with sudo, BUT it is not recommended at all to run any application with sudo. So we gonna fix this inconvenient setting of some user permissions. Verify if plugdev group exists
$ grep plugdev /etc/groupIf the above doesn’t return anything, then it doesn’t exist and you need to create it and also add your user. Replace with your username
$ sudo groupadd plugdev
$ sudo usermod -a -G plugdev <username>We copy a certain file with the access rules for openocd and activate them. NOTE: The file name may be different; to find out, just run ls /usr/share/openocd/contrib and check which file appears.
$ sudo cp /usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules
$ sudo udevadm triggerWindows users
Windows does not have a powerful terminal workflow like linux, but there is a good and nice project with the goal to emulate the easy and fancy way Linux has to install programs, and that is:

Open powershell in Admin mode and type
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))Just in case and from time to time you should upgrade choco
$ choco upgrade chocolateyOk install mingw to run gcc and gdb
$ choco install mingwtest installation
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/12.2.0/lto-wrapper.exe
...do not forget make
$ choco install makeOf course you can install Git
$ choco install gitand tree, to display beautiful directory list in cli
$ choco install treeVSCode
$ choco install vscodeALWAYS run PowerShell with admin permission to install anything with choco
By the way, the default VSCode terminal shell is PowerShell, but since we already installed git, ( that comes with its own shell base in BASH ), lets make a switch like is shown in this nice video from Neutro Dev.
Now you have a linux like terminal, where you can use bash scripting with all its powers making almost transparent "The way we work " without worry about the operative system in use.
Soon or later you gonna need python and its good friend pip ( that already comes with python, or should )
$ choco install pythonOk, we need another compiler if want our C program to run in our microcontroller, we choose the official GNU ARM compiler, open a terminal and type the following
$ choco install gcc-arm-embeddedOnce we have our program compiled we need somehow transfer it to the on-chip memory, and for that, it is necessary OpenOCD
$ choco install openocdNOTE: In Windows everything needs a driver!!!!, and the St-Link is no exception, download from here
Test your new compiler
$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=C:\ProgramData\chocolatey\lib\gcc-arm-embedded\tools\gcc-arm-none-eabi-10.3-2021.10\bin\arm-none-eabi-gcc.exe
COLLECT_LTO_WRAPPER=c:/programdata/chocolatey/lib/gcc-arm-embedded/tools/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/lto-wrapper.exe
Target: arm-none-eabi
Configured with: /mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/src/gcc/configure --build=x86_64-linux-gnu --host=i686-w64-mingw32 --target=arm-none-eabi --prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw --libexecdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/lib --infodir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/share/doc/gcc-arm-none-eabi/info --mandir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/share/doc/gcc-arm-none-eabi/man --htmldir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/share/doc/gcc-arm-none-eabi/html --pdfdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-mingw-wildcard --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-headers=yes --with-newlib --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-mingw/arm-none-eabi --with-libiconv-prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-gmp=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-mpfr=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-mpc=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-isl=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-libelf=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-mingw/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Arm Embedded Toolchain 10.3-2021.10' --with-multilib-list=rmprofile,aprofile
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.3.1 20210824 (release) (GNU Arm Embedded Toolchain 10.3-2021.10)Terminal and CLI worflow
I can write tons of lines on how to use the Terminal but someone else already did it really well and also wrote a book, https://linuxcommand.org/tlcl.php. You should and must read it, just remember if you are in Windows things will be a little more limited. the most important is to learn about navigation with the commands pwd, cd, ls, mkdir, rm,
Building OpenOCD
I love OpenOCD and really appreciate what these guys are doing, but it often takes them a long time to release a new version (around three years). Sometimes, new microcontrollers come to market without support. The project is so popular that even some companies have developed their own versions with updates to support their most recent microcontroller lines. ST is one of them. However, guess what? You need to build the binaries yourself
/usr/local/share/openocd/scripts/board or /usr/share/openocd/scripts/board/. want to know moreIf your board is not supported by the official OpenOCD version then you need to use the ST version. in case you previously installed OpenOCD, proceed to uninstall
$ sudo pacman -R openocdInstall the following missing dependency
$ sudo pacman -S hidapiClone the OpenOCD source files updated by ST
$ git clone --recursive https://github.com/STMicroelectronics/OpenOCD.git
$ cd OpenOCDProceed to build openocd using the instructions down below
./bootstrap
export CFLAGS="-Wno-error=calloc-transposed-args"
./configure
make
sudo make install
cd ..
rm -rf OpenOCDline export CFLAGS="-Wno-error=calloc-transposed-args" is just workaround for the problem described in here Calloc warning/error · Issue #101 · raspberrypi/openocdAnd before you tell me something about windows, I only know how to do this on Linux, but don’t worry you can a take a look to our Dockerhub where there is a OpenOCD image ready to use and we also have a stm32 version already build
