POSIX support in FreeRTOS on STM32
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-21 10:10 AM - last edited on ‎2025-02-24 6:59 AM by Andrew Neil
Hello,
As far as I know,
STM32 does not support the POSIX abstraction layer for FreeRTOS.
That means I can not use functions like:
- Interact with tasks through: 'pthread_create', 'pthread_join'..
- Use POSIX glue elements like: 'pthread_mutex'...
- Etc
If I am porting a big FreeRTOS project that is using POSIX to STM32: what I need to do? Is there a way of achieving it painlessly?
Thanks,
Carles
Solved! Go to Solution.
- Labels:
-
FreeRTOS
-
STM32H7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-21 10:15 AM - edited ‎2025-02-21 10:17 AM
Hello,
I don't think POSIX-FreeRTOS is supported natively by STM32 but I think you need to do it yourself. See https://www.freertos.org/Documentation/03-Libraries/05-FreeRTOS-labs/03-FreeRTOS-plus-POSIX/00-FreeRTOS-Plus-POSIX
https://github.com/FreeRTOS/Lab-Project-FreeRTOS-POSIX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-21 10:15 AM - edited ‎2025-02-21 10:17 AM
Hello,
I don't think POSIX-FreeRTOS is supported natively by STM32 but I think you need to do it yourself. See https://www.freertos.org/Documentation/03-Libraries/05-FreeRTOS-labs/03-FreeRTOS-plus-POSIX/00-FreeRTOS-Plus-POSIX
https://github.com/FreeRTOS/Lab-Project-FreeRTOS-POSIX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-22 9:40 AM
Thanls @mÆŽALLEm ,
I will try to use this FreeRTOS Lab Project and will see if it works (and then I will set it as 'Accept as Solution'.
Many thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-24 5:09 AM
I am trying to compile that 'Lab-Project-FreeRTOS-POSIX' inside my project but I am having some troubles in some "redefinitions" of types or something related wit that.
If I add the required 'include paths' to the build system, I got following errors:
Core/Src/sysmem.c:30:35: error: 'NULL' undeclared here (not in a function)
30 | static uint8_t *__sbrk_heap_end = NULL;
Core/Src/sysmem.c:53:13: error: unknown type name 'ptrdiff_t'
53 | void *_sbrk(ptrdiff_t incr)
So I will keep trying it, but it seems it is not just "plug & play"
Thanks,
Carles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-24 6:44 AM
Hello,
ST is not the provider of that software, so please contact the developers of that POSIX wrapper.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-24 6:46 AM
Ok. Then from 'STM32' part the current answer is that is not possible to use 'POSIX' in STM32 platform, is that correct?
Thanks,
Carles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-24 6:57 AM - edited ‎2025-02-24 6:59 AM
@selracelosuarg wrote:is not possible to use 'POSIX' in STM32 platform, is that correct?
No.
It's just that ST does not provide it as a "ready-to-go" example.
FreeRTOS is an independent 3rd-party product: https://www.freertos.org/
The FreeRTOS site says:
NOTE: FreeRTOS-Plus-POSIX is a FreeRTOS Labs project provided in the hope that it is useful. It is not a complete pthreads implementation, and does not necessary meet our production code quality standard. FreeRTOS-Plus-POSIX is provided in the Lab-Project-FreeRTOS-POSIX
FreeRTOS Forums: https://forums.freertos.org/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-24 7:09 AM
Thanks, I understand.
My point is:
"ST does not provide native support for POSIX out of the box, unlike its support for CMSIS_v2, for example."
Other frameworks, such as esp-idf, offer POSIX support by default, which is why I raised the question. I wanted to check if there is a "native" way to achieve this using STM32 tools or not.
So far, I have managed to compile and run a project using POSIX.
Below is the CMakeLists.txt code I needed to add to make it work:
{
[...]
# Create the 'CMake' configuration for 'Lab-Project-FreeRTOS-POSIX'
add_library(freertos_posix STATIC)
file(GLOB_RECURSE FREERTOS_POSIX_C_FILES "libs/Lab-Project-FreeRTOS-POSIX/*.c")
target_sources(freertos_posix PRIVATE
${FREERTOS_POSIX_C_FILES}
)
target_include_directories(freertos_posix
PRIVATE
# 'Parent' include paths required by 'freertos_posix'
Core/Inc
Middlewares/Third_Party/FreeRTOS/Source/include
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
# Library itself include paths
libs/Lab-Project-FreeRTOS-POSIX/FreeRTOS-Plus-POSIX/include/portable/
libs/Lab-Project-FreeRTOS-POSIX/FreeRTOS-Plus-POSIX/include/portable/st/stm32l475_discovery # TODO: create the corresponding for my board
# Following are also required not just for the library, but also for the project, so set them as PUBLIC
PUBLIC
libs/Lab-Project-FreeRTOS-POSIX/include/
libs/Lab-Project-FreeRTOS-POSIX/FreeRTOS-Plus-POSIX/include
libs/Lab-Project-FreeRTOS-POSIX/include/private # TODO: check why it must be public
)
# Add linked libraries
target_link_libraries(${CMAKE_PROJECT_NAME}
stm32cubemx
# Add user defined libraries
freertos_posix
)
Thanks!
Carles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-24 7:17 AM
@selracelosuarg wrote:"ST does not provide native support for POSIX ...
It's not so much about ST providing it, as the RTOS providing it.
Eclipse ThreadX (formerly Azure RTOS) has an Adaptation layer for POSIX:
https://github.com/eclipse-threadx/threadx/tree/master/utility/rtos_compatibility_layers/posix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-24 7:23 AM
Sorry @Andrew Neil , but I don't agree with you, I see your point, but I don't share it.
See for example:
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/pthread.html
But as far, I think it is clear for me. STM32 is not giving to me a similar think as 'ESP-IDF' does, so it is on my own (or as you are saying, the RTOS provider itself responsability). That is all I wanted to know.
Thanks,
Carles
