Merge pull request #332 from pigrew/stm32fsdev-dcdconnect

stm32fsdev: Implement dcd_connect.
This commit is contained in:
Ha Thach 2020-04-11 13:20:31 +07:00 committed by GitHub
commit 07809d03a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 13 deletions

View File

@ -62,6 +62,8 @@ All of the code for the low-level device API is in `src/portable/<vendor>/<chip
##### dcd_init ##### dcd_init
Initializes the USB peripheral for device mode and enables it. Initializes the USB peripheral for device mode and enables it.
This function should leave an internal D+/D- pull-up in its default power-on state. `dcd_connect` will be called by the USBD core following `dcd_init`.
#### dcd_int_enable / dcd_int_disable #### 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. 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 ##### dcd_remote_wakeup
Called to remote wake up host when suspended (e.g hid keyboard) 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 only if MCU has an internal pull-up. (BSP may define for MCU without internal pull-up.)
#### Special events #### 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. 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.

View File

@ -106,11 +106,11 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num);
// Wake up host // Wake up host
void dcd_remote_wakeup(uint8_t rhport); void dcd_remote_wakeup(uint8_t rhport);
// disconnect by disabling internal pull-up resistor on D+/D- // Connect or disconnect D+/D- line pull-up resistor.
void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK; // Defined in dcd source if MCU has internal pull-up.
// Otherwise, may be defined in BSP.
// connect by enabling internal pull-up resistor on D+/D-
void dcd_connect(uint8_t rhport) TU_ATTR_WEAK; void dcd_connect(uint8_t rhport) TU_ATTR_WEAK;
void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Endpoint API // Endpoint API

View File

@ -332,6 +332,7 @@ bool tud_init (void)
// Init device controller driver // Init device controller driver
dcd_init(TUD_OPT_RHPORT); dcd_init(TUD_OPT_RHPORT);
tud_connect();
dcd_int_enable(TUD_OPT_RHPORT); dcd_int_enable(TUD_OPT_RHPORT);
return true; return true;

View File

@ -240,16 +240,28 @@ 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; USB->CNTR |= USB_CNTR_RESETM | USB_CNTR_SOFM | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
dcd_handle_bus_reset(); dcd_handle_bus_reset();
// And finally enable pull-up, which may trigger the RESET IRQ if the host is connected. // Data-line pull-up is left disconnected.
// (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
} }
// Define only on MCU with internal pull-up. BSP can define on MCU without internal PU.
#if defined(USB_BCDR_DPPU)
// Disable internal D+ PU
void dcd_disconnect(uint8_t rhport)
{
(void) rhport;
USB->BCDR &= ~(USB_BCDR_DPPU);
}
// Enable internal D+ PU
void dcd_connect(uint8_t rhport)
{
(void) rhport;
USB->BCDR |= USB_BCDR_DPPU;
}
#endif
// Enable device interrupt // Enable device interrupt
void dcd_int_enable (uint8_t rhport) void dcd_int_enable (uint8_t rhport)
{ {

View File

@ -45,6 +45,20 @@ void dcd_init (uint8_t rhport)
(void) 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 // Enable device interrupt
void dcd_int_enable (uint8_t rhport) void dcd_int_enable (uint8_t rhport)
{ {

View File

@ -199,6 +199,7 @@ void setUp(void)
if ( !tusb_inited() ) if ( !tusb_inited() )
{ {
dcd_init_Expect(rhport); dcd_init_Expect(rhport);
dcd_connect_Expect(rhport);
tusb_init(); tusb_init();
} }

View File

@ -127,6 +127,7 @@ void setUp(void)
{ {
mscd_init_Expect(); mscd_init_Expect();
dcd_init_Expect(rhport); dcd_init_Expect(rhport);
dcd_connect_Expect(rhport);
tusb_init(); tusb_init();
} }
} }