-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash.sh
More file actions
executable file
·64 lines (54 loc) · 1.64 KB
/
flash.sh
File metadata and controls
executable file
·64 lines (54 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
set -e
FQBN="esp32:esp32:XIAO_ESP32S3:PSRAM=opi"
SKETCH="src/streamer"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
echo "=== Flash XIAO ESP32S3 ==="
echo ""
if ! command -v arduino-cli &>/dev/null; then
echo "arduino-cli not found. Run ./setup.sh first."
exit 1
fi
# Collect serial ports (skip Bluetooth and header line)
PORTS=()
while IFS= read -r line; do
PORTS+=("$line")
done < <(arduino-cli board list 2>/dev/null | tail -n +2 | grep -v "serial://.*Bluetooth" | grep -v "^$")
if [ ${#PORTS[@]} -eq 0 ]; then
echo "No serial ports detected."
echo ""
echo "Troubleshooting:"
echo " 1. Plug in the XIAO ESP32S3 via USB-C"
echo " 2. If it still doesn't show, hold BOOT while plugging in"
echo " 3. Re-run this script"
exit 1
fi
echo "Detected ports:"
echo ""
for i in "${!PORTS[@]}"; do
echo " $((i+1))) ${PORTS[$i]}"
done
echo ""
if [ ${#PORTS[@]} -eq 1 ]; then
PORT=$(echo "${PORTS[0]}" | awk '{print $1}')
echo "Only one port found, using: $PORT"
else
read -rp "Select port [1-${#PORTS[@]}]: " choice
if [[ ! "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt ${#PORTS[@]} ]; then
echo "Invalid selection."
exit 1
fi
PORT=$(echo "${PORTS[$((choice-1))]}" | awk '{print $1}')
fi
echo ""
echo "Uploading to $PORT..."
echo ""
arduino-cli upload --fqbn "$FQBN" --port "$PORT" "$SCRIPT_DIR/$SKETCH"
echo ""
echo "Flash complete."
echo ""
read -rp "Open serial monitor? [Y/n]: " monitor
if [[ ! "$monitor" =~ ^[nN] ]]; then
echo "Opening monitor at 115200 baud (Ctrl+C to exit)..."
arduino-cli monitor --port "$PORT" --config baudrate=115200
fi