From c026236824e95d9409136cd48481b69e2cea56dc Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 6 Apr 2020 16:33:04 +0700 Subject: house keeping --- src/device/usbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/device') diff --git a/src/device/usbd.c b/src/device/usbd.c index ddd99d7f1..125aa351c 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -421,7 +421,7 @@ void tud_task (void) uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const ep_dir = tu_edpt_dir(ep_addr); - TU_LOG2(" Endpoint: 0x%02X, Bytes: %ld\r\n", ep_addr, event.xfer_complete.len); + TU_LOG2(" Endpoint: 0x%02X, Bytes: %lu\r\n", ep_addr, event.xfer_complete.len); _usbd_dev.ep_status[epnum][ep_dir].busy = false; -- cgit v1.3.1 From 11201f1a06396d4ab8302f2bb5ce579cb4ae7a6c Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 9 Apr 2020 11:42:42 +0700 Subject: adding dcd_connect/disconnect --- src/device/dcd.h | 6 ++++++ src/device/usbd.h | 14 ++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'src/device') diff --git a/src/device/dcd.h b/src/device/dcd.h index 143a2de34..487ddb3b6 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -106,6 +106,12 @@ 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- +void dcd_connect(uint8_t rhport) TU_ATTR_WEAK; + //--------------------------------------------------------------------+ // Endpoint API //--------------------------------------------------------------------+ diff --git a/src/device/usbd.h b/src/device/usbd.h index beeec7e1c..817af20e3 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -65,6 +65,20 @@ static inline bool tud_ready(void) // Remote wake up host, only if suspended and enabled by host bool tud_remote_wakeup(void); +static inline bool tud_disconnect(void) +{ + TU_VERIFY(dcd_disconnect); + dcd_disconnect(TUD_OPT_RHPORT); + return true; +} + +static inline bool tud_connect(void) +{ + TU_VERIFY(dcd_connect); + dcd_connect(TUD_OPT_RHPORT); + return true; +} + // Carry out Data and Status stage of control transfer // - If len = 0, it is equivalent to sending status only // - If len > wLength : it will be truncated -- cgit v1.3.1 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. --- docs/porting.md | 6 ++++++ 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 ++++++++++++++ test/test/device/msc/test_msc_device.c | 1 + test/test/device/usbd/test_usbd.c | 1 + 7 files changed, 45 insertions(+), 10 deletions(-) (limited to 'src/device') 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//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(); } } -- cgit v1.3.1 From 1b3d1b52c9351391f62dea374345c8de7f985b0f Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 10 Apr 2020 13:54:50 +0700 Subject: fix uint32_t format with log --- src/device/usbd.c | 2 +- src/tusb.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/device') diff --git a/src/device/usbd.c b/src/device/usbd.c index 125aa351c..397a681ed 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -421,7 +421,7 @@ void tud_task (void) uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const ep_dir = tu_edpt_dir(ep_addr); - TU_LOG2(" Endpoint: 0x%02X, Bytes: %lu\r\n", ep_addr, event.xfer_complete.len); + TU_LOG2(" Endpoint: 0x%02X, Bytes: %u\r\n", ep_addr, (unsigned int) event.xfer_complete.len); _usbd_dev.ep_status[epnum][ep_dir].busy = false; diff --git a/src/tusb.c b/src/tusb.c index 8e0022f4d..8f234455f 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -96,9 +96,9 @@ void tu_print_mem(void const *buf, uint16_t count, uint8_t indent) char format[] = "%00lX"; format[2] += 2*size; - const uint8_t item_per_line = 16 / size; + const uint8_t item_per_line = 16 / size; - for(uint32_t i=0; i 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/device') 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