#!/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"