cancel
Showing results for 
Search instead for 
Did you mean: 

Running CRC check in HAL uart driver

phoenixjia
Associate III

I am using "HAL_UART_Transmit" and "HAL_UART_Receive" in the HAL uart driver to perform uart communication. While adding the CRC check to the communication protocol, I am wondering if there's any HAL uart driver API that incorporates CRC check functions, e.g., the sender calls "HAL_UART_Transmit_Until_CRC_Check_Complete" and the receiver calls "HAL_UART_Receive_with_CRC_Check"? So both the sender and receiver API will return when CRC check is complete.

8 REPLIES 8

There is not.

You should add whatever you need in the transmission of the buffer, or have some chaining / scatter gather mechanism where you generate, accumulate and output as part of your call back handlers for interrupts, or your wrapping of packet generation in polled mode.

Similar in the state machine or packet parsing on the input.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

So how the receiver notifies the sender in case of the CRC check failure?

phoenixjia
Associate III

Or the sender will expect a confirmation message sent back from the receiver indicating the result of the CRC check (either success or failure).

You deal with that in your protocol layer, say for X-MODEM you send an ACK if it was received correctly, and NACK if it was wrong, and you have a timeout some where to deal with the cases where insufficient data was moved, and some response was expected.

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

Or the sender will expect a confirmation message sent back from the receiver

Which option do you like more? The wheel is already invented. Use some well-know protocol.

 

Can you elaborate any well-known protocols? Either ACK/NACK or a confirmation message needs another pair of "HAL_UART_Transmit" and "HAL_UART_Receive", which adds a layer of complexity to the protocol.

SLIP, SDLC, X/Y-MODEM, several binary packet formats used by GPS/GNSS receivers, say uBlox or SiRF..

Nobody is interested in cluttering up the HAL_UART implementation with random protocols with limited use or appeal.

Having any kind of send / response on UARTs tends to be pretty niche, same for error detection, correction, or integrity checking.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
phoenixjia
Associate III

So here is the simplest solution with the CRC check. The sender will wait until the CRC check result comes back to complete a send request. Is it good enough?

 

         Sender                                  Receiver
HAL_UART_Transmit  --------------------------->HAL_UART_Receive
               |                                     |
               |                                  CRC check
               |                                     |
HAL_UART_Receive <--------------------------   HAL_UART_Transmit
               |                                     |