Skip navigation

SEGGER RunTime Library

The RunTime Library for embedded systems.

  • Designed and optimized for use with GCC
  • No viral licensing, no attribution clause
  • High performance, with time-critical routines written in assembly language
  • Significant code size reduction
  • Minimum RAM usage
  • No heap requirements

GCC has become a competitive compiler choice for embedded systems. Most toolchains using GCC also use either newlib, newlib-nano or glibc. Unfortunately, these libraries have significant disadvantages over professional runtime libraries for embedded systems.

  • Requires heap and memory management for functions such as printf()
  • Significant RAM usage, even for simple applications
  • Viral licensing and attribution clause with some libraries

This is where the SEGGER RunTime Library comes in.

What is the SEGGER RunTime Library?

The SEGGER RunTime Library is the replacement from SEGGER that converts any GCC-based toolchain into a professional development choice. The SEGGER RunTime Library is used in SEGGER's Embedded Studio IDE and has proven its value for years.

The SEGGER RunTime Library has been designed and written from the ground up for embedded devices to enable high optimization with low requirements.

  • Significant code size reduction (typically around 5 kB)
  • High performance, with time-critical routines written in assembly language
  • Highly optimized functions that, when used, don't cause the inclusion of many additional support functions (e.g. printf)
  • Formatted input and output functions are customizable from basic I/O to fully featured I/O, enabling reduction of final code footprint
  • Full support for localization, UTF-8, code pages, and locale codecs is linked only if used

In many cases, the ROM-savings of the SEGGER RunTime Library enable the use of a smaller microcontroller with less on-chip memory. This can result in significant cost savings, especially for devices built in large quantities for the mass market.

Being a simple replacement for newlib or newlib-nano, the SEGGER RunTime Library shrinks and accelerates GCC-based embedded applications. Whether the main concern with newlib is flash size, performance, or the attribution clause of the viral licensing, the SEGGER RunTime Library is the solution.

Optimized Floating-Point Support

The SEGGER Runtime library contains a complete, fully optimized and verified floating point library, which is required for devices without an FPU. The ARM and RISC-V variants of the library are completely written in assembly language, optimized either for small code size or increased execution speed. For other processor architectures the library has a portable C implementation.

The assembly language version has multiple implementations of basic operations using instructions and algorithms that make best use of the integer arithmetic instructions available in the architecture.  For instance, for single precision division:

  • Use a division instruction to iteratively develop a quotient, if available.
  • If no division instruction, but there is a multiplication instruction, use an initial reciprocal approximation refined by Newton-Raphson iterations with a final correction and multiplication.
  • If no division and no multiplication instruction, use a non-restoring division algorithm.

Similar optimizations apply to double-precision division.

Where appropriate, integer approximations for elementary functions are used that produce correct results within 0.5 units in the last place.

The floating-point library provides a consistent execution environment that ensures that infinities, not-a-number, and zero results with correct sign are accepted as inputs and generated as outputs. To be consistent with floating-point units executing in fast mode, the library elects to flush subnormals to a correctly-signed zero. Because subnormals do not typically occur in embedded systems, this optimization enables significant code size reduction.

Variants

The SEGGER RunTime Library can be licensed in source code to individual companies as well as to be included as libraries by providers of toolchains.

  • Source code makes it possible to step through library functions
  • Many functions can be tuned with different implementations for size-optimized code and speed-optimized code

The SEGGER RunTime Library is available in generic "C" code to run on any system. Additionally assembly optimized variants are available for:

  • ARM Cortex-A
  • ARM Cortex-M
  • RISC-V RV32M

Ports for other CPUs can be made available on request. If you are interested, please contact us for more information.

Memory Requirements

The SEGGER RunTime Library offers significant savings in flash memory. This is due to some functionality being written in assembly language, but primarily due to a structure that minimizes library internal dependencies, for example the file I/O not being linked in with printf() or scanf().

The SEGGER RunTime Library also uses less static RAM due to a structure designed from the ground up for embedded systems.

Benchmark Code:

int main(void) {
  printf("Hello World.\n");
  return 0;
}

SEGGER did some benchmarking on the SEGGER RunTime Library using NXP’s MCUXpresso as a representative IDE that might benefit from using the SEGGER RunTime Library. The benchmark consists of a simple "printf()" with output to a debug terminal. We compared the results for the SEGGER RunTime Library with the results for three other C libraries (Newlib, Newlib-nano, and Redlib). In each case, printf() was configured for the smallest possible size (size-optimized libraries, no floating point...). We then also tested with our own IDE, Embedded Studio, with the same code, using the SEGGER RunTimeLibrary, in one case using the GNU Linker, in another case using the SEGGER Linker. 

