From 715c4dbbf8fe7c6bb83013df626a201928704b30 Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Wed, 8 Apr 2020 11:51:33 -0400 Subject: stm32fsdev: Implement dcd_connect. --- src/device/dcd.h | 8 ++++---- src/device/usbd.c | 1 + src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 24 ++++++++++++++++++------ src/portable/template/dcd_template.c | 14 ++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) (limited to 'src') 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) { -- cgit v1.3.1 From 5bd9d14fc14d9130d7d879800bd46e4ca08e3d5f Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Fri, 10 Apr 2020 10:23:56 -0400 Subject: stm32fsdev: set dcd_connect API definitions to strong, Modify documentation. --- docs/porting.md | 4 ++-- src/device/dcd.h | 4 ++-- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/docs/porting.md b/docs/porting.md index 7d7d4cdb1..d3408aebd 100644 --- a/docs/porting.md +++ b/docs/porting.md @@ -62,7 +62,7 @@ All of the code for the low-level device API is in `src/portable//BCDR &= ~(USB_BCDR_DPPU); } -TU_ATTR_WEAK +// Enable internal D+ PU void dcd_connect(uint8_t rhport) { (void) rhport; -- cgit v1.3.1