SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: Arm GCC Compiler
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 GCC Compiler

Graham Kruk
Last updated: September 12, 2023 1:59 am
Graham Kruk 7 Min Read
Share
SHARE

The ARM GCC compiler is a free and open source compiler toolchain used to build software applications for ARM-based processors and microcontrollers. The ARM GCC toolchain allows developers to compile C and C++ source code into optimized ARM machine code that can run on devices with ARM processors.

Contents
Overview of ARM GCCKey Features of ARM GCCInstalling ARM GCC ToolchainUsing the ARM GCC CompilerCompiling for Bare MetalUsing ARM GCC with IDEsPros and Cons of ARM GCC

Overview of ARM GCC

The ARM GCC compiler is part of the GNU Compiler Collection (GCC) which contains compilers for various programming languages like C, C++, Objective-C, Fortran etc. The ARM backend in GCC can generate code for all ARM processors from ARMv2 to the latest ARMv8-A. The ARM GCC toolchain contains the compiler driver gcc, assembler as, linker ld, debugger gdb and run-time libraries.

The key components of the ARM GCC toolchain are:

  • gcc – The C and C++ compiler
  • as – The assembler
  • ld – The linker
  • gdb – The debugger
  • Newlib – The C standard library implementation

ARM GCC supports various ARM architectures like ARMv6, ARMv7-A, ARMv7-M, ARMv7E-M, ARMv8-A etc. It can generate code for 32-bit ARM (AArch32) and 64-bit ARM (AArch64) instruction sets. The compiler provides many optimization flags like -O1, -O2, -O3 for improving the performance and size of compiled code.

Key Features of ARM GCC

Here are some of the key features of the ARM GCC compiler:

  • Supports C and C++ languages with standards like C99, C11, C++98, C++11 etc.
  • Generates optimized code for various ARM cores like Cortex-A, Cortex-R, Cortex-M series.
  • Supports both 32-bit ARM (AArch32) and 64-bit ARM (AArch64) instruction sets.
  • Open source software with active development community.
  • Works across Linux, Windows and Mac OS platforms.
  • Integrated assembler, linker and debugger.
  • Supports various compiling optimizations like function inlining, loop optimizations, common subexpression elimination etc.
  • Easy to integrate with IDEs like Eclipse, Visual Studio Code etc.
  • Newlib provides low-level standard C library functions.
  • Can link code with other compiled libraries.

Installing ARM GCC Toolchain

The ARM GCC toolchain needs to be installed on your development machine before you can start compiling code. Here are some ways to get ARM GCC:

  • ARM’s Mbed Tools – Simple all-in-one tools with GCC arm compiler included.
  • GNU Arm Embedded Toolchain – Baremetal ARM GCC toolchain from Arm’s GNU toolchain website.
  • Linux package manager – Install GCC arm packages using apt-get, yum etc.
  • Compiler packages – Get pre-built GCC binaries for Windows, Mac and Linux.

The easiest way is to use the GNU Arm Embedded Toolchain or packages like Arm Mbed tools. They provide ready-to-use binaries that can be simply downloaded and used. For advanced users, you can also build GCC ARM compiler from source code.

After installing ARM GCC, ensure the compiler binaries are available on the path environment variable. You may need to set the path in your .bashrc or .bash_profile files.

Using the ARM GCC Compiler

To compile a simple C program for ARM, you can invoke the gcc compiler like: gcc -mcpu=cortex-m3 -mthumb -o test.o -c test.c

This will compile test.c source file into test.o object file with cortex-m3 specific code generation using Thumb instruction set.

Some key options when using gcc are:

  • -mcpu – Specify target ARM cpu
  • -mthumb – Use Thumb 16-bit instruction set
  • -mfpu – Specify floating point unit
  • -mfloat-abi – Floating point ABI
  • -march – Specify ARM architecture version
  • -o – Output executable name
  • -c – Compile to object file (don’t link)
  • -O1, -O2, -O3 – Optimization levels

After compiling, you can link the object files into an executable using the gcc linker ld. For example: ld -o test test.o -lstdc++ -lc -lm -lrdimon

This will link test.o with C++ and C standard libraries along with other libraries like librdimon.a provided by the gcc toolchain.

Compiling for Bare Metal

For bare metal projects, ARM GCC needs to be configured properly for your microcontroller and target board. This requires:

  • Correct MCU architecture like Cortex-M3
  • Chip specific startup code
  • Linker script matching memory map
  • Disable OS primitives in standard libraries

For Cortex-M chips, you need a startup.c file with platform setup code. The linker script specifies memory regions for code and data sections. Options like “-nostdlib -nostartfiles” are used to disable parts of standard library.

The compiler needs to be provided the correct include directories to pick up the hired platform headers. Prebuilt GCC toolchains like GNU Arm Embedded provide ready templates and libraries for various ARM MCUs to simplify bare metal compilation.

Using ARM GCC with IDEs

ARM GCC can be easily used with popular IDEs for embedded development like:

  • Eclipse – With plugins like Eclipse Embedded CDT.
  • Visual Studio Code – With C/C++ extension and ARM plugin.
  • IAR Embedded Workbench – Using command line compiler.
  • Arm Keil uVision – By configuring uVision project settings.

The IDE needs to be configured to point to the ARM GCC toolchain location and provide necessary include paths and compiler options. The ARM GCC command can be directly invoked from the IDE or build tools like make can be configured with IDE. This enables debugging, code navigation and other advanced features in the IDE while being able to use the GCC compiler.

Pros and Cons of ARM GCC

Some pros and cons of using ARM GCC are:

Pros:

  • Free and open source software
  • Supports latest C/C++ standards
  • Optimized performance for ARM cores
  • Cross platform toolchain
  • Large open source codebase

Cons:

  • Limited microcontroller/board support
  • Minimal run-time libraries for bare metal
  • Limited advanced compiler optimizations
  • Not as mature as commercial compilers
  • Requires expertise to configure properly

In summary, ARM GCC provides a very capable and feature rich C/C++ compiler toolchain for ARM devices. While it may require some expertise to configure properly, it is flexible enough to be used from bare metal projects to Linux applications.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article ARM GNU Toolchain
Next Article GNU ARM Embedded Toolchain
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

Is there a cache in the ARM Cortex-M4?

The short answer is yes, the ARM Cortex-M4 processor does…

9 Min Read

Using the Cortex M0+ in USB Memory Sticks for Audio Decoding

The Cortex M0+ microcontroller from ARM is well-suited for audio…

6 Min Read

Can ARM Cortex Run Linux?

The short answer is yes, ARM Cortex processors are capable…

7 Min Read

Does the GCC compiler detects unaligned code accesses during compilation as well?

The short answer is yes, the GCC compiler is capable…

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

Sign in to your account