From 587d1b334b9368759b2afba3114bc5590e7aee09 Mon Sep 17 00:00:00 2001 From: Peter Lawrence <12226419+majbthrd@users.noreply.github.com> Date: Sat, 23 Jan 2021 20:19:10 -0600 Subject: [PATCH 1/8] rp2040_hcd: check pointer before using --- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index c74578c3c..5ea9c7d53 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -444,6 +444,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * // Get appropriate ep. Either EPX or interrupt endpoint struct hw_endpoint *ep = get_dev_ep(dev_addr, ep_addr); + assert(ep); if (ep_addr != ep->ep_addr) { From edc2224118ca18d8c9dd9d6d77d66f6a6d904230 Mon Sep 17 00:00:00 2001 From: Peter Lawrence <12226419+majbthrd@users.noreply.github.com> Date: Sat, 23 Jan 2021 20:21:58 -0600 Subject: [PATCH 2/8] rp2040: start to adopt TU coding conventions --- src/portable/raspberrypi/rp2040/dcd_rp2040.c | 16 ++++++++-------- src/portable/raspberrypi/rp2040/hcd_rp2040.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c index 80e5d3c4b..8ad1729e5 100644 --- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c @@ -38,8 +38,6 @@ #include "device/dcd.h" -#include "pico/stdlib.h" - /*------------------------------------------------------------------*/ /* Low level controller *------------------------------------------------------------------*/ @@ -67,11 +65,7 @@ static struct hw_endpoint *hw_endpoint_get_by_addr(uint8_t ep_addr) } static void _hw_endpoint_alloc(struct hw_endpoint *ep) { - uint size = 64; - if (ep->wMaxPacketSize > 64) - { - size = ep->wMaxPacketSize; - } + uint size = TU_MIN(64, ep->wMaxPacketSize); // Assumes single buffered for now ep->hw_data_buf = next_buffer_ptr; @@ -244,7 +238,7 @@ static void reset_ep0(void) // If we have finished this transfer on EP0 set pid back to 1 for next // setup transfer. Also clear a stall in case uint8_t addrs[] = {0x0, 0x80}; - for (uint i = 0 ; i < count_of(addrs); i++) + for (uint i = 0 ; i < TU_ARRAY_SIZE(addrs); i++) { struct hw_endpoint *ep = hw_endpoint_get_by_addr(addrs[i]); ep->next_pid = 1u; @@ -479,4 +473,10 @@ void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr) } +void dcd_int_handler(uint8_t rhport) +{ + (void) rhport; + dcd_rp2040_irq(); +} + #endif diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c index 5ea9c7d53..efb2bd430 100644 --- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c +++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c @@ -86,7 +86,7 @@ static void set_dev_ep(uint8_t dev_addr, uint8_t ep_addr, struct hw_endpoint *ep uint8_t num = tu_edpt_number(ep_addr); uint8_t in = (ep_addr & TUSB_DIR_IN_MASK) ? 1 : 0; uint32_t index = ep - eps; - hard_assert(index < count_of(eps)); + hard_assert(index < TU_ARRAY_SIZE(eps)); // todo revisit why dev_addr can be 0 here if (dev_addr) { dev_ep_map[dev_addr-1][num][in] = 128u | index; @@ -245,7 +245,7 @@ static void hcd_rp2040_irq(void) static struct hw_endpoint *_next_free_interrupt_ep(void) { struct hw_endpoint *ep = NULL; - for (uint i = 1; i < count_of(eps); i++) + for (uint i = 1; i < TU_ARRAY_SIZE(eps); i++) { ep = &eps[i]; if (!ep->configured) From c4f7ea09f1e5df01eecc2b223728e066c1d8fc02 Mon Sep 17 00:00:00 2001 From: Michael Himing Date: Thu, 28 Jan 2021 20:31:11 +1100 Subject: [PATCH 3/8] Fix midi sysex sending bug --- src/class/midi/midi_device.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/class/midi/midi_device.c b/src/class/midi/midi_device.c index ce4c9cafe..9fff20be2 100644 --- a/src/class/midi/midi_device.c +++ b/src/class/midi/midi_device.c @@ -192,6 +192,7 @@ uint32_t tud_midi_n_write(uint8_t itf, uint8_t jack_id, uint8_t const* buffer, u if (midi->write_buffer[0] == 0x4) { if (data == 0xf7) { midi->write_buffer[0] = 0x5; + midi->write_target_length = 2; } else { midi->write_target_length = 4; } From cb8ceba3dd55030731e7372080218a9fd7f44431 Mon Sep 17 00:00:00 2001 From: charkster Date: Thu, 28 Jan 2021 13:12:54 -0700 Subject: [PATCH 4/8] fix #558 --- examples/device/usbtmc/src/usb_descriptors.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/device/usbtmc/src/usb_descriptors.c b/examples/device/usbtmc/src/usb_descriptors.c index 505456769..14500b1e4 100644 --- a/examples/device/usbtmc/src/usb_descriptors.c +++ b/examples/device/usbtmc/src/usb_descriptors.c @@ -80,10 +80,10 @@ uint8_t const * tud_descriptor_device_cb(void) TUD_USBTMC_BULK_DESCRIPTORS(/* OUT = */0x01, /* IN = */ 0x81, /* packet size = */USBTMCD_MAX_PACKET_SIZE) #if CFG_TUD_USBTMC_ENABLE_INT_EP -// Interrupt endpoint should be 2 bytes on a FS USB link +// Interrupt endpoint should be 2 bytes on a FS USB link, but some microcontrollers only allow 8, 16, 32 or 64 for FS # define TUD_USBTMC_DESC(_itfnum) \ TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3), \ - TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x82, /* epMaxSize = */ 2, /* bInterval = */16u ) + TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x82, /* epMaxSize = */ 8, /* bInterval = */16u ) # define TUD_USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN + TUD_USBTMC_INT_DESCRIPTOR_LEN) #else From 4f988b792cf8f176c95f3dc52fb5a8217633e890 Mon Sep 17 00:00:00 2001 From: charkster Date: Thu, 28 Jan 2021 18:15:49 -0700 Subject: [PATCH 5/8] fix #558 --- examples/device/usbtmc/src/usb_descriptors.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/device/usbtmc/src/usb_descriptors.c b/examples/device/usbtmc/src/usb_descriptors.c index 14500b1e4..f1ed1db7c 100644 --- a/examples/device/usbtmc/src/usb_descriptors.c +++ b/examples/device/usbtmc/src/usb_descriptors.c @@ -80,7 +80,8 @@ uint8_t const * tud_descriptor_device_cb(void) TUD_USBTMC_BULK_DESCRIPTORS(/* OUT = */0x01, /* IN = */ 0x81, /* packet size = */USBTMCD_MAX_PACKET_SIZE) #if CFG_TUD_USBTMC_ENABLE_INT_EP -// Interrupt endpoint should be 2 bytes on a FS USB link, but some microcontrollers only allow 8, 16, 32 or 64 for FS +// USBTMC Interrupt xfer always has length of 2, but we use epMaxSize=8 here for compatibility +// with microcontrollers that only allow 8, 16, 32 or 64 for FS endpoints # define TUD_USBTMC_DESC(_itfnum) \ TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3), \ TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x82, /* epMaxSize = */ 8, /* bInterval = */16u ) From effd82fd9c7e698b6b75521da7a109c5526700a1 Mon Sep 17 00:00:00 2001 From: charkster Date: Thu, 28 Jan 2021 18:34:58 -0700 Subject: [PATCH 6/8] fix #558 third attempt --- examples/device/usbtmc/src/usb_descriptors.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/device/usbtmc/src/usb_descriptors.c b/examples/device/usbtmc/src/usb_descriptors.c index f1ed1db7c..2336266b8 100644 --- a/examples/device/usbtmc/src/usb_descriptors.c +++ b/examples/device/usbtmc/src/usb_descriptors.c @@ -80,8 +80,8 @@ uint8_t const * tud_descriptor_device_cb(void) TUD_USBTMC_BULK_DESCRIPTORS(/* OUT = */0x01, /* IN = */ 0x81, /* packet size = */USBTMCD_MAX_PACKET_SIZE) #if CFG_TUD_USBTMC_ENABLE_INT_EP -// USBTMC Interrupt xfer always has length of 2, but we use epMaxSize=8 here for compatibility -// with microcontrollers that only allow 8, 16, 32 or 64 for FS endpoints +// USBTMC Interrupt xfer always has length of 2, but we use epMaxSize=8 for +// compatibility with mcus that only allow 8, 16, 32 or 64 for FS endpoints # define TUD_USBTMC_DESC(_itfnum) \ TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3), \ TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x82, /* epMaxSize = */ 8, /* bInterval = */16u ) From f3477f87acc96a136da6296e6892abc0116afc97 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 29 Jan 2021 11:30:15 +0700 Subject: [PATCH 7/8] specify ruby version for unit test --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 37cc4c40d..985c9ef34 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,8 @@ jobs: steps: - name: Setup Ruby uses: actions/setup-ruby@v1 + with: + ruby-version: '2.7' - name: Checkout TinyUSB uses: actions/checkout@v2 From 5734cf4bdda36a400d2ad5cc97f16b98048613ef Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 29 Jan 2021 11:36:45 +0700 Subject: [PATCH 8/8] fix #614 typo --- test/test/device/usbd/test_usbd.c | 12 ++++++------ test/test/support/tusb_config.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/test/device/usbd/test_usbd.c b/test/test/device/usbd/test_usbd.c index 06372b2e4..c90383b57 100644 --- a/test/test/device/usbd/test_usbd.c +++ b/test/test/device/usbd/test_usbd.c @@ -209,10 +209,10 @@ void test_usbd_control_in_zlp(void) { // 128 byte total len, with EP0 size = 64, and request length = 256 // ZLP must be return - uint8_t zlp_desc_configuration[CFG_TUD_ENDOINT0_SIZE*2] = + uint8_t zlp_desc_configuration[CFG_TUD_ENDPOINT0_SIZE*2] = { // Config number, interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(1, 0, 0, CFG_TUD_ENDOINT0_SIZE*2, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), + TUD_CONFIG_DESCRIPTOR(1, 0, 0, CFG_TUD_ENDPOINT0_SIZE*2, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), }; desc_configuration = zlp_desc_configuration; @@ -222,13 +222,13 @@ void test_usbd_control_in_zlp(void) // 1st transaction dcd_edpt_xfer_ExpectWithArrayAndReturn(rhport, EDPT_CTRL_IN, - zlp_desc_configuration, CFG_TUD_ENDOINT0_SIZE, CFG_TUD_ENDOINT0_SIZE, true); - dcd_event_xfer_complete(rhport, EDPT_CTRL_IN, CFG_TUD_ENDOINT0_SIZE, 0, false); + zlp_desc_configuration, CFG_TUD_ENDPOINT0_SIZE, CFG_TUD_ENDPOINT0_SIZE, true); + dcd_event_xfer_complete(rhport, EDPT_CTRL_IN, CFG_TUD_ENDPOINT0_SIZE, 0, false); // 2nd transaction dcd_edpt_xfer_ExpectWithArrayAndReturn(rhport, EDPT_CTRL_IN, - zlp_desc_configuration + CFG_TUD_ENDOINT0_SIZE, CFG_TUD_ENDOINT0_SIZE, CFG_TUD_ENDOINT0_SIZE, true); - dcd_event_xfer_complete(rhport, EDPT_CTRL_IN, CFG_TUD_ENDOINT0_SIZE, 0, false); + zlp_desc_configuration + CFG_TUD_ENDPOINT0_SIZE, CFG_TUD_ENDPOINT0_SIZE, CFG_TUD_ENDPOINT0_SIZE, true); + dcd_event_xfer_complete(rhport, EDPT_CTRL_IN, CFG_TUD_ENDPOINT0_SIZE, 0, false); // Expect Zero length Packet dcd_edpt_xfer_ExpectAndReturn(rhport, EDPT_CTRL_IN, NULL, 0, true); diff --git a/test/test/support/tusb_config.h b/test/test/support/tusb_config.h index d80e144da..0455f933b 100644 --- a/test/test/support/tusb_config.h +++ b/test/test/support/tusb_config.h @@ -74,7 +74,7 @@ //-------------------------------------------------------------------- #define CFG_TUD_TASK_QUEUE_SZ 100 -#define CFG_TUD_ENDOINT0_SIZE 64 +#define CFG_TUD_ENDPOINT0_SIZE 64 //------------- CLASS -------------// //#define CFG_TUD_CDC 0