SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: arm-none-eabi-gcc
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

arm-none-eabi-gcc

Graham Kruk
Last updated: September 12, 2023 1:48 am
Graham Kruk 9 Min Read
Share
SHARE

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.

Contents
Why Use arm-none-eabi-gcc?Key Components of the ToolchainTypical arm-none-eabi-gcc WorkflowUsing arm-none-eabi-gcc on the Command LineIntegrating arm-none-eabi-gcc with IDEsImportant Compiler OptionsDebugging with arm-none-eabi-gdbProfiling and Optimizing CodeLinking Against External LibrariesBare Metal vs RTOS DevelopmentLicensing and GovernanceResources

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:

  1. Writing code in C or C++ using a text editor or IDE
  2. Compiling the C/C++ code into assembly language using arm-none-eabi-gcc
  3. Assembling the .s files into .o object files using arm-none-eabi-as
  4. Linking the .o files into an executable binary using arm-none-eabi-ld
  5. Analyzing the compiled binary with objdump or loading onto hardware
  6. Debugging code using arm-none-eabi-gdb either on hardware or simulator
  7. Making modifications and improvements in the C/C++ code
  8. 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:

  1. Write a C file such as main.c
  2. Compile into assembly: $ arm-none-eabi-gcc -c main.c -o main.o
  3. Assemble into object file: $ arm-none-eabi-as main.o -o main.o
  4. Link into executable: $ arm-none-eabi-ld main.o -o main.elf
  5. 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:

  1. Compile code with -g to generate debug symbols
  2. Load executable file into the debugger
  3. Set breakpoints and watches on variables
  4. Step through code line by line
  5. Inspect variables and registers when stopped
  6. 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.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Understanding FreeRTOS Context Switch Time
Next Article gcc-arm cross compiler
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

Options for Floating Point Math on Cortex M Without FPUs

For Cortex M chips without a dedicated floating point unit…

8 Min Read

Setting CPU Targets for ARM Compilation with gcc

When compiling code for ARM processors using the gcc toolchain,…

9 Min Read

What happens after reset and before the Cortex-M processor starts executing the program?

When a Cortex-M processor first powers on or resets, it…

6 Min Read

How to Enable the FPU in Cortex-M4 Microcontrollers?

The Cortex-M4 processor includes a single precision floating point unit…

7 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account