#!/bin/bash # Build and Flash Script for ESP32-C5 Toolkit set -e echo "========================================" echo "ESP32-C5 Toolkit - Build and Flash" echo "========================================" echo "" # Check if IDF_PATH is set if [ -z "$IDF_PATH" ]; then echo "❌ ERROR: ESP-IDF environment not set!" echo "" echo "Please source ESP-IDF first:" echo " source \$IDF_PATH/export.sh" echo "" echo "Or if ESP-IDF is installed elsewhere:" echo " source ~/esp/esp-idf/export.sh" echo "" exit 1 fi echo "✓ ESP-IDF found at: $IDF_PATH" echo "" # Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "$SCRIPT_DIR" # Set target (ESP32-C5) echo "Setting target to ESP32-C5..." idf.py --preview set-target esp32c5 echo "" echo "Building firmware..." idf.py build if [ $? -eq 0 ]; then echo "" echo "✓ Build successful!" echo "" # Check if port is provided as argument if [ -n "$1" ]; then PORT="$1" echo "Flashing to port: $PORT" echo "" idf.py -p "$PORT" flash monitor else echo "To flash and monitor, run:" echo " idf.py -p [PORT] flash monitor" echo "" echo "Example:" echo " idf.py -p /dev/cu.usbserial-* flash monitor" echo "" echo "Or use this script with port:" echo " ./build_and_flash.sh /dev/cu.usbserial-*" fi else echo "" echo "❌ Build failed!" exit 1 fi