Serial & Tracing
Three serial communication protocols are integrated into the Firmware Environment.
UART Serial Monitor
Port Detection
> fw_serial_list_portsAuto-detects USB serial devices:
- ST-Link virtual COM port
- J-Link CDC
- FTDI (FT232, FT2232)
- CP2102 / CP2104
- CH340 / CH341
Connecting
> fw_serial_connect /dev/ttyUSB0 115200Parameters:
- Port path
- Baud rate (auto-detection available via
fw_serial_auto_baud) - Data bits (default: 8)
- Parity (default: none)
- Stop bits (default: 1)
Sending Data
> fw_serial_send "AT+RST\r\n"Sends a string. For binary data, use hex mode.
Reading
> fw_serial_readReturns buffered received data with timestamps per line.
Features
- Auto-reconnect — Recovers when USB device disconnects/reconnects
- DTR/RTS control — Toggle signals for bootloader entry (e.g., ESP32 auto-reset)
- HEX mode — Binary protocol display
- Log export — Export session to text or CSV
- Ring buffer — Configurable max line count
Baud Rate Auto-Detection
> fw_serial_auto_baudTries common baud rates (9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600) and reports which produces valid ASCII.
RTT (Real-Time Transfer)
Segger Real-Time Transfer provides zero-overhead debug logging over SWD/JTAG — no UART pins required.
How It Works
RTT uses a small RAM buffer on the MCU. The debug probe reads this buffer in the background during normal execution, with zero CPU overhead.
Requirements
- Segger J-Link probe (or compatible)
- RTT control block in firmware (
SEGGER_RTT.h)
Backends
| Backend | Tool | Notes |
|---|---|---|
| JLinkExe | Segger CLI | Most reliable |
| pylink | Python package | Scriptable |
Usage
> fw_rtt_startStarts RTT session. Data flows from MCU to host via the debug probe.
> fw_rtt_read 0Reads from channel 0 (default printf/logging channel).
> fw_rtt_write 1 "config:verbose"Writes to a down-channel (host → MCU).
Channels
RTT supports up to 32 channels:
- Channel 0 — Default printf/logging (up)
- Channels 1-15 — Custom data (up)
- Channels 16-31 — Down channels (host → MCU)
Storage
RTT logs are saved to .inverse/rtt/<sessionId>/ch<N>.log.
ITM / SWO (Instrumentation Trace Macrocell)
ARM Cortex-M3/M4/M7/M33 processors include hardware tracing via the SWO (Serial Wire Output) pin.
Requirements
- Cortex-M3 or higher
- SWO pin connected to debug probe
- CPU frequency known (for SWO baud calculation)
Usage
> fw_itm_startConnects to ITM via SWO pin.
> fw_itm_readReads ITM trace output.
SWO Profiling
> fw_swo_profileUses DWT (Data Watchpoint and Trace) cycle counter and exception trace for:
- Function timing
- Interrupt latency
- Sleep/wake profiling
Agent Tools
| Tool | Description |
|---|---|
fw_serial_list_ports | List available serial ports |
fw_serial_connect | Connect to a serial port |
fw_serial_disconnect | Disconnect |
fw_serial_send | Send data |
fw_serial_read | Read received data |
fw_serial_monitor | Stream serial output |
fw_serial_clear | Clear buffers |
fw_serial_auto_baud | Auto-detect baud rate |
fw_rtt_start | Start RTT session |
fw_rtt_read | Read RTT channel |
fw_rtt_write | Write to RTT down-channel |
fw_itm_start | Start ITM/SWO tracing |
fw_itm_read | Read ITM output |
fw_swo_profile | DWT cycle profiling |
Last edited