#!/bin/bash # Build and Flash Script for Pico RP2350 # This script compiles the project and flashes it to the board set -e # Exit on error PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BUILD_DIR="${PROJECT_DIR}/build" UF2_FILE="${BUILD_DIR}/basic1.uf2" echo "==========================================" echo " Pico RP2350 Build and Flash Script" echo "==========================================" echo "" # Step 1: Build the project echo "Step 1: Building project..." cd "${BUILD_DIR}" make -j4 if [ $? -ne 0 ]; then echo "❌ Build failed!" exit 1 fi echo "✓ Build successful!" echo "" # Check if UF2 file was created if [ ! -f "${UF2_FILE}" ]; then echo "❌ Error: ${UF2_FILE} not found!" exit 1 fi echo "UF2 file created: ${UF2_FILE}" echo "" # Step 2: Flash to board echo "Step 2: Flashing to board..." echo "" echo "Choose flashing method:" echo " 1) Use picotool (board must be connected and in BOOTSEL mode)" echo " 2) Manual copy (mount board as USB drive and copy UF2)" echo "" read -p "Enter choice (1 or 2): " choice case $choice in 1) echo "" echo "Using picotool to flash..." echo "Make sure your board is connected and in BOOTSEL mode" echo "(Hold BOOTSEL button while plugging in USB)" echo "" read -p "Press Enter when ready..." PICOTOOL="${HOME}/.pico-sdk/picotool/2.2.0-a4/picotool/picotool" if [ ! -f "${PICOTOOL}" ]; then echo "❌ picotool not found at: ${PICOTOOL}" exit 1 fi # Try to load the UF2 "${PICOTOOL}" load "${UF2_FILE}" -fx if [ $? -eq 0 ]; then echo "" echo "✓ Successfully flashed to board!" echo "✓ Board will automatically reboot and run the program" else echo "" echo "❌ Flash failed! Make sure:" echo " - Board is in BOOTSEL mode (hold BOOTSEL while plugging in)" echo " - USB cable is connected" echo " - You have permission to access USB devices" fi ;; 2) echo "" echo "Manual copy instructions:" echo "1. Hold BOOTSEL button on your board" echo "2. Plug in USB cable (or press RESET while holding BOOTSEL)" echo "3. Board should appear as USB drive (RPI-RP2)" echo "4. Copy this file to the drive:" echo " ${UF2_FILE}" echo "5. Board will automatically reboot when copy completes" echo "" # Try to detect if RPI-RP2 drive is mounted if [ -d "/Volumes/RPI-RP2" ]; then echo "✓ Detected RPI-RP2 drive at /Volumes/RPI-RP2" read -p "Copy UF2 file now? (y/n): " copy_now if [ "$copy_now" = "y" ] || [ "$copy_now" = "Y" ]; then cp "${UF2_FILE}" /Volumes/RPI-RP2/ echo "✓ File copied! Board will reboot automatically..." fi else echo "⚠ RPI-RP2 drive not detected" echo "Please manually copy the UF2 file when the drive appears" fi ;; *) echo "Invalid choice" exit 1 ;; esac echo "" echo "==========================================" echo "Done!" echo "=========================================="