samd21,samd51,nrf52840: unify bootloader entry process
Этот коммит содержится в:
		
							родитель
							
								
									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. | // to switch to the bootloader to flash new firmware. | ||||||
| func ResetProcessor() { | func EnterBootloader() { | ||||||
| 	arm.DisableInterrupts() | 	arm.DisableInterrupts() | ||||||
| 
 | 
 | ||||||
| 	// Perform magic reset into bootloader, as mentioned in | 	// 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 { | 		if setup.bRequest == usb_CDC_SET_LINE_CODING || setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { | ||||||
| 			// auto-reset into the bootloader | 			// auto-reset into the bootloader | ||||||
| 			if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 { | 			if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 { | ||||||
| 				ResetProcessor() | 				EnterBootloader() | ||||||
| 			} else { | 			} else { | ||||||
| 				// TODO: cancel any reset | 				// 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. | // to switch to the bootloader to flash new firmware. | ||||||
| func ResetProcessor() { | func EnterBootloader() { | ||||||
| 	arm.DisableInterrupts() | 	arm.DisableInterrupts() | ||||||
| 
 | 
 | ||||||
| 	// Perform magic reset into bootloader, as mentioned in | 	// 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 { | 		if setup.bRequest == usb_CDC_SET_LINE_CODING || setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { | ||||||
| 			// auto-reset into the bootloader | 			// auto-reset into the bootloader | ||||||
| 			if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 { | 			if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 { | ||||||
| 				ResetProcessor() | 				EnterBootloader() | ||||||
| 			} else { | 			} else { | ||||||
| 				// TODO: cancel any reset | 				// TODO: cancel any reset | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
							
								
								
									
										39
									
								
								src/machine/machine_nrf52840_enter_bootloader.go
									
										
									
									
									
										Обычный файл
									
								
							
							
						
						
									
										39
									
								
								src/machine/machine_nrf52840_enter_bootloader.go
									
										
									
									
									
										Обычный файл
									
								
							|  | @ -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()) | 				count := int(nrf.USBD.SIZE.EPOUT[0].Get()) | ||||||
| 				if count >= 7 { | 				if count >= 7 { | ||||||
| 					parseUSBLineInfo(udd_ep_out_cache_buffer[0][:count]) | 					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) | 				nrf.USBD.TASKS_EP0STATUS.Set(1) | ||||||
| 			} | 			} | ||||||
|  | @ -484,7 +486,9 @@ func cdcSetup(setup usbSetup) bool { | ||||||
| 
 | 
 | ||||||
| 		if setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { | 		if setup.bRequest == usb_CDC_SET_CONTROL_LINE_STATE { | ||||||
| 			usbLineInfo.lineState = setup.wValueL | 			usbLineInfo.lineState = setup.wValueL | ||||||
| 			checkShouldReset() | 			if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 { | ||||||
|  | 				EnterBootloader() | ||||||
|  | 			} | ||||||
| 			nrf.USBD.TASKS_EP0STATUS.Set(1) | 			nrf.USBD.TASKS_EP0STATUS.Set(1) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,25 +3,8 @@ | ||||||
| 
 | 
 | ||||||
| package machine | package machine | ||||||
| 
 | 
 | ||||||
| import ( | // EnterBootloader resets the chip into the serial bootloader. After | ||||||
| 	"device/arm" | // reset, it can be flashed using serial/nrfutil. | ||||||
| 	"device/nrf" | func EnterBootloader() { | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| 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() | ||||||
| } | } | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // 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() |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -3,5 +3,7 @@ | ||||||
| 
 | 
 | ||||||
| package machine | package machine | ||||||
| 
 | 
 | ||||||
| func checkShouldReset() { | // EnterBootloader resets the chip into the serial bootloader. | ||||||
|  | func EnterBootloader() { | ||||||
|  | 	// skip | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -3,45 +3,8 @@ | ||||||
| 
 | 
 | ||||||
| package machine | package machine | ||||||
| 
 | 
 | ||||||
| import ( | // EnterBootloader resets the chip into the UF2 bootloader. After reset, it | ||||||
| 	"device/arm" | // can be flashed via nrfutil or by copying a UF2 file to the mass storage device | ||||||
| 	"device/nrf" | func EnterBootloader() { | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| 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() | 	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 |  | ||||||
| // 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() |  | ||||||
| } |  | ||||||
|  |  | ||||||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 sago35
						sago35