Skip to main content
Visitor II
June 18, 2024
Question

Running CRC check in HAL uart driver

  • June 18, 2024
  • 4 replies
  • 2248 views

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.

    This topic has been closed for replies.

    4 replies

    Graduate II
    June 18, 2024

    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.

    Visitor II
    June 18, 2024

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

    Graduate II
    June 18, 2024

    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.

     

    Visitor II
    June 18, 2024

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

    Super User
    June 18, 2024

    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.

     

    Visitor II
    June 18, 2024

    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.

    Graduate II
    June 18, 2024

    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.

    Visitor II
    June 20, 2024

    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
     | |