Hardware Testing Setup
Relevant source files
The following files were used as context for generating this wiki page:
Hardware Testing Setup within the ComChan project encompasses the configuration and infrastructure required to validate communication with physical embedded devices. The system supports multiple transport layers, including physical Serial (UART), Real-Time Transfer (RTT) via SWD/J-Link, and Bluetooth Low Energy (BLE) using the Nordic UART Service (NUS). This setup allows developers to monitor raw logs and visualize telemetry data in real-time across different hardware architectures such as STM32 and nRF52 series.
The testing environment is designed to be robust, featuring auto-recovery mechanisms for connection drops and a simulation mode that allows for software-based testing without physical hardware. By leveraging a unified configuration system, ComChan ensures consistent behavior whether interacting with a real microcontroller or a simulated data stream.
Sources: README.md:144-165, src/config.rs:260-310
Connection Architectures
ComChan supports three primary hardware interface architectures for testing and monitoring. Each architecture requires specific configuration parameters to establish a stable communication link.
Serial UART Monitoring
The standard serial monitor interfaces with physical COM ports. It utilizes configurable parameters such as baud rate, data bits, stop bits, and parity to match the target device's UART configuration.
The system includes a "Magic Workflow" powered by Grimoire to simplify building and running these tests with specific feature flags like ble or ratty.
Sources: README.md:65-98, src/monitor.rs:188-210, Grimoire.toml:13-30
RTT & Defmt (SWD/J-Link)
For zero-latency logging, ComChan implements a probe mode that bypasses physical UART. This setup requires an ELF file to decode defmt metadata and a specified chip name for probe-rs integration.
| Parameter | Purpose | Source File Reference |
|---|---|---|
--rtt | Enables Real-Time Transfer mode | src/config.rs:242 |
--elf | Path to the compiled firmware ELF for decoding | src/config.rs:247 |
--chip | Target chip name (e.g., nRF52840_xxAA) | src/config.rs:250 |
Sources: README.md:133-138, src/config.rs:240-252, code_tests/stm32_defmt/Cargo.toml:7-14
BLE Streaming (Nordic UART Service)
Wireless telemetry is achieved through BLE. ComChan scans for peripherals and subscribes to the TX characteristic of the Nordic UART Service (NUS).
Hardware Simulation Environment
To facilitate testing without physical hardware, ComChan includes a simulation engine that generates mock sensor data.
Simulation Logic
When the --simulate flag is active, the system bypasses hardware initialization and feeds internally generated sine/cosine waves into the parser. This allows for the validation of the TUI, 2D plotter, and 3D wireframe engine under controlled conditions.
if config.simulate {
let t = state.x * 0.1;
let pitch = (t * 0.5).sin() * 45.0;
let roll = (t * 0.8).cos() * 30.0;
let yaw = (t * 2.0) % 360.0;
state.ingest_line(&format!("Pitch: {:.2}", pitch), config.plot_points);
state.ingest_line(&format!("Roll: {:.2}", roll), config.plot_points);
state.ingest_line(&format!("Yaw: {:.2}", yaw), config.plot_points);
}
Sources: src/plotter.rs:440-452, src/monitor.rs:282-300
Configuration and Recovery Setup
A robust testing setup requires handling hardware resets and connection drops. ComChan manages this via a merged configuration structure.
Key Hardware Settings
The MergedConfig struct handles the final state of the hardware connection settings after merging command-line arguments and config.toml.
| Config Option | Default | Description |
|---|---|---|
timeout_ms | 500ms | OS serial read timeout |
reset_delay_ms | 1000ms | Delay after opening port for hardware to stabilize |
port | "auto" | Auto-detection for USB serial ports |
baud | 9600 | Standard communication speed |
Sources: src/config.rs:115-135, src/config.rs:336-350
Reconnection Logic
For both RTT and Serial modes, the system enters a polling loop upon connection loss. It attempts to re-initialize the interface while providing visual feedback in the status bar.
Sources: src/monitor.rs:245-275, src/plotter.rs:468-478
Summary
The Hardware Testing Setup provides a flexible framework for embedded development, ranging from standard UART debugging to advanced RTT and BLE telemetry. By combining physical device support with a comprehensive simulation mode and automated recovery logic, ComChan ensures that hardware-software integration remains verifiable throughout the development lifecycle.
Sources: README.md:155-170, src/monitor.rs:560-565