Skip to content

fix: include CMSIS device header unconditionally in freertos_os2.h#184

Open
KnoerleMaTLS wants to merge 1 commit intoARM-software:mainfrom
KnoerleMaTLS:main
Open

fix: include CMSIS device header unconditionally in freertos_os2.h#184
KnoerleMaTLS wants to merge 1 commit intoARM-software:mainfrom
KnoerleMaTLS:main

Conversation

@KnoerleMaTLS
Copy link
Copy Markdown

@KnoerleMaTLS KnoerleMaTLS commented Apr 20, 2026

Context

We are integrating CMSIS-FreeRTOS into a CMake-based project using the CMSIS RTOS2 adapter layer. When building with GCC via CMake (without Keil MDK), SysTick_Handler was silently missing from the final binary, causing the RTOS to never tick. The root cause turned out to be the device header include being gated behind a Keil-specific macro.

Problem

In CMSIS/RTOS2/FreeRTOS/Include/freertos_os2.h, #include CMSIS_device_header is guarded by #if defined(_RTE_). The _RTE_ macro is Keil MDK-specific and is not defined when building with GCC, CMake, or other non-Keil toolchains. As a result, the CMSIS device header is never included in cmsis_os2.c, the SysTick macro is never defined, and SysTick_Handler inside the #if defined(SysTick) block is silently compiled out.

Fix

Move #include CMSIS_device_header outside the #if defined(_RTE_) guard so it is included unconditionally. Add an #elif !defined(CMSIS_device_header) error guard for non-RTE builds, matching the pattern used in os_systick.c from ARM-software/CMSIS_6.

Validation

Build cmsis_os2.c with a GCC-based toolchain using -DCMSIS_device_header=\"<device>.h\" (without -D_RTE_) and verify:

  1. Compilation succeeds.
  2. SysTick_Handler is present in the object file.
  3. Existing Keil MDK builds (with _RTE_) are unaffected.

Note

handlers.c and Config/FreeRTOSConfig.h have a similar unconditional #include "RTE_Components.h" but are RTE-only components (Cortex-A IRQ handler / template config) and are not addressed here.

References

Move `#include CMSIS_device_header` outside the `#if defined(_RTE_)`
guard so it is included for all toolchains, not only Keil MDK.

Previously the device header was only included when _RTE_ was defined,
which meant the SysTick macro was never available on GCC/CMake builds
and SysTick_Handler in cmsis_os2.c was silently compiled out.

Add an `#elif !defined(CMSIS_device_header)` error guard for non-RTE
builds, matching the pattern used in os_systick.c from the CMSIS_6
repository (ARM-software/CMSIS_6).

Note: handlers.c and Config/FreeRTOSConfig.h have a similar
unconditional `#include "RTE_Components.h"` but are RTE-only
components (Cortex-A IRQ handler / template config) and are not
addressed in this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SysTick_Handler silently compiled out on non-Keil toolchains (GCC/CMake)

1 participant