summaryrefslogtreecommitdiff
path: root/src/portable
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-11-24 14:43:31 +0700
committerGitHub <[email protected]>2018-11-24 14:43:31 +0700
commit3bb53273cd3770328f55ba317af3df0cce4333c1 (patch)
tree8148c662b9773f6af64ea71c9eac6ae3a7e402f3 /src/portable
parenta1c596490aa40863cd5f1e36a821157ffeab2af6 (diff)
parent47fabe42edaae4a5da6aa0d48c664a9184578753 (diff)
Merge pull request #14 from tannewt/discarded_qualifiers
A few more updates
Diffstat (limited to 'src/portable')
-rw-r--r--src/portable/microchip/samd21/dcd_samd21.c17
-rw-r--r--src/portable/microchip/samd51/dcd_samd51.c16
2 files changed, 31 insertions, 2 deletions
diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c
index c6101f312..c2464d6b0 100644
--- a/src/portable/microchip/samd21/dcd_samd21.c
+++ b/src/portable/microchip/samd21/dcd_samd21.c
@@ -71,10 +71,19 @@ static void bus_reset(void) {
*------------------------------------------------------------------*/
bool dcd_init (uint8_t rhport)
{
+ // Reset to get in a clean state.
+ USB->DEVICE.CTRLA.bit.SWRST = true;
+ while (USB->DEVICE.SYNCBUSY.bit.SWRST == 0) {
+
+ }
+ while (USB->DEVICE.SYNCBUSY.bit.SWRST == 1) {}
+
(void) rhport;
USB->DEVICE.DESCADD.reg = (uint32_t) &sram_registers;
USB->DEVICE.CTRLB.reg = USB_DEVICE_CTRLB_SPDCONF_FS;
- USB->DEVICE.CTRLA.reg = USB_CTRLA_MODE_DEVICE | USB_CTRLA_ENABLE;
+ USB->DEVICE.CTRLA.reg = USB_CTRLA_MODE_DEVICE | USB_CTRLA_ENABLE | USB_CTRLA_RUNSTDBY;
+ while (USB->DEVICE.SYNCBUSY.bit.ENABLE == 1) {}
+
USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_SOF | USB_DEVICE_INTENSET_EORST;
return true;
@@ -155,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 6e8053e59..e53a8641f 100644
--- a/src/portable/microchip/samd51/dcd_samd51.c
+++ b/src/portable/microchip/samd51/dcd_samd51.c
@@ -72,9 +72,17 @@ static void bus_reset(void) {
bool dcd_init (uint8_t rhport)
{
(void) rhport;
+ // Reset to get in a clean state.
+ USB->DEVICE.CTRLA.bit.SWRST = true;
+ while (USB->DEVICE.SYNCBUSY.bit.SWRST == 0) {
+
+ }
+ while (USB->DEVICE.SYNCBUSY.bit.SWRST == 1) {}
+
USB->DEVICE.DESCADD.reg = (uint32_t) &sram_registers;
USB->DEVICE.CTRLB.reg = USB_DEVICE_CTRLB_SPDCONF_FS;
- USB->DEVICE.CTRLA.reg = USB_CTRLA_MODE_DEVICE | USB_CTRLA_ENABLE;
+ USB->DEVICE.CTRLA.reg = USB_CTRLA_MODE_DEVICE | USB_CTRLA_ENABLE | USB_CTRLA_RUNSTDBY;
+ while (USB->DEVICE.SYNCBUSY.bit.ENABLE == 1) {}
USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_SOF | USB_DEVICE_INTENSET_EORST;
return true;
@@ -155,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 )
{