From cc5dfd03cd64b1faad7374f6207cb80837134c89 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 8 Jan 2021 11:21:26 +0700 Subject: [PATCH] update comment and correct the size to 8+2 --- src/portable/microchip/samd/dcd_samd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/portable/microchip/samd/dcd_samd.c b/src/portable/microchip/samd/dcd_samd.c index 35fac23a8..4806342cc 100644 --- a/src/portable/microchip/samd/dcd_samd.c +++ b/src/portable/microchip/samd/dcd_samd.c @@ -39,11 +39,14 @@ static TU_ATTR_ALIGNED(4) UsbDeviceDescBank sram_registers[8][2]; // 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]; +// USB DMA controller may decide to overwrite/overflow the buffer with +// 2 extra bytes of CRC. From datasheet's "Management of SETUP Transactions" section +// If the number of received data bytes is the maximum data payload specified by +// PCKSIZE.SIZE minus one, only the first CRC data is written to the data buffer. +// If the number of received data is equal or less than the data payload specified +// by PCKSIZE.SIZE minus two, both CRC data bytes are written to the data buffer. +// Therefore we will increase it to 10 bytes just to be safe +static TU_ATTR_ALIGNED(4) uint8_t _setup_packet[8+2]; // ready for receiving SETUP packet static inline void prepare_setup(void)