Test EnvironmentTest project: Simple "main" project with "printf()"
ROM UsageRAM Usage
100100MCUXpresso1, Newlib!CALCULATE_BAR_0!31888 bytes!CALCULATE_BAR_1!2864 bytes
31.125.4MCUXpresso, Redlib!CALCULATE_BAR_0!9940 bytes!CALCULATE_BAR_1!728 bytes
3014.5MCUXpresso, Newlib-nano!CALCULATE_BAR_0!9552 bytes!CALCULATE_BAR_1!416 bytes
13.76.4MCUXpresso, SEGGER RunTime Library!CALCULATE_BAR_0!4392 bytes!CALCULATE_BAR_1!184 bytes
7.80Embedded Studio2, SEGGER RunTime Library, GNU Linker!CALCULATE_BAR_0!2502 bytes!CALCULATE_BAR_1!0 bytes
5.90Embedded Studio, SEGGER RunTime Library, SEGGER Linker!CALCULATE_BAR_0!1868 bytes!CALCULATE_BAR_1!0 bytes
2.60.3Embedded Studio, SEGGER RunTime Library, SEGGER Linker, Host Formatting!CALCULATE_BAR_0!818 bytes!CALCULATE_BAR_1!8 bytes

1: MCUXpresso IDE v3.1.0-2200 and SDK 2.5.0 for the Freedom K66F board
2: Embedded Studio 4.16 with the Kinetis K60 CPU Support Package v1.02

Performance

The performance of a runtime library can have a huge impact on the speed of your application. You might actively use or try to avoid library functions, such as sprintf(), memcpy(), memcmp(), .... But especially when dealing with floating point or 64-bit operations, the compiler will make you call library functions, such as for division and multiplication, that you do not see. Here the choice of the right runtime library can make the difference.

The SEGGER RealTime Library uses improved, highly advanced low-level implementations for such operations, which can be tuned for speed or size. With the assembly optimized variants, performance can be even more optimized by using the target platform to its full potential.

Library Verification

To verify the correct functionality of the SEGGER RunTime Library, we created and used our verification test suite. It checks the entire functionality of all library functions, including the entire floating point library with all corner cases.

More than 450 different tests with millions of test cases are executed. Below an exert for just a single test for sys_float64_add(), adding 64-bit doubles:

 

IEEE-754 Floating-point Library Tests
Copyright (c) 2018-2019 SEGGER Microcontroller GmbH.

sys_float64_add:
  0 failures (47256 tests)

Totals:
  0 failures (47256 tests)

If you are interested in replaying our results, or if you want to verify the library you currently use, or if you are going to develop your own runtime library, you can get the SEGGER RunTime Library Verification Test Suite.

How to use the SEGGER Runtime Library

The SEGGER Runtime Library can be used with any GCC-based IDE/toolchain by replacing the runtime library delivered with that toolchain (usually newlib, newlib-nano, or some other variant) with the SEGGER Runtime Library.

Examples include:

  • AC6 System Workbench for STM32 (SW4STM32)
  • Atmel Studio 7
  • Atollic TrueStudio for STM32
  • NXP MCUXpresso
  • Renesas e2 studio (for Synergy or RZ targets)
  • SiLabs Simplicity Studio

In SEGGER Embedded Studio and Rowley CrossWorks, the SEGGER Runtime Library is already included as the default C library.

The SEGGER Runtime Library is provided in source code and contains everything needed.

We recommend keeping the SEGGER Runtime Library separate from your application files. It is good practice to keep all the associated program files (including the header files) together in the LIB subdirectory of your project’s root directory. This practice has the advantage of being very easy to update to newer versions of the SEGGER Runtime Library by simply replacing the LIB directory. Your application files can be stored anywhere.

Please make sure that the list of included directories in your project contains the LIB directory and that any other runtime libraries are removed from the project.

Include "__libc.h" in any application source files that make calls to the SEGGER Runtime Library.

You will also need to implement functions like __assert(), __putchar(), and __getchar() in your project according to your needs before the project will build correctly. 

The SEGGER Runtime Library is exposed to the user by a set of header files that provide an interface to the library. The actual implementation is done in a small number of C source and Assembly files that must be added to your project before building.

The configuration of the SEGGER Runtime Library is defined by the content of __libc_conf.h, which is included by all C and assembly language source files.

Please see the SEGGER Runtime Library User Guide for details.