Skip to main content

ARM None Eabi

How to build gcc compiler for cortex-m3. Usefull to get c++ 20 features on a microcontroler.

Build from source

mkdir -p $HOME/install
export PATH=$HOME/install:$PATH
https://ftp.fau.de/gnu/binutils/binutils-2.38.tar.xz
tar xvf binutils-2.38.tar.xz
cd binutils-2.38
mkdir build
cd build
../configure --prefix=$HOME/install \
--target=arm-none-eabi \
--with-cpu=cortex-m3 \
--with-no-thumb-interwork \
--with-mode=thumb
make
make install
wget ftp://sourceware.org/pub/newlib/newlib-4.1.0.tar.gz
tar xvf newlib-4.1.0.tar.gz
wget https://ftp.fau.de/gnu/gcc/gcc-12.1.0/gcc-12.1.0.tar.gz
tar xvf gcc-12.1.0.tar.gz
cd gcc-12.1.0
./contrib/download_prerequisites
mkdir build
cd build
../configure --prefix=$HOME/install \
--target=arm-none-eabi \
--with-cpu=cortex-m3 \
--disable-multilib \
--with-mode=thumb \
--with-no-thumb-interwork \
--enable-languages=c,c++ \
--with-newlib \
--with-headers=../../newlib/libc/include
make
make install
cd 
mkdir build
../configure --prefix=$HOME/install \
--target=arm-none-eabi \
--disable-multilib \
--disable-newlib-supplied-syscalls
make
make install

Usage

Makefile
ARM_NONE_EABI_ROOT=${HOME}/install

CC=$(ARM_NONE_EABI_ROOT)/arm-none-eabi-gcc
OBJ=$(ARM_NONE_EABI_ROOT)/arm-none-eabi-objcopy

all:
$(CC) speech.cpp main.cpp -mcpu=cortex-m3 -std=c++20 -mfloat-abi=soft -L$(ARM_NONE_EABI_ROOT)/lib -fmodules-ts --specs=nosys.specs -mthumb -Wall -Wextra -Werror -O -o main.elf
$(OBJ) -O binary main.elf main.bin
"cc_flags": 
"-Wimplicit-function-declaration -Wmissing-prototypes -Wstrict-prototypes -Os -ffunction-sections -fdata-sections -Wall -Wextra -Wredundant-decls -Wshadow -fno-common -mthumb -mcpu=cortex-m3",
"cxx_flags":
"-fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -Wextra -Wredundant-decls -Wshadow -fno-common -mthumb -mcpu=cortex-m3"