Serial command shell firmware for ATmega328P boards on PlatformIO. Current board targets:
- ATmega328P Xplained Mini
- Arduino Uno
The project provides:
- Interactive UART shell (
arduino$prompt) - GPIO, timing, I2C, EEPROM, and low-level AVR register commands
- EEPROM-backed mini filesystem (
fs ...) - Startup script support (
/scripts/boot.sh) with background LED blink task
- MCU: ATmega328P @ 16 MHz
- Framework: Arduino
- Serial monitor baud: 57600
Supported board definitions:
atmega328p_xplained_mini- Uses custom board file:
boards/atmega328p_xplained_mini.json - Typical upload:
xplainedmini_isp(EDBG over USB)
- Uses custom board file:
uno- Uses PlatformIO built-in Arduino Uno board definition
- Typical upload: Optiboot serial bootloader (
arduinoprotocol)
src/main.cpp: boot sequence + main loopsrc/shell.hpp: shared constants and function declarationssrc/shell_shared.cpp: parsers, helpers, FS primitives, history, common statesrc/shell_help.cpp: top-level help/status textsrc/shell_commands.cpp: command dispatchersrc/shell_commands_*.cpp: command groups by domain (fs,i2c,eeprom,gpio,lowlevel)src/shell_io.cpp: serial line input, echo, history (up/down arrows)src/shell_startup.cpp: startup script loader and background blink taskplatformio.ini: build/env config + feature switchesboards/atmega328p_xplained_mini.json: custom board definition
- PlatformIO Core installed
pioinPATHor use~/.platformio/penv/bin/pio
Examples below use the explicit binary path:
PIO=~/.platformio/penv/bin/pio
Select board in platformio.ini first:
[target]
board = atmega328p_xplained_mini
; board = unoBuild (single environment):
$PIO run -e avrUpload:
$PIO run -e avr -t uploadOpen monitor:
$PIO device monitor -e avrIf you prefer plain monitor command, keep baud at 57600.
Notes:
verandidprint board name based on the selected target.- Upload transport is board-dependent (EDBG ISP for Xplained Mini, serial bootloader for Uno).
In [features] (0 = disabled, 1 = enabled):
feature_i2cfeature_eepromfeature_fs(requiresfeature_eeprom=1)feature_tonefeature_lowlevel
These map to compile-time flags (FEATURE_*) in build_flags.
Use a single environment and switch board in [target]:
[target]
board = atmega328p_xplained_mini
; board = unoThe selected board also controls compile-time board identification used by shell commands (ver, id).
-DFW_VERSION="1.1.0"-DDEMO_BAUD=57600UL
board_hardware.eesave = yes is enabled.
This keeps EEPROM content across uploads that involve chip erase operations (notably ISP flows). For Uno serial bootloader uploads, EEPROM is typically preserved as well unless explicitly erased by tooling or firmware commands.
Type help in the terminal for runtime-visible commands.
helpstatusveridecho <text>freeuptimemicrosreset
pinmode <pin> <in|out|pullup>digitalread <pin>digitalwrite <pin> <0|1>analogread <A0-A5>pwm <pin> <0-255>pulse <pin> <count> <high_ms> <low_ms>watch <pin>delay <ms>freq <pin> [ms]tone <pin> <freq> [ms]/notone <pin>(whenfeature_tone=1)
i2cscani2cspeed <100k|400k>i2cread <addr> <n>i2cwrite <addr> <bytes...>i2cwr <addr> <reg> <bytes...>i2crr <addr> <reg> <n>
eepread <addr> [len]eepwrite <addr> <bytes...>eeperase confirm
fs helpfs format confirmfs ls [path]fs cat <path>fs mkdir <path>fs touch <path>fs write <path> <text>fs rm <path>fs stat
Notes:
- EEPROM size is 1024 bytes on ATmega328P.
- FS reserves metadata and uses the remaining space for file data.
eep*commands operate on raw EEPROM and can destroy FS data.
ddr <port> [value]port <port> [value]pin <port>peek <addr>poke <addr> <val>reg
On boot (when feature_fs=1):
- FS is initialized if needed.
/scriptsdirectory is ensured./scripts/boot.shis auto-created if missing.- Script is parsed and executed.
Default auto-created script:
# Startup script
# blink <pin> <period_ms>
blink 13 1000Supported script syntax right now:
- Blank lines and
#comments blink <pin> <period_ms>
blink starts a non-blocking background task handled from loop().
- Target has only 2 KB SRAM. Keep stack usage low, especially in command handlers.
- Avoid large local buffers in deep call paths (
fscommands are the most stack-sensitive). - Prefer flash-stored strings/constants (
F(...),PROGMEM) over RAM globals where practical. - Feature flags in
platformio.iniare the primary way to trim footprint. eep*raw EEPROM commands andfscommands share the same EEPROM space. Mixing them can corrupt FS metadata/data.- If behavior becomes unstable (garbled output/resets), check memory first:
- Disable heavy features temporarily (
feature_* = 0) to bisect. - Recheck stack-heavy paths in recently changed code.
- Rebuild and verify memory report from PlatformIO output.
- Disable heavy features temporarily (
peek/pokeare intentionally dangerous and can crash the MCU. Use at your own risk.resettriggers watchdog reset immediately.watchandpulsecan be interrupted with any key.- If terminal output looks like garbage, check baud is
57600.
help
fs stat
fs ls /
fs cat /scripts/boot.sh
Then edit/create files with fs write ... as needed.
This project is licensed under the MIT License (see LICENSE).
It is provided as-is, without warranty of any kind.
