mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 22:13:39 +00:00
samd21,samd51,nrf52840: unify bootloader entry process
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
//go:build nrf52840
|
||||
// +build nrf52840
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/arm"
|
||||
"device/nrf"
|
||||
)
|
||||
|
||||
const (
|
||||
DFU_MAGIC_SERIAL_ONLY_RESET = 0x4e
|
||||
DFU_MAGIC_UF2_RESET = 0x57
|
||||
DFU_MAGIC_OTA_RESET = 0xA8
|
||||
)
|
||||
|
||||
// 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()
|
||||
}
|
||||
|
||||
// EnterUF2Bootloader resets the chip into the UF2 bootloader. After reset, it
|
||||
// can be flashed via nrfutil or by copying a UF2 file to the mass storage device
|
||||
func EnterUF2Bootloader() {
|
||||
arm.DisableInterrupts()
|
||||
nrf.POWER.GPREGRET.Set(DFU_MAGIC_UF2_RESET)
|
||||
arm.SystemReset()
|
||||
}
|
||||
|
||||
// EnterOTABootloader resets the chip into the bootloader so that it can be
|
||||
// flashed via an OTA update
|
||||
func EnterOTABootloader() {
|
||||
arm.DisableInterrupts()
|
||||
nrf.POWER.GPREGRET.Set(DFU_MAGIC_OTA_RESET)
|
||||
arm.SystemReset()
|
||||
}
|
||||
Reference in New Issue
Block a user