From bf8c4612dccfc65e0867d03d85d9ebe2e46101e0 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 14 Nov 2018 14:36:26 -0800 Subject: [PATCH] Make sure OUT endpoint 0 on the SAMDs always has a valid buffer to store a SETUP token into. --- src/portable/microchip/samd21/dcd_samd21.c | 6 ++++++ src/portable/microchip/samd51/dcd_samd51.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c index 93425b63c..c2464d6b0 100644 --- a/src/portable/microchip/samd21/dcd_samd21.c +++ b/src/portable/microchip/samd21/dcd_samd21.c @@ -164,6 +164,12 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; + // A setup token can occur immediately after an OUT STATUS packet so make sure we have a valid + // buffer for the control endpoint. + if (epnum == 0 && dir == 0 && buffer == NULL) { + buffer = _setup_packet; + } + bank->ADDR.reg = (uint32_t) buffer; if ( dir == TUSB_DIR_OUT ) { diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c index 705e06e61..e53a8641f 100644 --- a/src/portable/microchip/samd51/dcd_samd51.c +++ b/src/portable/microchip/samd51/dcd_samd51.c @@ -163,6 +163,12 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; + // A setup token can occur immediately after an OUT STATUS packet so make sure we have a valid + // buffer for the control endpoint. + if (epnum == 0 && dir == 0 && buffer == NULL) { + buffer = _setup_packet; + } + bank->ADDR.reg = (uint32_t) buffer; if ( dir == TUSB_DIR_OUT ) {