Communication Module
Overview
This module encompasses all communication subsystems in the Galvanic Isolator: CAN bus for vehicle-level integration and UART (RS-232) for inverter interface. The implementation emphasizes reliability through interrupt-driven hardware interfaces, ring buffers, and efficient deferred processing.
Code Organization
- Headers:
Core/Inc/App/Communication/ - Source:
Core/Src/App/Communication/ - UART Implementation:
uart_comm.h,uart_comm.c - CAN Implementation:
can_comm.h,can_comm.c,can_driver.h,can_driver.c
Documentation Split
For detailed protocol information, see the specialized documents:
UART/RS-232 Communication
Covers the inverter serial interface with:
- DMA circular buffering - Continuous non-blocking reception into 2048-byte buffer
- Idle Line detection - Automatic message boundary detection (~95 µs idle threshold)
- Key=value protocol - RS-232 telemetry format (S, U, I, RPM, PWM, temperatures)
- Speed control encoding - Compact command format (e.g.,
s04++for 44% speed) - Pass-through mode - Bridge UART data across CAN for remote debugging
CAN Bus Communication
Covers the vehicle integration network with:
- FDCAN peripheral - STM32L562 hardware, 11-bit IDs, classic CAN 2.0B format
- Status frames - Periodic 50 Hz telemetry broadcast (PWM, voltage, current, RPM, temperatures)
- Debug frames - On-demand diagnostic information
- Bootloader frames - Remote firmware update and device programming
- Pass-through framing - Multi-frame UART data tunneling with START/END markers
- Ring buffer processing - 128-frame buffering with batch ISR limits
- Bus-off recovery - Automatic error state handling
System Architecture
Data Flow Sequence
Quick Reference Guide
UART Communication Cheat Sheet
| Item | Value | Notes |
|---|---|---|
| Peripheral | UART4 | STM32L562xx |
| Baud Rate | 115200 8N1 | RS-232 compatible |
| RX Buffer | 2048 bytes | Circular, DMA-fed |
| Trigger | Idle Line | ~95 µs @ 115200 |
| Poll Rate | 1-3 ms | Main task loop |
| Speed Encoding | Compact | s04++ = 44%, m = 100% |
| Telemetry Format | Key=Value | S=2.45, RPM=2450 |
Example UART Speed Commands:
0 → 0% (stop)
s1---- → 4% (4 dashes)
s04++ → 44% (tens=4, ++=additional 4%)
m → 100% (max speed)CAN Bus Cheat Sheet
| Item | Value | Notes |
|---|---|---|
| Peripheral | FDCAN | STM32L562xx |
| Protocol | CAN 2.0B Classic | 11-bit standard IDs |
| Bitrate | 500 kbps (typical) | Configurable |
| RX Buffer | 128 frames | Ring buffer |
| TX Buffer | 128 frames | Queued frames |
| Status Rate | 50 Hz | 20 ms period |
| ISR Batch Size | 2 frames | Prevents overrun |
| Process Budget | 8 frames | Per task cycle |
| Passthrough Delay | 1 ms | Inter-frame spacing |
Message ID Ranges:
0x020-0x021 → Left inverter status (L_ID=0x004)
0x030-0x031 → Right inverter status (R_ID=0x005)
0x0E0 → ECU command broadcast
0x4F0-0x4F1 → Bootloader & programming
0x023-0x025 → Left inverter passthrough
0x033-0x035 → Right inverter passthroughIntegration Notes
- UART polling should be called from main task loop (e.g., every 1-3 ms)
- CAN RX processing uses time budgets to prevent starvation
- Status frame transmission runs on 20 ms timer (50 Hz)
- Pass-through mode bridges UART↔CAN for remote diagnostics
- Hardware errors trigger FSM fault states for safety handling
- Both subsystems are transport-independent for future protocol additions
