So far, the communication was the hardest part of every project I was part of. I already did a tool to ease debugging and creating an aplication layer, but still, the hard part was to correctly receive all bytes and in case of error, recover or retry.
I tried a lot of things, but none of them really worked for me: fixed length messages, dma, acknowledgement, … One solution, two new problems. Than a whole new bunch of problems with STM32 HAL UART drivers and their libraries. And all I want is just to send a couple of bytes reliably.
Solution: SDP – Simple Data Protocol
Main objective of this protocol is to send/receive data between different nodes, with payloads up to 255 bytes. User should care only to send response to received messages and to handle errors if messages was not send/received even after all retries. Other should handle the protocol itself.
Protocol receives all bytes on the serial line using RX not empty interrupt and than parse the message (eg, discarding invalid bytes, search for SOF, DLE and EOF flags), check message with CRC-16 and than passing only valid message payload to user handler.
This is a template. Example provides a code to use this library with STM32 Low Layer (LL) UART and CRC drivers, but can easily be customized to any other microcontroller. Files are neatly commented so the porting should be “easy”. Python (v2 and v3 compatible) module is also available.
All other informations and code examples can be found on Github: