summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-01-08 11:57:25 +0700
committerGitHub <[email protected]>2021-01-08 11:57:25 +0700
commit5442508f82a1b5716fb8ca8e53d8c45c93e53d5e (patch)
tree8c29e2238ddf22084020e9f526f009633f19c96b /src
parent9f0b401f802fa553bd7fc84e76299702d8568b4c (diff)
parent3e1d85eed25c384cc9fe6e7e16fbfbdc491c5536 (diff)
Merge pull request #586 from hathach/walkround-samd21-setup-overflow
walkround for samd21 setup_packet overflow
Diffstat (limited to 'src')
-rw-r--r--src/portable/microchip/samd/dcd_samd.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/portable/microchip/samd/dcd_samd.c b/src/portable/microchip/samd/dcd_samd.c
index f1dca88a5..68a15672a 100644
--- a/src/portable/microchip/samd/dcd_samd.c
+++ b/src/portable/microchip/samd/dcd_samd.c
@@ -37,14 +37,23 @@
/* 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,
+// 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 need to increase it to 10 bytes here.
+static TU_ATTR_ALIGNED(4) uint8_t _setup_packet[8+2];
// 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;
}