2024-06-18 12:22 PM
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.
2024-06-18 12:35 PM
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.
2024-06-18 12:43 PM
So how the receiver notifies the sender in case of the CRC check failure?
2024-06-18 12:53 PM
Or the sender will expect a confirmation message sent back from the receiver indicating the result of the CRC check (either success or failure).
2024-06-18 12:59 PM - edited 2024-06-18 01:35 PM
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.
2024-06-18 01:29 PM
> 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.
2024-06-18 02:27 PM
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.
2024-06-18 02:45 PM
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.
2024-06-19 05:49 PM
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
| |