From 13f8de9766b26e8473a37eb4a9b9aace58cf0972 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Fri, 25 Jul 2025 20:59:31 -0500 Subject: [PATCH 1/3] pbio/version: bump to v4.0.0-alpha.0 We plan on calling the next release v4. The main purpose of changing this now is so that the WebUSB BOS descriptors will point to labs.pybricks.com instead of code.pybricks.com. Also fix missing include in usb_common_desc.c to make this actually take effect. --- lib/pbio/drv/usb/usb_common_desc.c | 2 ++ lib/pbio/include/pbio/version.h | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pbio/drv/usb/usb_common_desc.c b/lib/pbio/drv/usb/usb_common_desc.c index bacbe97d2..edc3e2802 100644 --- a/lib/pbio/drv/usb/usb_common_desc.c +++ b/lib/pbio/drv/usb/usb_common_desc.c @@ -8,6 +8,8 @@ #if PBDRV_CONFIG_USB +#include + #include "usb_common_desc.h" #if PBIO_VERSION_LEVEL_HEX == 0xA diff --git a/lib/pbio/include/pbio/version.h b/lib/pbio/include/pbio/version.h index cab93be40..5cc8a1d11 100644 --- a/lib/pbio/include/pbio/version.h +++ b/lib/pbio/include/pbio/version.h @@ -14,16 +14,16 @@ #include /** The current major version. */ -#define PBIO_VERSION_MAJOR 3 +#define PBIO_VERSION_MAJOR 4 /** The current minor version. */ -#define PBIO_VERSION_MINOR 6 +#define PBIO_VERSION_MINOR 0 /** The current patch version. */ -#define PBIO_VERSION_MICRO 1 +#define PBIO_VERSION_MICRO 0 /** The current prerelease level as a hex digit. */ -#define PBIO_VERSION_LEVEL_HEX 0xF +#define PBIO_VERSION_LEVEL_HEX 0xA /** The current prerelease serial. */ #define PBIO_VERSION_SERIAL 0 From ffcf6d0acbe8aa71f7954d7f943b2a4677549eb5 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 26 Jul 2025 11:08:56 -0500 Subject: [PATCH 2/3] pbio/drv/usb_ev3: use correct register for reset Use the correct register when calling USBReset(). Also replace some hard-coded values with macros in the related TI library. --- lib/pbio/drv/usb/usb_ev3.c | 2 +- lib/tiam1808/drivers/usb.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/pbio/drv/usb/usb_ev3.c b/lib/pbio/drv/usb/usb_ev3.c index 27d7926ff..ba97555b8 100644 --- a/lib/pbio/drv/usb/usb_ev3.c +++ b/lib/pbio/drv/usb/usb_ev3.c @@ -819,7 +819,7 @@ void pbdrv_usb_init(void) { // Power on and reset the controller PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_USB0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE); - USBReset(USB0_BASE); + USBReset(USB_0_OTGBASE); // Reset the PHY HWREG(CFGCHIP2_USBPHYCTRL) |= CFGCHIP2_RESET; diff --git a/lib/tiam1808/drivers/usb.c b/lib/tiam1808/drivers/usb.c index bca3c3a24..aa94a9fcd 100644 --- a/lib/tiam1808/drivers/usb.c +++ b/lib/tiam1808/drivers/usb.c @@ -3151,7 +3151,7 @@ void USBEnableOtgIntr(unsigned int ulBase) unsigned int reg; reg = HWREG(ulBase + USB_0_CTRL); - reg &= 0xFFFFFFF7; + reg &= ~USBOTG_CTRL_UINT; HWREG(ulBase + USB_0_CTRL) = reg; /* This API enables the USB Interrupts through subsystem specific wrapper @@ -3171,14 +3171,13 @@ void USBReset(unsigned int ulBase) unsigned int reg; reg = HWREG(ulBase + USB_0_CTRL); - reg |= 1; + reg |= USBOTG_CTRL_RESET; /* Set the Reset Bit */ HWREG(ulBase + USB_0_CTRL) = reg; /* Wait till Reset bit is cleared */ - while(((HWREG(ulBase + USB_0_CTRL)) & 0x1 )== 1); - + while(((HWREG(ulBase + USB_0_CTRL)) & USBOTG_CTRL_RESET) == USBOTG_CTRL_RESET); } void USBClearOtgIntr(unsigned int ulBase) From 5f7f3a4b8da190fded49922a7a465022e0d0e3f8 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 26 Jul 2025 11:10:38 -0500 Subject: [PATCH 3/3] 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: https://github.com/pybricks/support/issues/2295 --- lib/pbio/drv/usb/usb_ev3.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/pbio/drv/usb/usb_ev3.c b/lib/pbio/drv/usb/usb_ev3.c index ba97555b8..d92df8c9d 100644 --- a/lib/pbio/drv/usb/usb_ev3.c +++ b/lib/pbio/drv/usb/usb_ev3.c @@ -813,14 +813,17 @@ static pbio_error_t pbdrv_usb_ev3_process_thread(pbio_os_state_t *state, void *c } void pbdrv_usb_init(void) { + // If we came straight from a firmware update, we need to send a disconnect + // to the host, then reset the USB controller. + USBDevDisconnect(USB0_BASE); + + PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_USB0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_SWRSTDISABLE); + PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_USB0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE); + // This reset sequence is from Example 34-1 in the AM1808 TRM (spruh82c.pdf) // Because PHYs and clocking are... as they tend to be, use the precise sequence // of operations specified. - // Power on and reset the controller - PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_USB0, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE); - USBReset(USB_0_OTGBASE); - // Reset the PHY HWREG(CFGCHIP2_USBPHYCTRL) |= CFGCHIP2_RESET; for (int i = 0; i < 50; i++) {