#!/bin/bash # erase_all.sh — Erase entire Flash on nRF52 via OpenOCD set -e # Exit on error # Default interface is swd0 INTERFACE="swd0" # Parse command line argument for SWD interface while getopts "i:" opt; do case "$opt" in i) if [[ "$OPTARG" == "swd0" || "$OPTARG" == "swd1" ]]; then INTERFACE="$OPTARG" else echo "Invalid interface: $OPTARG" echo "Usage: $0 [-i swd0|swd1]" exit 1 fi ;; *) echo "Usage: $0 [-i swd0|swd1]" exit 1 ;; esac done # Run OpenOCD command for full chip erase sudo openocd \ -f ./raspberrypi-${INTERFACE}.cfg \ -f target/nrf52.cfg \ -c "init" \ -c "nrf52_recover" \ -c "reset halt" \ -c "nrf5 mass_erase" \ -c "shutdown" echo "✅ Device erase complete."