2025-02-21 10:10 AM - last edited on 2025-02-24 06: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:
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.
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
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
2025-02-22 09: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!
2025-02-24 05: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
2025-02-24 06:44 AM
Hello,
ST is not the provider of that software, so please contact the developers of that POSIX wrapper.
Thanks.
2025-02-24 06: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
2025-02-24 06:57 AM - edited 2025-02-24 06: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/
2025-02-24 07: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
2025-02-24 07: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
2025-02-24 07: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