github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/machine_nrf52840_enter_bootloader.go (about)

     1  //go:build nrf52840
     2  
     3  package machine
     4  
     5  import (
     6  	"device/arm"
     7  	"device/nrf"
     8  )
     9  
    10  const (
    11  	dfuMagicSerialOnlyReset = 0x4e
    12  	dfuMagicUF2Reset        = 0x57
    13  	dfuMagicOTAReset        = 0xA8
    14  )
    15  
    16  // EnterSerialBootloader resets the chip into the serial bootloader. After
    17  // reset, it can be flashed using serial/nrfutil.
    18  func EnterSerialBootloader() {
    19  	arm.DisableInterrupts()
    20  	nrf.POWER.GPREGRET.Set(dfuMagicSerialOnlyReset)
    21  	arm.SystemReset()
    22  }
    23  
    24  // EnterUF2Bootloader resets the chip into the UF2 bootloader. After reset, it
    25  // can be flashed via nrfutil or by copying a UF2 file to the mass storage device
    26  func EnterUF2Bootloader() {
    27  	arm.DisableInterrupts()
    28  	nrf.POWER.GPREGRET.Set(dfuMagicUF2Reset)
    29  	arm.SystemReset()
    30  }
    31  
    32  // EnterOTABootloader resets the chip into the bootloader so that it can be
    33  // flashed via an OTA update
    34  func EnterOTABootloader() {
    35  	arm.DisableInterrupts()
    36  	nrf.POWER.GPREGRET.Set(dfuMagicOTAReset)
    37  	arm.SystemReset()
    38  }