This is an update to the thread viewtopic.php?t=369119 but it's locked.
I was able to solve the issue of detecting when a USB host is connected using this code for the RP2040. I believe this is the simplest version possible:
But it did not work for RP2350. For RP2350 I had to also force the USB in device mode:
My custom board cannot distinguish if the power comes from USB VBUS or directly from the +5V in the board, so I think there is no other alternative.
I was able to solve the issue of detecting when a USB host is connected using this code for the RP2040. I believe this is the simplest version possible:
Code:
usb_hw->phy_direct_override = USB_USBPHY_DIRECT_OVERRIDE_DP_PULLUP_EN_OVERRIDE_EN_BITS;usb_hw->phy_direct = USB_USBPHY_DIRECT_DP_PULLUP_EN_BITS;while (true){ if ((usb_hw->phy_direct & USB_USBPHY_DIRECT_RX_DP_BITS) != USB_USBPHY_DIRECT_RX_DP_BITS) { printf("Do my stuff when USB connected\n"); }}Code:
// Enable the USB controller in device mode.// This was not necessary in the RP2040, but it is in the RP2350Ausb_hw->main_ctrl = USB_MAIN_CTRL_CONTROLLER_EN_BITS;Statistics: Posted by logronoide — Fri Mar 14, 2025 11:39 am