An interrupt-driven, dual-UART message parser for STM32 (tested on NUCLEO-G431RB) that:
- Uses a state machine to validate incoming frames (ID โ LEN โ DATA โ CRC)
- Buffers data in a lock-free circular buffer for non-blocking reception
- Verifies message integrity using CRC16/CMS (poly
0x8005, init0xFFFF, xorOut0x0000) - Sends a fixed 6-byte response on valid CRC
- Non-blocking UART RX using HAL
HAL_UART_Receive_ITand per-UART circular buffers - Deterministic parsing with strict ID โ LEN mapping
- Table-driven CRC16/CMS calculation for efficiency
- Works with two UART interfaces independently
.
โโ circular_message.c / .h # Circular buffer implementation
โโ message_state.c / .h # State machine parser & response builder
โโ crc16_cms.c / .h # CRC16/CMS calculation
โโ main.c # UART init, interrupt handling, main loop
โโ STM32-UART-Protocol-Parser-with-CRC16.ioc # STM32CubeMX configuration
โโ PROTOCOL.md # On-wire protocol specification
โโ Message Examples.txt # Example request/response frames
โโ LICENSE
โโ .gitignore
Frame format (big-endian CRC): [ ID(1) | LEN(1) | DATA(LEN-4) | CRC_HI(1) | CRC_LO(1) ]
markdown Kopyala Dรผzenle
- Allowed IDs:
0x55, 0x66, 0x77, 0x88, 0x99 - LEN includes all fields; DATA length = LEN โ 4
- CRC16/CMS is computed over
ID..last DATA byte - ID โ LEN mapping: 0x55 โ 0xFF 0x66 โ 0x7F 0x77 โ 0x06 0x88 โ 0x07 0x99 โ 0x05
yaml Kopyala Dรผzenle
See PROTOCOL.md for full details.
From Message Examples.txt:
Request: 77 06 88 BD 9F CC
makefile Kopyala Dรผzenle Response: 33 05 F1 33 E9
yaml Kopyala Dรผzenle (Last two bytes are CRC16/CMS over [ID..OUT3])
- Open
STM32-UART-Protocol-Parser-with-CRC16.iocin STM32CubeIDE - Generate code and ensure
Src/andInc/contain the provided.cand.hfiles - Connect NUCLEO-G431RB via USB
- Flash the program to the board
- Open HTerm / Serial Monitor @ 115200-8N1 and send example frames in HEX mode
This project is released under the MIT License. See LICENSE.
Developed by Erkin Coลkun Ruhi
