-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash.sh
More file actions
executable file
·30 lines (26 loc) · 1.27 KB
/
Copy pathflash.sh
File metadata and controls
executable file
·30 lines (26 loc) · 1.27 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
#!/usr/bin/env bash
#
# Flash the micro:bit v2 (nRF52833) with the SoftDevice + this app via pyOCD.
#
# The nRF52833 ships with "hardened" APPROTECT: a normal flash-algo erase fails
# at address 0x0 (result code 0x67). A CTRL-AP **mass erase** recovers/unlocks
# the chip, and must happen in the same session right before programming.
#
# ./flash.sh # uses pyocd on PATH
# PYOCD=/path/to/pyocd ./flash.sh
#
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
SDK_DIR="${HERE}/sdk/nRF5_SDK_17.1.0_ddde560"
APP="${SDK_DIR}/examples/ble_peripheral/ble_app_hids_keyboard/pca10100/s140/armgcc/_build/nrf52833_xxaa.hex"
S140="${SDK_DIR}/components/softdevice/s140/hex/s140_nrf52_7.2.0_softdevice.hex"
PYOCD="${PYOCD:-pyocd}"
[ -f "${APP}" ] || { echo "App hex not found: ${APP}"; echo "Build it first (see README)."; exit 1; }
echo ">> Mass erase (CTRL-AP recover; needed for hardened APPROTECT) ..."
timeout 90 "${PYOCD}" erase -t nrf52833 --mass
echo ">> Flashing SoftDevice + app ..."
timeout 120 "${PYOCD}" flash -t nrf52833 "${S140}" "${APP}"
echo ">> Reset ..."
timeout 30 "${PYOCD}" reset -t nrf52833
echo ">> Done. The micro:bit should show a blinking ring and advertise as 'microbit kbd'."
echo " (If pyocd hangs over USB/WSL: unplug & replug the board, then re-run.)"