Skip to main content
Visitor II
February 24, 2023
Solved

HAL_UART functions do not work with Azure RTOS ThreadX

  • February 24, 2023
  • 5 replies
  • 2646 views

Hello,

I followed this guide:

https://community.st.com/s/article/how-does-the-threadx-semaphore-work

And everything works.

But when I try to add a modification, a HAL_UART_Transmit - HAL_UART_Transmit(&huart2, (uint8_t *)&message, 1, 10); - in one thread I always get the error 'huart2' undeclared. Well huart2 is declared in my main.c but of course not in the app_thread.c. And there are my threads.

So my question is how can I solve this error? With FreeRTOS I just created threads and all the code in my main.c so there was no issue to use HAL_UART. But I am not sure how to solve it on ThreadX?

    This topic has been closed for replies.
    Best answer by Karl Yamashita

    extern UART_HandleTypeDef huart2;

    5 replies

    MStew.1Author
    Visitor II
    February 24, 2023

    The same for HAL_GPIO_WritePin or HAL_GPIO_TogglePin.. I am not able to use them with Azure RTOS in the threads in the app_threadx.c file. Is there a way to be able to use them?

    Graduate II
    February 24, 2023

    I get the same error. So the fix was to add #include "main.h" to the app_threadx.c file

    MStew.1Author
    Visitor II
    February 25, 2023

    Thank you @Community member​ this solved the problem with the LEDs, the HAL_GPIO_WritePin or HAL_GPIO_TogglePin works. But still the HAL_UART_Transmit function does not work in the app_threadx.c file. Do you know how to solve this too?

    Graduate II
    February 25, 2023

    Well "HAL_UART_Transmit function does not work" is kind of vague. You need to describe the issue in more detail.

    MStew.1Author
    Visitor II
    February 26, 2023

    So I followed this guide:

    https://community.st.com/s/article/how-does-the-threadx-semaphore-work

    And everything works as expected.

    But I wanted to modify the example. I added in my app_threadx.c file in my threads the

    HAL_UART_Transmit and HAL_UART_Receive functions. I initialized the uart in the CubeMX configurations so its in there.

    But the problem I face is the following: Since I add all my code in the app_threadx.c and so my uart transmit and receive functions in my threads I get the error when I try to build: 'huart2' undeclared - The uart2 is declared in my main.c file but not in the app_threadx.c.

    So how can I use uart transmit and uart receive in my threads?

    With FreeRTOS it was straight forward, as I did all the code in the main.c so I could use the uart transmit and receive functions in my threads out of the box as it was all in the main.c file.

    Graduate II
    February 26, 2023

    extern UART_HandleTypeDef huart2;