Newer
Older
m5scp2_exp / 54_write_sample.sh
#!/bin/bash

source ./lib.sh

# Get esptool command
BUILD_TOOL=$(lib_get_esptool_command)
# BUILD_TOOLの文字列の長さが20以上の場合は、終了する
if [ ${#BUILD_TOOL} -ge 20 ]; then
    echo $BUILD_TOOL
    echo "==="
    echo "Please execute the script again."
    echo "(上記のメッセージを確認したあと) もう一度実行してください。"
    echo "==="
    exit 1
fi

# Find port - Cross-platform detection
PORT=$(lib_detect_esptool_port)

# Check if PORT is set, otherwise prompt user
if [ -z "$PORT" ]; then
    lib_no_esp_device_message_and_exit
fi

echo "Using port: $PORT"

# Define the paths to the firmware files
BUILD_PATH="Sample/build/esp32.esp32.m5stack_stickc_plus2"
BOOTLOADER_PATH="$BUILD_PATH/Sample.ino.bootloader.bin"
PARTITIONS_PATH="$BUILD_PATH/Sample.ino.partitions.bin"
FIRMWARE_PATH="$BUILD_PATH/Sample.ino.bin"

# Check if all required files exist
if [ ! -f "$BOOTLOADER_PATH" ]; then
    echo "Bootloader file not found at $BOOTLOADER_PATH"
    exit 1
fi
if [ ! -f "$PARTITIONS_PATH" ]; then
    echo "Partitions file not found at $PARTITIONS_PATH"
    exit 1
fi
if [ ! -f "$FIRMWARE_PATH" ]; then
    echo "Firmware file not found at $FIRMWARE_PATH"
    exit 1
fi

echo "Flashing complete Sample firmware..."
echo "Bootloader: $BOOTLOADER_PATH"
echo "Partitions: $PARTITIONS_PATH"
echo "Main firmware: $FIRMWARE_PATH"

# Upload the complete firmware using esptool.py
$BUILD_TOOL --chip esp32 --port "$PORT" --baud 460800 write-flash -z \
    0x1000 "$BOOTLOADER_PATH" \
    0x8000 "$PARTITIONS_PATH" \
    0x10000 "$FIRMWARE_PATH"
 
echo "Flashing completed."

# Open serial monitor
read -p "シリアルモニタを開きますか?(y/n): " yn
if [ $yn = "y" ]; then
    echo "終了するときはCtrl+Cを押してください。"
    arduino-cli monitor -p "$PORT" --config 115200
fi