pi_pico/flash.sh
Mohamed Salem 3687e48684 Add complete firmware stack with USB-CDC proof of life
Dockerized build system (Dockerfile, docker-compose, build.sh) with
Pico SDK cross-compilation. Modular CMake split into project_config,
mcu_config, and sources_config under cmake/. Component architecture
following inc/prg/cfg convention: STD_TYPES, MCU_USB, HAL_COM,
APP_CLSW, SYS_ECU. Full call chain SYS_ECU -> APP_CLSW -> HAL_COM
-> MCU_USB verified end-to-end on RP2040-Zero hardware over USB-CDC.
Includes flash.sh for automated .uf2 flashing on macOS and
devcontainer config for VS Code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 18:23:24 +02:00

46 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# flash.sh - Flash firmware to the Raspberry Pi Pico
# ============================================================================
# This script MUST run on the host macOS (not inside Docker) because it
# needs access to /Volumes/RPI-RP2, the USB mass storage mount point that
# appears when the Pico is held in BOOTSEL mode during power-on.
#
# Usage:
# 1. Hold BOOTSEL on the Pico and plug it into USB
# 2. Run: ./flash.sh
#
# Or chain with a build:
# docker compose run --rm pico-build bash build.sh && ./flash.sh
# ============================================================================
PICO_MOUNT="/Volumes/RPI-RP2"
UF2_FILE="build/Color_Switcher_PICO.uf2"
# Verify the firmware file exists before waiting for the Pico
if [ ! -f "$UF2_FILE" ]; then
echo "Error: $UF2_FILE not found. Run the build first:"
echo " docker compose run --rm pico-build bash build.sh"
exit 1
fi
# Wait for the Pico to appear in BOOTSEL mode
echo "Waiting for Pico in BOOTSEL mode ($PICO_MOUNT)..."
echo " -> Hold BOOTSEL and plug in the Pico via USB"
while [ ! -d "$PICO_MOUNT" ]; do
sleep 0.5
done
# Copy the firmware to the Pico's USB mass storage
echo "Pico detected. Copying $UF2_FILE..."
cp "$UF2_FILE" "$PICO_MOUNT/"
# Wait for the Pico to unmount (it reboots automatically after receiving the .uf2)
echo "Waiting for Pico to reboot..."
while [ -d "$PICO_MOUNT" ]; do
sleep 0.5
done
echo "Done! Pico rebooted with new firmware."
echo " -> Open a serial monitor: screen /dev/tty.usbmodem* 115200"