Back to Home

UART CLI for microcontrollers: debug commands

The material describes the implementation of UART CLI for debugging microcontroller firmware. Covers commands for diagnosing hardware resources, peripherals, performance, and built-in calculators. Examples for middle/senior developers.

CLI in MCU: from GPIO to CAN and PLL calculators
Advertisement 728x90

Implementing UART CLI for Microcontroller Firmware Debugging

UART CLI provides a command-line interface over UART for debugging microcontroller firmware. The syntax is similar to assembler: command name followed by positional arguments separated by spaces. One command — one line.

command_name arg1 arg2 arg3 ...

To connect from a PC, use TeraTerm with inter-byte delay settings to avoid overflowing the firmware buffer. The first thing that appears in the console is the system initialization log in green, similar to a black box flight recorder. After initialization, the --> prompt appears, sometimes with uptime to verify clocking.

Command Structure: Getters and Setters

Commands are divided into getters (viewing states) and setters (changing parameters). Getters are safe for firmware analysis.

Google AdInline article slot
  • h or help [substring] — list of commands, filtered by substring.
  • TAB — command autocompletion.
  • vi — firmware version, compiler, git SHA256.

The ll [module] command displays logging levels for modules and supports printf-style debugging.

h
h gpio

Hardware Resource Diagnostics

CLI provides access to the state of key subsystems:

  • freq — core frequency.
  • clk — enabled clocks for subsystems.
  • gl — GPIO pin states.
  • rm [addr] [bytes] — read memory by address.
  • wm [addr] [data] — write to memory.

For registers:

Google AdInline article slot
rr timer5 0x10
nrm  # reading NAU8814 registers over I2C

List of diagnostic commands:

| Command | Description |

|---------|----------|

Google AdInline article slot

| fd | Flash diagnostics |

| pwd | PWM settings |

| lmd | LED status |

| intd | Interrupts |

| cdf | CAN filters |

| trd | Timers |

| cd | Stack fill levels per core |

Network and Peripheral Interfaces

  • i2cs — scan I2C bus, displays device addresses (DS3231, EEPROM).
  • cs [can_num] [id] [hex_data] — send CAN packet.
  • ll can debug — log of received CAN packets.

The repeat [cmd] N P command repeats a command N times with period P ms — useful for stress tests.

Performance and Task Monitoring

  • scd — super loop diagnostics: while(1) iterations/sec, average duration.
  • Task scheduler: view and disable by ID without rebuilding.
  • nvram — read/write NVRAM for reconfiguration.

Example super loop on MCU and PC:

![scd on MCU]

reboot — core reboot.

Built-in Calculators and Utilities

CLI turns the device into a computing tool:

  • Base64, RLE, AES256 decoding.
  • SHA256, CRC16 hashing.
  • GNSS distances, vector angles.
  • Linear equations, PLL coefficients (clock_pll_calc 220000000).
  • bd val1 val2 — bit diff in 32-bit registers.
  • Capacitor value by marking.
  • cfim — actual CAN IDs by mask.

Voltage divider example:

calc_vdiv R1=1000 R2=1000 Vin=3.3

Unit tests run by substring: test i2c.

Key Points

  • UART CLI is essential in debug builds for bring-up and debugging.
  • Doesn't hang on power reconnection, unlike SWD/JTAG.
  • Supports UART, stdin/stdout, other protocols.
  • Firmware updates and calibration via CLI.
  • Number of commands adapts to flash size.

Implementation Facts

CLI is a hierarchical structure of firmware modules. It parses commands and routes them to components. On Windows, it's a console application like BusyBox for debugging under controlled conditions. Auto-exit after 60 sec timeout or Esc.

— Editorial Team

Advertisement 728x90

Read Next