Skip to content

Commit 2b2ae66

Browse files
committed
pbio/drv/usb_ev3: fix USB not working after firmware update
Fix the USB being in a bad state after a firmware update. The firmware updater uses the USB to transfer the new firmware and then jumps to the new firmware without resetting the USB controller. Calling USBReset() was not enough to reset the USB controller. Even after this we would never get any interrupts, so requests from a host would time out. This is fixed by using the PSC to reset the USB controller instead of USBReset(). Also, before we reset things, we need to tell the host to disconnect from the firmware update USB device. When we reconfigure things the EV3 will appear as a completely different USB device. Fixes: pybricks/support#2295
1 parent 43f7da7 commit 2b2ae66

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

lib/pbio/drv/usb/usb_ev3.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,14 +813,17 @@ static pbio_error_t pbdrv_usb_ev3_process_thread(pbio_os_state_t *state, void *c
813813
}
814814

815815
void pbdrv_usb_init(void) {
816+
// If we came straight from a firmware update, we need to send a disconnect
817+
// to the host, then reset the USB controller.
818+
USBDevDisconnect(USB0_BASE);
819+
820+
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_USB0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_SWRSTDISABLE);
821+
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_USB0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
822+
816823
// This reset sequence is from Example 34-1 in the AM1808 TRM (spruh82c.pdf)
817824
// Because PHYs and clocking are... as they tend to be, use the precise sequence
818825
// of operations specified.
819826

820-
// Power on and reset the controller
821-
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_USB0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
822-
USBReset(USB_0_OTGBASE);
823-
824827
// Reset the PHY
825828
HWREG(CFGCHIP2_USBPHYCTRL) |= CFGCHIP2_RESET;
826829
for (int i = 0; i < 50; i++) {

0 commit comments

Comments
 (0)