Thread Safe LibC Software Pack
June 15, 2026 · View on GitHub
Overview
This utility implements the mutex locks needed to make libc thread-safe. Depending on the libc implementation used in the project, a different set of hooks is provided, in accordance with its documentation. Refer to the relevant C source files for further details.
Description and Usage
Description
This component is structured around "libc glue" files:
ARM/armlib_lock_glue.cGCC/newlib_lock_glue.cIAR/dlib_lock_glue.cThese files implement the necessary APIs needed by their libc flavor to ensure thread-safety. They rely onstm32_lock.h(located at the root of the component) for a basic set of "common" APIs to reuse. This header also handles the configuration of the component (strategy selection). It may, if so configured, delegate work totemplate/stm32_lock_user.h, which contains stubbed implementations of the required primitives, to be filled in by the user.
Usage
At runtime, the user code must not interact with this component directly, but rather let libc manage it on it autonomously.
The strategy can be explicitly selected by defining exactly one of the following macros in the project:
STM32_THREAD_SAFE_USER_LOCKS=1user‑defined implementation of the locking mechanism (template provided)
STM32_THREAD_SAFE_BAREMETAL_ALLOW_LOCKS=1bare-metal; allow lock usage from interruptsSTM32_THREAD_SAFE_BAREMETAL_DENY_LOCKS=1bare-metal; deny lock usage from interrupts (thread is hung on use)STM32_THREAD_SAFE_FREERTOS_ALLOW_LOCKS=1FreeRTOS; allow lock usage from interruptsSTM32_THREAD_SAFE_FREERTOS_DENY_LOCKS=1FreeRTOS; deny lock usage from interrupts (thread is hung on use)