stm32fsdev: Implement dcd_connect.

This commit is contained in:
Nathan Conrad
2020-04-08 11:51:33 -04:00
parent d6578823bb
commit 715c4dbbf8
7 changed files with 48 additions and 13 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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();
// And finally enable pull-up, which may trigger the RESET IRQ if the host is connected.
// (if this MCU has an internal pullup)
#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
// Data-line pull-up is left disconnected.
}
// Define only on MCU with internal pull-up so BSP can override (needed on MCU without internal pull-up)
#if defined(USB_BCDR_DPPU)
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)
{

View File

@@ -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)
{