Platform Support

CMRX provides simplified integration path for certain well-supported platforms. This simplified way trades flexibility for ease of integration. Instead of using FindCMSIS module to locate your HAL and customizing its settings, platform module will do this automatically. Instead of using FindCMSIS directly, the much simplified procedure is used:

set(CMRX_DEVICE <part_name>)
include(cmrx/cmake/CMRX.cmake)

The variable CMSIS_DEVICE contains microcontroller name as recognized by your HAL, including manufacturer identifiaction, e.g. stm32h753xx or rp2040. If it contains prefix of any supported platform, then platform support is activated. The content of the variable is case-insensitive.

The slight downside is that you can use platform support only in explicitly supported configuration. Following is the list of currently supported platforms and their specifics:

STM32 - CubeMX

Many STM32 microcontrollers are supported when using CubeMX-generated projects. These projects must use CMake as the generated buildsystem. No other buildsystems are supported as of now. To use STM32 platform support, integrate CMRX into top-level CMakeLists using following lines:

set(CMRX_DEVICE stm32<mcu_name>)
include(cmrx/cmake/CMRX.cmake)

Where <mcu_name> is the name CubeMX HAL recognizes as device name. This device name often covers a group of devices, like stm32h753xx. Check CubeMX HAL sources to find out actual device name. If you plan using linker script CubeMX generated for you, your work is done here. If you want to customize and/or move the linker script from its default location as generated by CubeMX, then you have to set variable CMRX_LINKER_SCRIPT before including CMRX.cmake. It must point to existing linker script file and doing so will override autodetected linker script location. This may also be needed in case you have multiple similarly-named linker scripts, such as STM32H753VIH_FLASH.ld and stm32h753vid_flash.ld where it is ambiguous which one to use. Platform module will issue an error in such case and you have to either delete unused linker scripts or specify the correct one manually.

When writing drivers, you may need to access STM32 peripheral register declarations. CubeMX creates stm32cubemx target which provides include paths for easy inclusion. You cannot link this target to your drivers as it injects HAL source files into target and that causes multiple symbol definition. Use stm32cubemx_headers target instead. It provides access to CubeMX HAL headers without injecting additional source files.

CubeMX HAL maintains correct information on CPU frequency if HAL-based clock manipulation routines are used, thus STM32 platform will enable CMRX_SYSTICK_USE_SYSTEMCORECLOCK so both CMRX and timing provider will use HAL-provided information on current CPU frequency.

Adding support for new platform

Adding support for new platform is quite straightforward. In the simplest case, all you need is to create CMake file having lowercase name of your platform (e.g. stm32.cmake or rp2.cmake) and place it into cmake/platform subdirectory. This code will automatically be activated for any CMRX_DEVICE which contains prefix equal to your platform name. If there are two matching platforms, shorter name will have precedence over longer. So if there were both rp2.cmake and rp20.cmake then rp2.cmake will always be used for all part names starting with “rp2” string. Once platform support file is found, no further files are considered.

This file should contain specific instructions to integrate with HAL of your microcontroller. Usually these specific steps include generation of DEVICE variable, setting up CMSIS_ROOT and CMRX_LINKER_SCRIPT variables, calling FindCMSIS (in case of ARM-based devices) and setting up CMRX_ARCH and CMRX_HAL variables. It is always a good idea to let users to customize linker script, so platform support code should always accept any value of CMRX_LINKER_SCRIPT variable set before platform code is executed. It may nevertheless check for its validity.

In some cases, platforms may need either some special CMake support or code to be includede into kernel build. This can be triggered by setting variable CMRX_PLATFORM not just CMRX_ARCH and CMRX_HAL. The value this variable is set to should ideally be prefixed with platform support name, but may have non-empty suffix. Thus, if one platform covers several different behaviors, it is possible to select one of multiple platform support variants and set CMRX_PLATFORM to its name. This is purely optional and platform support code doesn’t have to set this variable if no specific code handling is needed. Setting this variable will enable following optional behavior:

If your platform needs to run any CMake steps during CMRX module loading, your can create file cmake/${CMRX_ARCH}/platform/${CMRX_PLATFORM}/CMRX.cmake and it will be loaded automatically after HAL file is included. If this file doesn’t exist, CMake will proceed without error.

If your platform requires any platform-specific code to be included into kernel build, then create folder src/arch/${CMRX_ARCH}/${CMRX_PLATFORM} in CMRX source tree. If this folder exsits, then the build system will expect that it contains platform-specific CMakeLists.txt and optionally also some source code. If directory doesn’t exists, it is skipped without error, but if directory exists, it must contain CMakeLists.txt otherwise CMake will stop with error. CMakeLists file can inject additional sources into CMRX kernel build to make them part of the kernel. Use this feature with caution as any code injected here will run with full kernel privileges and bugs introduced in it may compromise security of whole kernel and thus, device.

← Supported Hardware