Skip to content

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

ItemValueNotes
PeripheralUART4STM32L562xx
Baud Rate115200 8N1RS-232 compatible
RX Buffer2048 bytesCircular, DMA-fed
TriggerIdle Line~95 µs @ 115200
Poll Rate1-3 msMain task loop
Speed EncodingCompacts04++ = 44%, m = 100%
Telemetry FormatKey=ValueS=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

ItemValueNotes
PeripheralFDCANSTM32L562xx
ProtocolCAN 2.0B Classic11-bit standard IDs
Bitrate500 kbps (typical)Configurable
RX Buffer128 framesRing buffer
TX Buffer128 framesQueued frames
Status Rate50 Hz20 ms period
ISR Batch Size2 framesPrevents overrun
Process Budget8 framesPer task cycle
Passthrough Delay1 msInter-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 passthrough

Integration 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

Released under the MIT License.