Interrupt with HAL UART for FreeRTOS

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Sanyika67
Level 1
Level 1
First solution authored 5 sign-ins First reply posted

Hello,


I want to use the UART with FreeRTOS using the mtb_hal_cat1 library.

I use redirect_io for the printf.

My question is how to enable RX interrupt with HAL lib to use with a FreeRTSO task.

I tried with this 2 functions : 

cyhal_uart_register_callback(&cy_retarget_io_uart_obj, uart_event_handler, NULL);
cyhal_uart_enable_event(&cy_retarget_io_uart_obj,(cyhal_uart_event_t)CYHAL_UART_IRQ_RX_NOT_EMPTY ,1, true);

 

But it never goes on the callback function

Thank you

Alexandre

0 Likes
1 Solution
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @Sanyika67 

 

You need to use the cyhal_uart_read_async API for the UART block to be enabled and the interrupt to trigger when data is received in the Rx buffer. Please try calling this API to initiate the UART read and see if the interrupt is triggered. 

Please make sure that the UART function is running inside a task in FreeRTOS as well to ensure proper flow. 

 

Could you please share your project with us so that we can try it at our end as well?

 

Best regards, 
Hari

View solution in original post

3 Replies
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @Sanyika67 

 

You need to use the cyhal_uart_read_async API for the UART block to be enabled and the interrupt to trigger when data is received in the Rx buffer. Please try calling this API to initiate the UART read and see if the interrupt is triggered. 

Please make sure that the UART function is running inside a task in FreeRTOS as well to ensure proper flow. 

 

Could you please share your project with us so that we can try it at our end as well?

 

Best regards, 
Hari

Sanyika67
Level 1
Level 1
First solution authored 5 sign-ins First reply posted

It's working well using async funct,

the issues was more on the FreeRTOS side 

thank you

0 Likes
SandraLewisFrin
Level 1
Level 1
10 sign-ins 5 questions asked 5 sign-ins

I am working on STM32L152VB-A controller. I am using FreeRTOS.
I used CubeMX to generate the code and I configured USART1 with global interrupts.
The non interrupt RX and TX (HAL_UART_Receive and HAL_UART_Transmit) is working.
But I am trying to make it work with interrupts.

Only after I called HAL_UART_Receive_IT, I am getting interrupt.
Since I couldn't know the receive data size, I am planning to receive characters one by one.

Since I use RTOS, I am confused about where to write HAL_UART_Receive_IT, as the message can come at any time. can anybody guide me??

PS: I tried calling the HAL_UART_Receive_IT inside ISR, but it is also not working.

0 Likes