The CLib Support Library provides hooks to make C library functions such as malloc and free thread-safe for FreeRTOS and ThreadX RTOSes. It supports GCC Newlib, ARM C library, IAR C library, and LLVM ARM picolibc toolchains, and also implements the standard time() function backed by the microcontroller Real-Time Clock (RTC).
Most application developers will not interact with this library directly; it is automatically included as a dependency of ModusToolbox™ BSPs. For full API documentation, see the Reference Guide.
For GCC, IAR, and LLVM ARM toolchains, the startup code must call cy_toolchain_init() after static data initialization and before static constructors. This is done automatically for PSoC™ devices.
When the HAL is present and an RTC-capable device is used, the standard time() function returns seconds elapsed since the epoch, sourced from the microcontroller RTC.
Initializes the CLIB support library with an RTC handle.
| Parameter | Type | Description |
|---|---|---|
| rtc | mtb_hal_rtc_t* / cyhal_rtc_t* | Pointer to the RTC handle. May be NULL if time() will not be used. |
Note: For MTB_HAL_API_VERSION >= 3, mtb_clib_support_init must be called before time() is invoked. If not called, time() will assert (when asserts are enabled) and return a default time value.
Returns a pointer to the RTC handle used by the CLIB support library.
| Type | Description | |
|---|---|---|
| Returns | mtb_hal_rtc_t* / cyhal_rtc_t* | Pointer to the RTC handle, or NULL if not initialized. |
Deprecated macros: cy_set_rtc_instance is replaced by mtb_clib_support_init; cy_get_rtc_instance is replaced by mtb_clib_support_get_rtc.
To configure time() with an existing RTC handle:
The library provides the following C library hook implementations:
GCC Newlib: _sbrk, __malloc_lock, __malloc_unlock, __env_lock, __env_unlock
ARM C library: _platform_post_stackheap_init, __user_perthread_libspace, _mutex_initialize, _mutex_acquire, _mutex_release, _mutex_free, _sys_exit, $Sub$$_sys_open, _ttywrch, _sys_command_string
IAR C library: __aeabi_read_tp (FreeRTOS), _reclaim_reent, __iar_system_Mtxinit (FreeRTOS), __iar_system_Mtxlock (FreeRTOS), __iar_system_Mtxunlock (FreeRTOS), __iar_system_Mtxdst (FreeRTOS), __iar_file_Mtxinit, __iar_file_Mtxlock, __iar_file_Mtxunlock, __iar_file_Mtxdst, __iar_Initdynamiclock, __iar_Lockdynamiclock, __iar_Unlockdynamiclock, __iar_Dstdynamiclock, __close, __lseek, remove
LLVM ARM picolibc: __retarget_lock_init_recursive, __retarget_lock_init, __retarget_lock_close_recursive, __retarget_lock_close, __retarget_lock_acquire_recursive, __retarget_lock_acquire, __retarget_lock_release_recursive, __retarget_lock_release, __aeabi_errno_addr, _exit
C++: __cxa_guard_acquire, __cxa_guard_abort, __cxa_guard_release
Time: time() from <time.h>, backed by the microcontroller RTC (when HAL is present)
For reference documentation on the hook interfaces defined by each toolchain, see:
The following options must be enabled in FreeRTOSConfig.h:
To enable Thread Local Storage for GCC Newlib, also enable configUSE_NEWLIB_REENTRANT.
The following option must be enabled:
When building with IAR:
For more information about porting with ThreadX, see the ThreadX GitHub.
LLVM ARM (picolibc) is currently supported for use with FreeRTOS only.
Note: The picolibc printf implementation does not provide thread safety for streams shared between multiple threads. Applications must implement their own synchronization for printf in multithreaded contexts.
This library is used by:
This library depends on:
(c) 2020-2026, Infineon Technologies AG, or an affiliate of Infineon Technologies AG. All rights reserved.