summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-03-04 18:36:18 +0700
committerhathach <[email protected]>2021-03-04 18:36:18 +0700
commit8cabbb28df17bfcb7c549a98aec4eef4e70bba12 (patch)
tree867506d57d2eea1892f7e27c834f9005bc635c7c
parent4c31a29ff05a9f08afb6932eb3089bb154d59106 (diff)
fix enum walkaround forever check for SE0 when pull up is disabled
-rw-r--r--hw/bsp/rp2040/family.c4
-rw-r--r--hw/bsp/rp2040/family.mk1
-rw-r--r--src/portable/raspberrypi/rp2040/dcd_rp2040.c43
-rw-r--r--src/portable/raspberrypi/rp2040/rp2040_usb.c5
4 files changed, 37 insertions, 16 deletions
diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c
index ec4088ea1..9995c23d7 100644
--- a/hw/bsp/rp2040/family.c
+++ b/hw/bsp/rp2040/family.c
@@ -80,8 +80,8 @@ bool __no_inline_not_in_flash_func(get_bootsel_button)() {
#if defined(LOGGER_RTT)
// Logging with RTT
-// If RTT Control Block is not found by 'Auto Detection`
-// try to use 'Search Range` with '0x20000000 0x10000'
+// - If RTT Control Block is not found by 'Auto Detection` try to use 'Search Range` with '0x20000000 0x10000'
+// - SWD speed is rather slow around 1000Khz
#include "pico/stdio/driver.h"
#include "SEGGER_RTT.h"
diff --git a/hw/bsp/rp2040/family.mk b/hw/bsp/rp2040/family.mk
index 9aacae37d..b0fb58ff7 100644
--- a/hw/bsp/rp2040/family.mk
+++ b/hw/bsp/rp2040/family.mk
@@ -1,3 +1,4 @@
FAMILY_SUBMODULES = hw/mcu/raspberrypi/pico-sdk
JLINK_DEVICE = rp2040_m0_0
+PYOCD_TARGET = rp2040
diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c
index ba708081c..f844a0c65 100644
--- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c
+++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c
@@ -312,18 +312,7 @@ static void dcd_rp2040_irq(void)
hw_handle_buff_status();
}
- if (status & USB_INTS_BUS_RESET_BITS)
- {
- pico_trace("BUS RESET (addr %d -> %d)\n", assigned_address, 0);
- usb_hw->dev_addr_ctrl = 0;
- handled |= USB_INTS_BUS_RESET_BITS;
- dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
- usb_hw_clear->sie_status = USB_SIE_STATUS_BUS_RESET_BITS;
-#if TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX
- rp2040_usb_device_enumeration_fix();
-#endif
- }
-
+ // SE0 for 2 us or more, usually together with Bus Reset
if (status & USB_INTS_DEV_CONN_DIS_BITS)
{
handled |= USB_INTS_DEV_CONN_DIS_BITS;
@@ -340,7 +329,35 @@ static void dcd_rp2040_irq(void)
usb_hw_clear->sie_status = USB_SIE_STATUS_CONNECTED_BITS;
}
-#if 0 // TODO Enable SUSPEND & RESUME interrupt and test later on with/without VBUS detection
+ // SE0 for 2.5 us or more
+ if (status & USB_INTS_BUS_RESET_BITS)
+ {
+ pico_trace("BUS RESET\n");
+ usb_hw->dev_addr_ctrl = 0;
+ handled |= USB_INTS_BUS_RESET_BITS;
+ dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
+ usb_hw_clear->sie_status = USB_SIE_STATUS_BUS_RESET_BITS;
+
+#if TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX
+ // Only run enumeration walk-around if pull up is enabled
+ if ( usb_hw->sie_ctrl & USB_SIE_CTRL_PULLUP_EN_BITS )
+ {
+ rp2040_usb_device_enumeration_fix();
+ }
+#endif
+ }
+
+#if 0
+ // TODO Enable SUSPEND & RESUME interrupt and test later on with/without VBUS detection
+
+ /* Note from pico datasheet 4.1.2.6.4 (v1.2)
+ * If you enable the suspend interrupt, it is likely you will see a suspend interrupt when
+ * the device is first connected but the bus is idle. The bus can be idle for a few ms before
+ * the host begins sending start of frame packets. You will also see a suspend interrupt
+ * when the device is disconnected if you do not have a VBUS detect circuit connected. This is
+ * because without VBUS detection, it is impossible to tell the difference between
+ * being disconnected and suspended.
+ */
if (status & USB_INTS_DEV_SUSPEND_BITS)
{
handled |= USB_INTS_DEV_SUSPEND_BITS;
diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c
index c6f6d7231..98ffea9a3 100644
--- a/src/portable/raspberrypi/rp2040/rp2040_usb.c
+++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c
@@ -60,8 +60,11 @@ void rp2040_usb_init(void)
memset(usb_hw, 0, sizeof(*usb_hw));
memset(usb_dpram, 0, sizeof(*usb_dpram));
- // Mux to phy
+ // Mux the controller to the onboard usb phy
usb_hw->muxing = USB_USB_MUXING_TO_PHY_BITS | USB_USB_MUXING_SOFTCON_BITS;
+
+ // Force VBUS detect so the device thinks it is plugged into a host
+ // TODO support VBUs detect
usb_hw->pwr = USB_USB_PWR_VBUS_DETECT_BITS | USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN_BITS;
}