75 lines
2.0 KiB
Bash
Executable File
75 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
PORT="${PORT:-/dev/cu.usbmodem101}"
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
FIRMWARE="$ROOT/firmware/adafruit-circuitpython-espressif_esp32s3_devkitc_1_n8r8-en_US-10.2.1.bin"
|
|
CIRCUITPY_MOUNT="${CIRCUITPY_MOUNT:-}"
|
|
|
|
if [[ ! -f "$FIRMWARE" ]]; then
|
|
echo "Firmware not found: $FIRMWARE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -r "$PORT" || ! -w "$PORT" ]]; then
|
|
cat >&2 <<EOF
|
|
Cannot access $PORT as $(id -un).
|
|
|
|
Temporary fix from a local terminal:
|
|
sudo chmod 666 $PORT
|
|
|
|
Permanent fix:
|
|
sudo usermod -aG dialout $(id -un)
|
|
# then log out/in, or start a new shell with: newgrp dialout
|
|
EOF
|
|
exit 2
|
|
fi
|
|
|
|
echo "==> Probing ESP32-S3 on $PORT"
|
|
python3 -m esptool --chip esp32s3 --port "$PORT" flash_id
|
|
|
|
echo "==> Erasing flash"
|
|
python3 -m esptool --chip esp32s3 --port "$PORT" erase_flash
|
|
|
|
echo "==> Flashing CircuitPython N8R8 firmware"
|
|
python3 -m esptool --chip esp32s3 --port "$PORT" --baud 460800 write_flash -z 0x0 "$FIRMWARE"
|
|
|
|
echo "==> Waiting for CIRCUITPY mount"
|
|
for _ in $(seq 1 60); do
|
|
if [[ -n "$CIRCUITPY_MOUNT" && -d "$CIRCUITPY_MOUNT" ]]; then
|
|
break
|
|
fi
|
|
for candidate in \
|
|
"/media/$USER/CIRCUITPY" \
|
|
"/run/media/$USER/CIRCUITPY" \
|
|
"/media/$(id -un)/CIRCUITPY" \
|
|
"/Volumes/CIRCUITPY"; do
|
|
if [[ -d "$candidate" ]]; then
|
|
CIRCUITPY_MOUNT="$candidate"
|
|
break 2
|
|
fi
|
|
done
|
|
sleep 1
|
|
done
|
|
|
|
if [[ -z "$CIRCUITPY_MOUNT" || ! -d "$CIRCUITPY_MOUNT" ]]; then
|
|
cat >&2 <<EOF
|
|
Flashing finished, but CIRCUITPY did not auto-mount.
|
|
Reset the board once, then rerun just deployment with:
|
|
CIRCUITPY_MOUNT=/path/to/CIRCUITPY bash circuitpython/deploy_only.sh
|
|
EOF
|
|
exit 3
|
|
fi
|
|
|
|
echo "==> Deploying prototype to $CIRCUITPY_MOUNT"
|
|
mkdir -p "$CIRCUITPY_MOUNT/lib"
|
|
cp "$ROOT/circuitpython/code.py" "$CIRCUITPY_MOUNT/code.py"
|
|
cp "$ROOT/circuitpython/lib/"*.py "$CIRCUITPY_MOUNT/lib/"
|
|
cp "$ROOT/circuitpython/lib/"*.mpy "$CIRCUITPY_MOUNT/lib/"
|
|
sync
|
|
|
|
echo "==> Deployed. Files on CIRCUITPY:"
|
|
find "$CIRCUITPY_MOUNT" -maxdepth 2 -type f | sort
|
|
|
|
echo "==> Done. Reset the board if it does not reload automatically."
|