From 60620dca4286fc9ce9ddf4c2f2e6a39c062a5056 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 8 Jan 2021 01:21:03 +0700 Subject: [PATCH] walkround for samd21 setup_packet overflow increase setup packet size from 8 to 12, since USB DMA controller is suspected to overflow the buffer with 2 extra bytes --- src/portable/microchip/samd/dcd_samd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/portable/microchip/samd/dcd_samd.c b/src/portable/microchip/samd/dcd_samd.c index f1dca88a5..35fac23a8 100644 --- a/src/portable/microchip/samd/dcd_samd.c +++ b/src/portable/microchip/samd/dcd_samd.c @@ -37,14 +37,20 @@ /* MACRO TYPEDEF CONSTANT ENUM *------------------------------------------------------------------*/ static TU_ATTR_ALIGNED(4) UsbDeviceDescBank sram_registers[8][2]; -static TU_ATTR_ALIGNED(4) uint8_t _setup_packet[8]; + +// Setup packet is only 8 bytes in length. However under certain scenario, +// SAMD21 USB DMA controller is "suspected" to overwrite/overflow the setup_packet with 2 extra bytes. +// Which corrupt other variable and cause issue such as +// https://github.com/adafruit/circuitpython/issues/3912 (on macOS) +// Therefore we increase it to 12 bytes as walk-around until figuring out the root cause +static TU_ATTR_ALIGNED(4) uint8_t _setup_packet[8+4]; // ready for receiving SETUP packet static inline void prepare_setup(void) { // Only make sure the EP0 OUT buffer is ready sram_registers[0][0].ADDR.reg = (uint32_t) _setup_packet; - sram_registers[0][0].PCKSIZE.bit.MULTI_PACKET_SIZE = sizeof(_setup_packet); + sram_registers[0][0].PCKSIZE.bit.MULTI_PACKET_SIZE = sizeof(tusb_control_request_t); sram_registers[0][0].PCKSIZE.bit.BYTE_COUNT = 0; }