cancel
Showing results for 
Search instead for 
Did you mean: 

Seeking Assistance with Variable-Length UART Receive Interrupts on STM32F091RC using STM32Cube IDE

SANTHOSH1
Associate II

Dear ST Community,

I'm currently working on STM32F091RC using STM32Cube IDE, and I've encountered an issue with handling UART receive interrupts for variable-length data. Currently, I have set a fixed length of 5 bytes for the data, and the UART communication is functioning properly. However, I now require the flexibility to receive data of varying lengths, such as 1 byte, 5 bytes, and so on.

Despite my attempts to modify the code to accommodate variable-length data reception, the UART doesn't seem to work reliably. I believe I might be missing something crucial in my implementation.

Could someone please provide guidance, code snippets, or any possible solutions to efficiently handle variable-length UART receive interrupts for the STM32F091RC?

Any help or insights would be greatly appreciated.

Thank you,

Santhosh

1 ACCEPTED SOLUTION

Accepted Solutions
Saket_Om
ST Employee

Hello SANTHOSHI1

 

You can find an example of how to use HAL_UARTEx_ReceiveToIdle_DMA in a project by following the link. It can serve as an inspiration for your own project.

If your question is answered, please close this topic by clicking "Accept as Solution".
Thanks

Omar

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

View solution in original post

5 REPLIES 5
Andrew Neil
Evangelist III

The classic way to do it on any microcontroller is to just have the interrupt receive one byte at a time into a circular (ring)  buffer. Processing of the received data is then done in the "mainline" code.

 

Saket_Om
ST Employee

Hello SANTHOSH

 

A new HAL UART API has been introduced by ST for the purpose of managing continuous reception or reception of an unknown length. It is based on the reception continuing until either the expected length is received, or an IDLE event occurs. This API is available in Interrupt or DMA modes, namely HAL_UARTEx_ReceiveToIdle_IT and HAL_UARTEx_ReceiveToIdle_DMA.

An example has been developed for this use case, and it is available in some STM32 firmware packages (G0/G4/L5) under the name Examples\UART\UART_ReceptionToIdle_CircularDMA.

It is recommended that you review this example to determine if it meets your requirements.

 

If your question is answered, please close this topic by clicking "Accept as Solution".
Thanks

Omar

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

It sounds like a robust approach, and I'm eager to implement it in my project. Would you be able to share a code snippet or offer guidance on how to implement this technique effectively? I would greatly appreciate any insights or examples you could provide.

Saket_Om
ST Employee

Hello SANTHOSHI1

 

You can find an example of how to use HAL_UARTEx_ReceiveToIdle_DMA in a project by following the link. It can serve as an inspiration for your own project.

If your question is answered, please close this topic by clicking "Accept as Solution".
Thanks

Omar

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar
Saket_Om
ST Employee

Hello @SANTHOSHI1

 

If your question is answered, please close this topic by clicking "Accept as Solution".


Thanks

Omar

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar