Setting up the build environment:
Note:
$
denotes running as user.
#
denotes running as root. Depending on your setup, you might want use something like sudo
\
denotes a line break for formatting purposes. You should continue as if everything was on the same line.
Windows
InstallĀ MSYS2
64 bit: (x86_64) | http://repo.msys2.org/distrib/msys2-x86_64-latest.exe |
MSYS 32-bit appears to be broken at the moment
MSYS2 provides a GNU environment using pacman as package manager.
After the installation, one should install updates. Launch as “MSYS2 MinGW 64-bit” and run
$ pacman-key --init $ pacman-key --populate $ pacman -Suy
If it asks to import a key, confirm.
The first time it may prompt MSYS2 has to close to proceed. Once it closes, restart MSYS2, and run the update command again. Repeat until there are no longer updates available.
After installing MSYS2, follow the instructions for pacman based distros. Please note, unlike on regular Linux distros, pacman is run as a regular user, so no root or sudo required.
macOS
Install MacPorts, https://github.com/macports/macports-base/releases/
follow the instruction for ports based distros
Pacman based
ArchLinux, Manjaro,, Parabola, etc
# pacman -S base-devel git
MSYS 32 bit
$ pacman -S mingw-w64-i686-arm-none-eabi-toolchain mingw-w64-i686-openocd mingw-w64-i686-cmake
For MSYS 64 bit
$ pacman -S mingw-w64-x86_64-arm-none-eabi-toolchain mingw-w64-x86_64-openocd mingw-w64-x86_64-cmake
Please note we require the cmake package even though we are not using cmake, there is some dependency that will make the build fail otherwise.
See <a href=https://github.com/msys2/MINGW-packages/issues/8099>https://github.com/msys2/MINGW-packages/issues/8099</a> for details.
apt-based
Debian, Ubuntu, Mint, etc.
# apt-get install build-essential git binutils-arm-none-eabi \ gcc-arm-none-eabi gdb-multiarch \ libnewlib-arm-none-eabi libnewlib-nano-arm-none-eabi \ libstdc++-arm-none-eabi-newlib openocd
The build environment depends on bash being the default shell (/bin/sh to symlink to bash)
Ubuntu defaults to dash, which will cause the build to fail.
To configure Ubuntu to use bash in stead of dash, run
sudo dpkg-reconfigure dash
then answer “no”, to make bash the default shell.
rpm-based
CentOS, CentOS, SUSE, etc.
I have no rpm-based system at hand. The days I used Mandriva are long gone. I have not been able to locate a web-searchable repository from any of the rpm-based systems. For pacman or apt based distros, they are trivial to find, but for rpm, I get no results other then “how to list installed packages”
# yum install
It should include the “arm-none-eabi” variant of binutils, gcc, gdb and newlib. Furthermore openocd is required.
Ports based
FreeBSD, OpenBSD, NetBSD, macOS
I have no *BSD system at hand, nor do I own any Apple hardware, these are merely notes. If you use any of those systems, I would appreciate your input to complete these instructions.
The naming convention appears to be equal to the pacman based names, so the packages would be
arm-none-eabi-binutils arm-none-eabi-gcc arm-none-eabi-gdb arm-none-eabi-newlib openocd
Other
We need the cross compile toolchain for the triplet “arm-none-eabi”, search your repository. It should include the “arm-none-eabi” variant of binutils, gcc, gdb and newlib.
Furthermore, we need openocd, again search your repository.
If you require to build a toolchain from source, buildroot might be a useful tool.
Testing the enviorement
Create a directory where you like the files to be and enter it.
$ git clone https://github.com/a-v-s/ucdev $ git clone https://github.com/a-v-s/blinky $ cd blinky/bluepill_stm32f1 $ make
And see if this builds successfully. A succesfull build should end in something like
arm-none-eabi-size debug/blinky.elf text data bss dec hex filename 2300 20 32 2352 930 debug/blinky.elf arm-none-eabi-objcopy -O ihex debug/blinky.elf debug/blinky.hex arm-none-eabi-objcopy -O binary -S debug/blinky.elf debug/blinky.bin