How To Use

Use Thread Safe LibC as follows:

1. Selecting Files

Include the utility in your project and ensure that the appropriate glue file is built based on the compiler:

  • Headers: stm32_lock.h (mandatory), templates/stm32_lock_user.h (optional, if STM32_THREAD_SAFE_USER_LOCKS is defined).

  • Sources (one toolchain glue selected by the compiler): - GCC/newlib: GCC/newlib_lock_glue.c - ARMCC/ARMlibc: ARM/armlib_lock_glue.c - IAR/DLib: IAR/dlib_lock_glue.c

2. Configuration

Selecting a Strategy

Define exactly one of the following macros in the build configuration:

  • STM32_THREAD_SAFE_USER_LOCKS=1

  • STM32_THREAD_SAFE_BAREMETAL_ALLOW_LOCKS=1

  • STM32_THREAD_SAFE_BAREMETAL_DENY_LOCKS=1

  • STM32_THREAD_SAFE_FREERTOS_ALLOW_LOCKS=1

  • STM32_THREAD_SAFE_FREERTOS_DENY_LOCKS=1

If none of these macros is defined, the default strategy is STM32_THREAD_SAFE_BAREMETAL_ALLOW_LOCKS (interrupts are disabled during critical sections).

FreeRTOS Note

For FreeRTOS strategies, enable configUSE_NEWLIB_REENTRANT=1 in FreeRTOSConfig.h so that newlib becomes thread-safe.

3. Thread Safe LibC Usage

No explicit API calls are needed. Once the module is compiled and a strategy is selected, the C library automatically uses the glue functions and locks (for example around malloc, environment/timezone updates, file locks, and C++ static initialization).