summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Conrad <[email protected]>2020-04-08 11:51:33 -0400
committerNathan Conrad <[email protected]>2020-04-09 17:03:12 -0400
commit715c4dbbf8fe7c6bb83013df626a201928704b30 (patch)
treef2379e646562b08cbb099c36956a37594d424dfa
parentd6578823bb405cacbda13a044b66ba0a4f16a3d4 (diff)
stm32fsdev: Implement dcd_connect.
-rw-r--r--docs/porting.md6
-rw-r--r--src/device/dcd.h8
-rw-r--r--src/device/usbd.c1
-rw-r--r--src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c24
-rw-r--r--src/portable/template/dcd_template.c14
-rw-r--r--test/test/device/msc/test_msc_device.c1
-rw-r--r--test/test/device/usbd/test_usbd.c1
7 files changed, 45 insertions, 10 deletions
diff --git a/docs/porting.md b/docs/porting.md
index deb1b9efb..7d7d4cdb1 100644
--- a/docs/porting.md
+++ b/docs/porting.md
@@ -62,6 +62,8 @@ All of the code for the low-level device API is in `src/portable/<vendor>/<chip
##### dcd_init
Initializes the USB peripheral for device mode and enables it.
+If the MCU has an internal pull-up, this function should leave it disabled.
+
#### dcd_int_enable / dcd_int_disable
Enables or disables the USB device interrupt(s). May be used to prevent concurrency issues when mutating data structures shared between main code and the interrupt handler.
@@ -77,6 +79,10 @@ Called when the device received SET_CONFIG request, you can leave this empty if
##### dcd_remote_wakeup
Called to remote wake up host when suspended (e.g hid keyboard)
+##### dcd_connect / dcd_disconnect
+
+Connect or disconnect the data-line pull-up resistor. Define as a weak function if the MCU has an internal pull-up, otherwise do not define.
+
#### Special events
You must let TinyUSB know when certain events occur so that it can continue its work. There are a few methods you can call to queue events for TinyUSB to process.
diff --git a/src/device/dcd.h b/src/device/dcd.h
index 487ddb3b6..f6a8aebbf 100644
--- a/src/device/dcd.h
+++ b/src/device/dcd.h
@@ -106,11 +106,11 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num);
// Wake up host
void dcd_remote_wakeup(uint8_t rhport);
-// disconnect by disabling internal pull-up resistor on D+/D-
-void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK;
-
-// connect by enabling internal pull-up resistor on D+/D-
+// Connect or disconnect D+/D- line pull-up resistor.
+// Defined as weak in dcd source if MCU has internal pull-up.
+// Can be strongly defined in BSP.
void dcd_connect(uint8_t rhport) TU_ATTR_WEAK;
+void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK;
//--------------------------------------------------------------------+
// Endpoint API
diff --git a/src/device/usbd.c b/src/device/usbd.c
index ddd99d7f1..17a251a92 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -332,6 +332,7 @@ bool tud_init (void)
// Init device controller driver
dcd_init(TUD_OPT_RHPORT);
+ tud_connect();
dcd_int_enable(TUD_OPT_RHPORT);
return true;
diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
index f962a4bee..b893ec05a 100644
--- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
+++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
@@ -239,17 +239,29 @@ void dcd_init (uint8_t rhport)
}
USB->CNTR |= USB_CNTR_RESETM | USB_CNTR_SOFM | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
dcd_handle_bus_reset();
+
+ // Data-line pull-up is left disconnected.
+}
- // And finally enable pull-up, which may trigger the RESET IRQ if the host is connected.
- // (if this MCU has an internal pullup)
+// Define only on MCU with internal pull-up so BSP can override (needed on MCU without internal pull-up)
#if defined(USB_BCDR_DPPU)
- USB->BCDR |= USB_BCDR_DPPU;
-#else
- // FIXME: callback to the user to ask them to twiddle a GPIO to disable/enable D+???
-#endif
+TU_ATTR_WEAK
+void dcd_disconnect(uint8_t rhport)
+{
+ (void) rhport;
+ USB->BCDR &= ~(USB_BCDR_DPPU);
+}
+
+TU_ATTR_WEAK
+void dcd_connect(uint8_t rhport)
+{
+ (void) rhport;
+ USB->BCDR |= USB_BCDR_DPPU;
}
+#endif
+
// Enable device interrupt
void dcd_int_enable (uint8_t rhport)
{
diff --git a/src/portable/template/dcd_template.c b/src/portable/template/dcd_template.c
index 102910509..d29c98e55 100644
--- a/src/portable/template/dcd_template.c
+++ b/src/portable/template/dcd_template.c
@@ -45,6 +45,20 @@ void dcd_init (uint8_t rhport)
(void) rhport;
}
+#if HAS_INTERNAL_PULLUP
+// Enable internal D+/D- pullup
+void dcd_connect(uint8_t rhport) TU_ATTR_WEAK
+{
+ (void) rhport;
+}
+
+// Disable internal D+/D- pullup
+void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK
+{
+ (void) rhport;
+}
+#endif
+
// Enable device interrupt
void dcd_int_enable (uint8_t rhport)
{
diff --git a/test/test/device/msc/test_msc_device.c b/test/test/device/msc/test_msc_device.c
index 095c28170..62a36d3e3 100644
--- a/test/test/device/msc/test_msc_device.c
+++ b/test/test/device/msc/test_msc_device.c
@@ -199,6 +199,7 @@ void setUp(void)
if ( !tusb_inited() )
{
dcd_init_Expect(rhport);
+ dcd_connect_Expect(rhport);
tusb_init();
}
diff --git a/test/test/device/usbd/test_usbd.c b/test/test/device/usbd/test_usbd.c
index 06372b2e4..1bb32c1e5 100644
--- a/test/test/device/usbd/test_usbd.c
+++ b/test/test/device/usbd/test_usbd.c
@@ -127,6 +127,7 @@ void setUp(void)
{
mscd_init_Expect();
dcd_init_Expect(rhport);
+ dcd_connect_Expect(rhport);
tusb_init();
}
}