Comparison SEGGER Toolchain and gcc with CMake

From SEGGER Knowledge Base
Jump to navigation Jump to search

General

This article describes the use of the SEGGER toolchain (https://www.segger.com/products/development-tools/embedded-studio/technology/tools/segger-toolchain/) with CMake and showcases the code-size comparisons between the SEGGER toolchain and the ARM GCC toolchain.

We have based our internal testing on 3 different projects:

  1. A FreeRTOS demo that runs on an Atmel/Microchip SAME70_Xplained Ultra board (see below for how to reproduce this on your own)
  2. Our internal embench IOT benchmarking application
  3. Our internal emPower OS demo application

The builds for all 3 demos have been done using the SEGGER compiler as well as the ARM GCC compiler.
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.

A. Results for the FreeRTOS demo application
Build Configuration ARM GCC
Code + RO Data
SEGGER
Code + RO Data
abs. diff* % diff*
Without LTO Balanced w/o LTO 42 064 42 294 +230 +0.5%
Size-optimized w/o LTO 42 064 38 894 -3170 -7.5%
With LTO Balanced with LTO 38 388 38 642 +254 +0.7%
Size-optimized with LTO 38 388 34 192 -4196 -10.9%
B. Results for the embench IOT benchmarking application
Build Configuration ARM GCC
Code + RO Data
SEGGER
Code + RO Data
abs. diff* % diff*
Without LTO Balanced w/o LTO 102 060 102 137 +77 +0.1%
Size-optimized w/o LTO 102 060 94 687 -7373 -7.2%
With LTO Balanced with LTO 88 496 88 749 +253 +0.3%
Size-optimized with LTO 88 496 81 809 -6687 -7.6%
C. Results for the emPower OS demo application
Build Configuration ARM GCC
Code + RO Data
SEGGER
Code + RO Data
abs. diff* % diff*
Without LTO Balanced w/o LTO 658 622 629 956 -28666 -4.4%
Size-optimized w/o LTO 658 622 617 368 -41254 -6.3%
With LTO Balanced with LTO 643 170 618 051 -25119 -3.9%
Size-optimized with LTO 643 170 603 623 -39547 -6.1%

Notes:

  • (diff*): SEGGER build size minus ARM GCC build size
  • ("Balanced") : using "-Os" optimization switch
  • ("Size-optimized") : using "-Oz" optimization switch

Tool versions for comparison

Following versions have been used for the applications listed above:


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

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_20250909_1000.zip

Instructions for the demo

Setup

  1. Download the 1-stop ZIP package from Media:FreeRTOS_SGR_20250909_1000.zip
  2. Unzip the package. This will yield a working folder called "FreeRTOS_SGR".
  3. Under "FreeRTOS_SGR" there are following folders/files of interest:
    • Source : this contains the FreeRTOS-kernel.
    • Demo : this corresponds in function to the Demo folder found in the official FreeRTOS source code repository. In the demo package it contains only 2 subfolders:
      - Common : copy of the Common folder from the official FreeRTOS source code repository. Required for some basic demo functionality.
      - CORTEX_M7_SAME70_Xplained_AtmelStudio : the actuall demo application.
  4. Install required compiler toolchains and other prerequisites:
  5. Make sure the PATH environment variable contains the paths to the following:
    • cmake executable (at least version 3.24)
    • ninjaexecutable
    • arm-none-eabi-gcc executable 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!

  1. Check which configuration-presets are available:
    $ cmake --list-presets
    Available configure presets:
    
      "sgr_flat_noipo"    - sgr_flat_noipo
      "sgr_flat_ipo"      - sgr_flat_ipo
      "armgcc_flat_noipo" - armgcc_flat_noipo
      "armgcc_flat_ipo"   - armgcc_flat_ipo
    
  2. 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_noipo_dbg"
      "sgr_flat_noipo_rel"
      "sgr_flat_noipo_minsizerel"
      "sgr_flat_ipo_dbg"
      "sgr_flat_ipo_rel"
      "sgr_flat_ipo_minsizerel"
      "armgcc_flat_noipo_dbg"
      "armgcc_flat_noipo_rel"
      "armgcc_flat_noipo_minsizerel"
      "armgcc_flat_ipo_dbg"
      "armgcc_flat_ipo_rel"
      "armgcc_flat_ipo_minsizerel"
    
  3. First execute the configuration step with
    cmake --preset <config-preset-name>
    Example:
    $ cmake --preset sgr_flat_ipo
    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
    ================================================================================================================
    
  4. Then execute the build step with
    cmake --build <build-preset-name>
    Example:
    $ cmake --build --preset sgr_flat_ipo_minsizerel
    [22/47] Building C object CMakeFiles/CORTEX_M7_SAME70-FreeRTOS-Demo.dir/MinSizeRel/src/ASF/common/services/serial/usart_serial.o
    

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!

  1. 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.
  2. The selected configuration-preset is shown in the extensions page. You may also choose another configuration-preset by clicking on the pencil icon.
  3. The currently effective build-preset is shown in the extensions page. You may also choose another build-preset by clicking on the pencil icon.
  4. Click on the build-icon on the "Build" section in order to build the associated artefacts.