samd21,samd51,nrf52840: unify bootloader entry process

Этот коммит содержится в:
sago35 2022-07-05 22:28:13 +09:00 коммит произвёл Ron Evans
родитель ff7c71c99c
коммит fcefcb191c
9 изменённых файлов: 60 добавлений и 69 удалений

Просмотреть файл

@ -1734,9 +1734,9 @@ func (tcc *TCC) Set(channel uint8, value uint32) {
}
}
// ResetProcessor should perform a system reset in preperation
// EnterBootloader should perform a system reset in preperation
// to switch to the bootloader to flash new firmware.
func ResetProcessor() {
func EnterBootloader() {
arm.DisableInterrupts()
// Perform magic reset into bootloader, as mentioned in

Просмотреть файл

@ -583,7 +583,7 @@ func cdcSetup(setup usbSetup) bool {
if setup.bRequest == usb_CDC_SET_LINE_CODING || setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE {
// auto-reset into the bootloader
if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 {
ResetProcessor()
EnterBootloader()
} else {
// TODO: cancel any reset
}

Просмотреть файл

@ -1974,9 +1974,9 @@ func (tcc *TCC) Set(channel uint8, value uint32) {
}
}
// ResetProcessor should perform a system reset in preparation
// EnterBootloader should perform a system reset in preparation
// to switch to the bootloader to flash new firmware.
func ResetProcessor() {
func EnterBootloader() {
arm.DisableInterrupts()
// Perform magic reset into bootloader, as mentioned in

Просмотреть файл

@ -586,7 +586,7 @@ func cdcSetup(setup usbSetup) bool {
if setup.bRequest == usb_CDC_SET_LINE_CODING || setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE {
// auto-reset into the bootloader
if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 {
ResetProcessor()
EnterBootloader()
} else {
// TODO: cancel any reset
}

Просмотреть файл

@ -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()
}

Просмотреть файл

@ -320,7 +320,9 @@ func (usbcdc *USBCDC) handleInterrupt(interrupt.Interrupt) {
count := int(nrf.USBD.SIZE.EPOUT[0].Get())
if count >= 7 {
parseUSBLineInfo(udd_ep_out_cache_buffer[0][:count])
checkShouldReset()
if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 {
EnterBootloader()
}
}
nrf.USBD.TASKS_EP0STATUS.Set(1)
}
@ -484,7 +486,9 @@ func cdcSetup(setup usbSetup) bool {
if setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE {
usbLineInfo.lineState = setup.wValueL
checkShouldReset()
if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 {
EnterBootloader()
}
nrf.USBD.TASKS_EP0STATUS.Set(1)
}

Просмотреть файл

@ -3,25 +3,8 @@
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
// EnterBootloader 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()
func EnterBootloader() {
EnterSerialBootloader()
}

Просмотреть файл

@ -3,5 +3,7 @@
package machine
func checkShouldReset() {
// EnterBootloader resets the chip into the serial bootloader.
func EnterBootloader() {
// skip
}

Просмотреть файл

@ -3,45 +3,8 @@
package machine
import (
"device/arm"
"device/nrf"
)
const (
DFU_MAGIC_SERIAL_ONLY_RESET = 0x4e
DFU_MAGIC_UF2_RESET = 0x57
DFU_MAGIC_OTA_RESET = 0xA8
)
// 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 {
EnterUF2Bootloader()
}
}
// 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
// EnterBootloader 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()
func EnterBootloader() {
EnterUF2Bootloader()
}