Comparison SEGGER Toolchain and gcc with CMake
General
This article describes the use of the SEGGER Toolchain with CMake and showcases the code-size comparisons between the SEGGER Toolchain (compiler and linker) and the ARM GCC toolchain (compiler and linker).
We have based our internal testing on three different projects:
- A FreeRTOS demo that runs on an Atmel/Microchip SAME70_Xplained Ultra board (see below for how to reproduce this on your own)
- Our internal embench IOT benchmarking application
- Our internal emPower OS demo application
The source code for the comparisons has been kept mostly identical between the ARM GCC and SEGGER Toolchain builds, with the exception of some toolchain-specific code (e.g. startup/initialization code or compiler specific attributes syntax).
All compared builds have been configured to "-Oz" optimization level (which optimizes for size, corresponding to the "*_minsizerel" build presets mentioned below). Furthermore the effect of using Link-Time-Optimization (LTP/IPO) is also shown.
Further optimization of the firmware size is possible beyond what is demonstrated here by applying techniques as described under the article: How to optimize a Firmware for minimal Size
A general guide on how to utilize the SEGGER CMake toolchain is available as a README.md file at https://github.com/SEGGERMicro/segger-toolchain-cmake
Build size comparison tables
The following tables summarize the results we have obtained.
| Code | RO-Data | Sum (Code + RO-Data) | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| ARM GCC | SEGGER | abs. Diff* | % diff* | ARM GCC | SEGGER | abs. Diff* | % diff* | ARM GCC | SEGGER | abs. Diff* | |
| without LTO | 41108 | 37848 | -3260 | -7.9% | 956 | 1046 | +90 | +9.4% | 42064 | 38894 | -3170 |
| with LTO | 37440 | 34576 | -2864 | -7.6% | 948 | 1000 | +52 | +5.5% | 38388 | 35576 | -2812 |
| Code | RO-Data | Sum (Code + RO-Data) | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| ARM GCC | SEGGER | abs. Diff* | % diff* | ARM GCC | SEGGER | abs. Diff* | % diff* | ARM GCC | SEGGER | abs. Diff* | |
| without LTO | 83076 | 75766 | -7310 | -8.8% | 18984 | 18921 | -63 | -0.3% | 102060 | 94687 | -7373 |
| with LTO | 69724 | 63018 | -6706 | -9.6% | 18772 | 18791 | +19 | +0.1% | 88496 | 81809 | -6687 |
| Code | RO-Data | Sum (Code + RO-Data) | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| ARM GCC | SEGGER | abs. Diff* | % diff* | ARM GCC | SEGGER | abs. Diff* | % diff* | ARM GCC | SEGGER | abs. Diff* | |
| without LTO | 158158 | 119224 | -38934 | -24.6% | 492640 | 490511 | -2129 | -0.4% | 650798 | 609735 | -41063 |
| with LTO | 143954 | 106642 | -37312 | -25.9% | 492288 | 490149 | -2139 | -0.4% | 636242 | 596791 | -39451 |
Notes:
- (diff*): SEGGER build size minus ARM GCC build size
Tool versions for comparison
Following versions have been used for the applications listed above:
- SEGGER toolchain: version V8.25 Build 2025090300.59980 - part of SEGGER Embedded Studio, obtainable at https://www.segger.com/downloads/embedded-studio
- - Compiler version = 19.1.2
- - Linker version = 4.44.2
- ARM GCC toolchain: version 14.2.Rel1 - obtainable at https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
- - Compiler version = 14.2.1
- - Linker version = 2.43.1.20241119
- SEGGER CMake toolchain: version 1.2.0 - obtainable at https://github.com/SEGGERMicro/segger-toolchain-cmake
- ARM GCC CMake toolchain: version 02dbd14fc6e32aa568eaf8b200cef48b2c6d7b7d (main) - obtainable at https://github.com/vpetrigo/arm-cmake-toolchains.git
Reproducing the results for the FreeRTOS demo
Description of the FreeRTOS demo project
The demo project has been derived from the official FreeRTOS Demo from version 202411.00 and runs on the Atmel/Microchip SAME70_Xplained Ultra board
The original demo description is here http://www.freertos.org/Atmel_SAMV7_Cortex-M7_RTOS_Demo.html.
In comparison with the original demo code, our demo version comes with following changes:
- some adaptations for the SEGGER compiler (e.g. for defining __inline__ macros, startup code etc.)
- addition of CMakeLists.txt in order to build with both ARM GCC as well as SEGGER on the same code base (with exception of tool-specific startup code)
- redefinition of the GPIO-port for the blinking LED such that now LED3 is used.
- mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0: this ensures that the more comprehensive test-set is run as described under http://www.freertos.org/Atmel_SAMV7_Cortex-M7_RTOS_Demo.html
- adaptation in the GNU linker script in order to move read-only data from the .text output section into a dedicated output section. Required for better comparison of resulting code and data sizes.
1-Stop ZIP package
A complete 1-stop ZIP package for the demo is available that includes the FreeRTOS kernel in addition to the demo project: Media:FreeRTOS_SGR_20251009_1519.zip
Instructions for the demo
Setup
- Download the 1-stop ZIP package from Media:FreeRTOS_SGR_20251009_1519.zip
- Unzip the package. This will yield a working folder called "FreeRTOS_SGR".
- Under "FreeRTOS_SGR" there are following folders/files of interest:
Source: this contains the FreeRTOS-kernel.Demo: this corresponds in function to theDemofolder found in the official FreeRTOS source code repository. In the demo package it contains only 2 subfolders:- -
Common: copy of theCommonfolder from the official FreeRTOS source code repository. Required for some basic demo functionality. - -
CORTEX_M7_SAME70_Xplained_AtmelStudio: the actuall demo application.
- -
- Install required compiler toolchains and other prerequisites:
- Install Ninja: https://ninja-build.org/
- Install CMake: version 3.24 or later: https://cmake.org/download
- Install SEGGER Embedded Studio V8.25: https://www.segger.com/downloads/embedded-studio
- For ARM GCC builds, install ARM GCC version 14.2.Rel1: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
- Make sure the
PATHenvironment variable contains the paths to the following:cmakeexecutable (at least version 3.24)ninjaexecutablearm-none-eabi-gccexecutable etc. (from your ARM GCC distribution)
Command-line usage
NOTE: issue these commands from within the FreeRTOS_SGR/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio subfolder!
- Check which configuration-presets are available:
$ cmake --list-presets Available configure presets: "sgr_flat_nolto" - sgr_flat_nolto "sgr_flat_lto" - sgr_flat_lto "armgcc_flat_nolto" - armgcc_flat_nolto "armgcc_flat_lto" - armgcc_flat_lto
- Check which build-presets are available (their name-endings indicate which kind of build-configurations they perform):
$ cmake --build --list-presets Available build presets: "sgr_flat_nolto_dbg" "sgr_flat_nolto_minsizerel" "sgr_flat_lto_dbg" "sgr_flat_lto_minsizerel" "armgcc_flat_nolto_dbg" "armgcc_flat_nolto_minsizerel" "armgcc_flat_lto_dbg" "armgcc_flat_lto_minsizerel"
- First execute the configuration step with
cmake --preset <config-preset-name>
- Example:
$ cmake --preset sgr_flat_lto Preset CMake variables: CMAKE_CONFIGURATION_TYPES="MinSizeRel;Debug;Release" CMAKE_MAKE_PROGRAM="ninja" CMAKE_SYSTEM_PROCESSOR="arm-cortex-m7" CMAKE_TOOLCHAIN_FILE:FILEPATH="C:/WORK/DEV/PRJ/CMAKE/WRKSPC/FreeRTOS/FreeRTOS_SGR/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/cmake_toolchains/segger-toolchain-cmake/segger-toolchain.cmake" PROJECT_ENABLE_IPO="1" PROJECT_FLAT_SOURCE_LIST="1" -- CMAKE_MODULE_PATH extended by C:/WORK/DEV/PRJ/CMAKE/WRKSPC/FreeRTOS/FreeRTOS_SGR/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/cmake_modules -- The C compiler identification is SEGGERClang 19.1.2 -- Found binutils: arm-none-eabi -- The CXX compiler identification is SEGGERClang 19.1.2 -- Found binutils: arm-none-eabi -- The ASM compiler identification is SEGGERClang -- Found binutils: arm-none-eabi -- Found assembler: C:/Program Files/SEGGER/SEGGER Embedded Studio 8.25/bin/cc.exe -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files/SEGGER/SEGGER Embedded Studio 8.25/bin/cc.exe - skipped -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files/SEGGER/SEGGER Embedded Studio 8.25/bin/cc++.exe - skipped -- ================================================================================================================ SEGGER_CMAKE_TOOLCHAIN_VERSION = 1.2.0 SEGGER_TOOLCHAIN_PKG_ROOT = C:/Program Files/SEGGER/SEGGER Embedded Studio 8.25 SEGGER_CMAKE_HAS_BUILTIN_COMPILER_ID = TRUE CMAKE_SYSTEM_NAME = Generic CMAKE_SYSTEM_PROCESSOR = arm-cortex-m7 Available build configuration types = MinSizeRel, Debug, Release ================================================================================================================
- Example:
- Then execute the build step with
cmake --build <build-preset-name>
- Example:
$ cmake --build --preset sgr_flat_lto_minsizerel [22/47] Building C object CMakeFiles/CORTEX_M7_SAME70-FreeRTOS-Demo.dir/MinSizeRel/src/ASF/common/services/serial/usart_serial.o
- Example:
Visual Studio Code (VS Code) usage
NOTE: open the FreeRTOS_SGR/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio subfolder as the workspace folder withing VS Code!
- When opening the project folder in VS Code for the first time, the CMake extension pops up a drop-down list of configuration-presets to choose from.
- The selected configuration-preset is shown in the extensions page. You may also choose another configuration-preset by clicking on the pencil icon.
- The currently effective build-preset is shown in the extensions page. You may also choose another build-preset by clicking on the pencil icon.
- Click on the build-icon on the "Build" section in order to build the associated artefacts.