aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-06-18 09:29:09 +0200
committerRon Evans <[email protected]>2021-06-18 13:00:00 +0200
commitcd628bcde6d86cac40be31993bac4338120d75ff (patch)
tree657c580c28f6460946b92205369de5be071e2d0e
parentd1f445735cae8f8e118b5deec577734139464716 (diff)
downloadtinygo-cd628bcde6d86cac40be31993bac4338120d75ff.tar.gz
tinygo-cd628bcde6d86cac40be31993bac4338120d75ff.zip
nrf52840: add support for flashing with the BOSSA tool
This only works with a custom bossac build from Arduino, not with the upstream version. It avoids needing the manual "double tap" to enter bootloader mode before flashing firmware.
-rw-r--r--src/machine/machine_nrf52840_usb_reset_bossa.go26
-rw-r--r--src/machine/machine_nrf52840_usb_reset_none.go2
-rw-r--r--targets/nano-33-ble.json2
3 files changed, 28 insertions, 2 deletions
diff --git a/src/machine/machine_nrf52840_usb_reset_bossa.go b/src/machine/machine_nrf52840_usb_reset_bossa.go
new file mode 100644
index 000000000..42c6ad000
--- /dev/null
+++ b/src/machine/machine_nrf52840_usb_reset_bossa.go
@@ -0,0 +1,26 @@
+// +build nrf52840,nrf52840_reset_bossa
+
+package machine
+
+import (
+ "device/arm"
+ "device/nrf"
+)
+
+const DFU_MAGIC_SERIAL_ONLY_RESET = 0xb0
+
+// checkShouldReset is called by the USB-CDC implementation to check whether to
+// reset into the bootloader/OTA and if so, resets the chip appropriately.
+func checkShouldReset() {
+ if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 {
+ EnterSerialBootloader()
+ }
+}
+
+// EnterSerialBootloader resets the chip into the serial bootloader. After
+// reset, it can be flashed using serial/nrfutil.
+func EnterSerialBootloader() {
+ arm.DisableInterrupts()
+ nrf.POWER.GPREGRET.Set(DFU_MAGIC_SERIAL_ONLY_RESET)
+ arm.SystemReset()
+}
diff --git a/src/machine/machine_nrf52840_usb_reset_none.go b/src/machine/machine_nrf52840_usb_reset_none.go
index 08c615eb7..796a021e7 100644
--- a/src/machine/machine_nrf52840_usb_reset_none.go
+++ b/src/machine/machine_nrf52840_usb_reset_none.go
@@ -1,4 +1,4 @@
-// +build nrf52840,!nrf52840_reset_uf2
+// +build nrf52840,!nrf52840_reset_uf2,!nrf52840_reset_bossa
package machine
diff --git a/targets/nano-33-ble.json b/targets/nano-33-ble.json
index 53b4fcac7..df22221fd 100644
--- a/targets/nano-33-ble.json
+++ b/targets/nano-33-ble.json
@@ -1,6 +1,6 @@
{
"inherits": ["nrf52840"],
- "build-tags": ["nano_33_ble"],
+ "build-tags": ["nano_33_ble", "nrf52840_reset_bossa"],
"flash-command": "bossac_arduino2 -d -i -e -w -v -R --port={port} {bin}",
"flash-1200-bps-reset": "true",
"linkerscript": "targets/nano-33-ble.ld"