From 655092d568720188a3a34b9376a7ebcf274dab79 Mon Sep 17 00:00:00 2001 From: Reimu NotMoe Date: Fri, 27 Dec 2024 04:17:26 +0800 Subject: [PATCH] dcd_pic: check USBBUSY bit on PIC32s --- src/portable/microchip/pic/dcd_pic.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/portable/microchip/pic/dcd_pic.c b/src/portable/microchip/pic/dcd_pic.c index a4fa0e840..b4a698199 100644 --- a/src/portable/microchip/pic/dcd_pic.c +++ b/src/portable/microchip/pic/dcd_pic.c @@ -492,6 +492,9 @@ bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { tu_memclr(&_dcd, sizeof(_dcd)); #if TU_PIC_INT_SIZE == 4 + // The USBBUSY bit is present on PIC32s and we're required to check it + // prior to powering on the USB peripheral (see DS61126F page 27) + while (U1PWRCbits.USBBUSY); U1PWRCSET = _U1PWRC_USBPWR_MASK; #else U1PWRCbits.USBPWR = 1;