arm-none-eabi-gcc is a version of the GNU Compiler Collection (GCC) cross-compiler toolchain targeted for ARM Cortex-M and Cortex-R family microcontrollers. It allows you to compile C and C++ code into machine code that can run on ARM Cortex-M and Cortex-R cores.
The “arm-none-eabi” prefix refers specifically to the ABI (Application Binary Interface) used by the toolchain which is configured for bare-metal ARM Cortex cores without an OS. The GCC toolchain itself provides the compiler, assembler, linker and other utilities needed to build complete applications.
Why Use arm-none-eabi-gcc?
Here are some of the key reasons to use the arm-none-eabi-gcc toolchain:
- It is free and open source – you can use it without licensing costs
- Works with all ARM Cortex-M and Cortex-R microcontrollers from different vendors
- Actively maintained and updated by ARM and the GNU community
- Supports the latest C and C++ language standards
- Optimized to generate efficient code for Cortex-M and Cortex-R cores
- Integrates smoothly into IDEs like Eclipse, Visual Studio Code etc
- Huge user community provides support and tutorials
In summary, arm-none-eabi-gcc provides a mature, robust and free platform for embedded development on ARM microcontrollers.
Key Components of the Toolchain
Here are some of the key components that make up the complete arm-none-eabi-gcc toolchain:
- Compiler (arm-none-eabi-gcc) – compiles C/C++ code into assembly language
- Assembler (arm-none-eabi-as) – converts assembly language into machine code
- Linker (arm-none-eabi-ld) – links compiled object files into executables
- Archiver (arm-none-eabi-ar) – creates and manages libraries from object files
- Debugger (arm-none-eabi-gdb) – debugs programs interactively or post-mortem
- Binary Utilities (arm-none-eabi-objcopy, objdump etc) – manipulate binary and object files
- Runtime Libraries – libraries providing standard C/C++ functions
- Header Files – provide interfaces to runtime libraries
The core compiler, assembler and linker make up the essential translation chain from C/C++ to machine code. The debugger and binary utilities help to analyze, manipulate and debug code. Runtime libraries provide important C/C++ functions and abstraction from the hardware.
Typical arm-none-eabi-gcc Workflow
A typical application development workflow using arm-none-eabi-gcc involves:
- Writing code in C or C++ using a text editor or IDE
- Compiling the C/C++ code into assembly language using arm-none-eabi-gcc
- Assembling the .s files into .o object files using arm-none-eabi-as
- Linking the .o files into an executable binary using arm-none-eabi-ld
- Analyzing the compiled binary with objdump or loading onto hardware
- Debugging code using arm-none-eabi-gdb either on hardware or simulator
- Making modifications and improvements in the C/C++ code
- Repeating the compile-assemble-link cycle iteratively
The compiler options can be tuned to trade-off factors like code size, speed and debugging info in the compiled binary. Runtime behavior can be analyzed and debugged to identify bugs.
Using arm-none-eabi-gcc on the Command Line
The arm-none-eabi-gcc toolchain can be used directly from the command line on Linux, macOS and Windows. Here is an example workflow:
- Write a C file such as main.c
- Compile into assembly: $ arm-none-eabi-gcc -c main.c -o main.o
- Assemble into object file: $ arm-none-eabi-as main.o -o main.o
- Link into executable: $ arm-none-eabi-ld main.o -o main.elf
- Analyze with objdump: $ arm-none-eabi-objdump -D main.elf
This shows the basic steps – the compiler, assembler and linker can be invoked separately on the command line. Many more options are available to control compilation, linking, output formats etc.
Integrating arm-none-eabi-gcc with IDEs
While the command line usage shows the core workflow, arm-none-eabi-gcc can be more easily integrated into IDEs like Eclipse, Visual Studio Code, Atollic TrueSTUDIO etc. These provide a GUI interface for:
- Configuring the toolchain and compiler options
- Editing, building and debugging projects
- Managing code, headers, libraries and other files
- Integrated debugging and analysis tools
- Flash programming and hardware debugging
The IDE manages invoking the underlying compiler, assembler, linker and debugger tools automatically based on the project configuration. This simplifies development and provides a more unified environment optimized for embedded projects.
Important Compiler Options
arm-none-eabi-gcc has many options to control the compilation process. Here are some important ones:
- -mcpu – Select specific ARM processor for code generation
- -march – Select ARM architecture
- -mfloat-abi – Defines floating point ABI conventions
- -mthumb – Generate Thumb-2 16-bit instructions
- -O1 – Basic optimization for code size and speed
- -Os – Optimize for smaller code size
- -Og – Optimize debugging experience
- -g – Generate debugging information
- -Wall – Enable common warnings
- -c – Only perform compilation step
- -I – Add include search path
There are many more options – refer to the gcc manual for details. Tuning these appropriately allows generating optimized code.
Debugging with arm-none-eabi-gdb
arm-none-eabi-gdb is the GDB ARM debugger integrated into the toolchain. It enables stepping through code, setting breakpoints, examining variables and machine state. Typical debugging workflow:
- Compile code with -g to generate debug symbols
- Load executable file into the debugger
- Set breakpoints and watches on variables
- Step through code line by line
- Inspect variables and registers when stopped
- Use GDB commands to analyze program flow and fix bugs
GDB can interface with JTAG/SWD hardware debugging interfaces for debugging directly on the microcontroller. It can also debug executables running on an instruction set simulator.
Profiling and Optimizing Code
To optimize code for the target ARM microcontroller, arm-none-eabi-gcc provides options like -Og, -Os and -Ofast. Higher levels of optimization like -O3 can actually increase code size and reduce performance on microcontrollers. The compiler can also integrate with profiling tools like gprof to analyze and optimize hot spots.
Optimization should balance factors like performance vs code size vs energy efficiency for the specific microcontroller. Profiling on real hardware and analysis with objdump helps to tune compiler options.
Linking Against External Libraries
Programs compiled with arm-none-eabi-gcc can link against external libraries to reuse code. Important libraries include:
- CMSIS libraries – Provide standardized interfaces for Cortex-M cores, peripherals and RTOS
- Newlib – Standard C library implementation
- Armsemihosting – Allow host/target communication for semihosting
- Device vendor HALs – Hardware abstraction layers for SoC peripherals
- Other 3rd party external libraries
The linker will search library paths specified with -L. Object files and libraries can be specified on the linker command line or in a linker script.
Bare Metal vs RTOS Development
The arm-none-eabi-gcc toolchain can be used for:
- Bare metal – No OS, application directly accesses hardware
- RTOS – With a real-time operating system such as FreeRTOS
For bare metal, newlib provides C standard library implementations tailored for embedded. For RTOS, interfaces are used to integrate with OS kernel and services.
Compilation flags indicate if an RTOS is used. Preprocessor macros interface between application code and RTOS definitions.
Licensing and Governance
The arm-none-eabi-gcc project is hosted on Github by ARM’s GNU toolchain team. Upstream components include:
- GCC – GNU Compiler Collection
- GDB – GNU Debugger
- Newlib – C standard library
- Binutils – Binary utilities
These are open source tools governed by the GPL, LGPL, or GPL compatible licenses. Companies like ARM maintain and validate the tools for Cortex-M and Cortex-R cores.
Users must accept the license agreements to download and use the toolchain. There are also commercial licensing options for professional support services.
Resources
Here are some useful resources for learning more about arm-none-eabi-gcc:
- ARM Developer – https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain
- GNU Arm Embedded Toolchain – https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm
- GCC Manual – https://gcc.gnu.org/onlinedocs/
- ARM Cortex Reference Manuals – https://developer.arm.com/architectures/cpu-architecture/a-profile/exploration-tools
- Forums – https://community.arm.com/developer/tools-software/tools/b/tools-software-ides-forum
There are also many tutorials, blogs, videos and books that cover using arm-none-eabi-gcc for embedded and IoT development with ARM Cortex-M and Cortex-R processors.