feat(firmware): Jetson binary serial protocol on USART1 (Issue #120) #132

Merged
sl-jetson merged 1 commits from sl-firmware/issue-120-serial-protocol into main 2026-03-02 09:26:46 -05:00
Collaborator

Issue #120 — STM32 Serial Binary Protocol

Summary

  • New jlink module: USART1 (PB6/PB7) at 921600 baud, DMA2_Stream2_Channel4 circular RX, IDLE interrupt
  • Binary frame: [STX][LEN][CMD][PAYLOAD][CRC16_hi][CRC16_lo][ETX], CRC16-XModem
  • Commands: 0x01 HEARTBEAT, 0x02 DRIVE, 0x03 ARM, 0x04 DISARM, 0x05 PID_SET, 0x07 ESTOP
  • 50 Hz STATUS telemetry TX — 20-byte packed struct (pitch/roll/yaw×10, motor_cmd, vbat_mv, RSSI/LQ, balance_state, rc_armed, mode, estop, soc_pct, fw version)
  • 1s heartbeat timeout → jlink_is_active() false; main loop clears auto command (RC-only fallback)
  • jlink takes priority over legacy jetson_cmd; both coexist for backward compat
  • 39 pytest tests — all passing

Files

  • include/jlink.h — new
  • src/jlink.c — new
  • include/config.h — JLINK_BAUD, JLINK_HB_TIMEOUT_MS, JLINK_TLM_HZ, FW_MAJOR/MINOR/PATCH
  • src/main.c — integration: jlink_init, jlink_process, flag handlers, 50 Hz telemetry TX
  • test/test_jlink_frames.py — new, 39 tests

Closes #120

## Issue #120 — STM32 Serial Binary Protocol ### Summary - New `jlink` module: USART1 (PB6/PB7) at 921600 baud, DMA2_Stream2_Channel4 circular RX, IDLE interrupt - Binary frame: `[STX][LEN][CMD][PAYLOAD][CRC16_hi][CRC16_lo][ETX]`, CRC16-XModem - Commands: `0x01` HEARTBEAT, `0x02` DRIVE, `0x03` ARM, `0x04` DISARM, `0x05` PID_SET, `0x07` ESTOP - 50 Hz STATUS telemetry TX — 20-byte packed struct (pitch/roll/yaw×10, motor_cmd, vbat_mv, RSSI/LQ, balance_state, rc_armed, mode, estop, soc_pct, fw version) - 1s heartbeat timeout → jlink_is_active() false; main loop clears auto command (RC-only fallback) - jlink takes priority over legacy jetson_cmd; both coexist for backward compat - 39 pytest tests — all passing ### Files - `include/jlink.h` — new - `src/jlink.c` — new - `include/config.h` — JLINK_BAUD, JLINK_HB_TIMEOUT_MS, JLINK_TLM_HZ, FW_MAJOR/MINOR/PATCH - `src/main.c` — integration: jlink_init, jlink_process, flag handlers, 50 Hz telemetry TX - `test/test_jlink_frames.py` — new, 39 tests Closes #120
sl-webui added 1 commit 2026-03-02 09:23:43 -05:00
New jlink module replaces ASCII-over-USB-CDC jetson_cmd with a dedicated
hardware UART binary protocol at 921600 baud for reliable Jetson comms.

- include/jlink.h: JLinkState struct, jlink_tlm_status_t (20-byte packed),
  command/telemetry IDs (0x01-0x07 cmd, 0x80 status), API declarations
- src/jlink.c: USART1 DMA2_Stream2_Channel4 circular RX (128 bytes),
  IDLE interrupt, CRC16-XModem (poly 0x1021) frame parser state machine,
  command dispatch (HEARTBEAT/DRIVE/ARM/DISARM/PID_SET/ESTOP),
  jlink_send_telemetry() blocking TX (≈0.28 ms per frame)
- include/config.h: JLINK_BAUD=921600, JLINK_HB_TIMEOUT_MS=1000,
  JLINK_TLM_HZ=50, FW_MAJOR/MINOR/PATCH version constants
- src/main.c: jlink_init(), jlink_process() in main loop, arm/disarm/
  estop/PID flag handling, 50 Hz STATUS telemetry TX, jlink takes
  priority over legacy jetson_cmd for speed/steer injection
- test/test_jlink_frames.py: 39 pytest tests (39/39 pass) — CRC16,
  frame building, parser state machine, drive/PID/status encoding

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sl-jetson merged commit 6da4ae885d into main 2026-03-02 09:26:46 -05:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: seb/saltylab-firmware#132
No description provided.