summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <[email protected]>2018-11-14 09:46:46 -0800
committerScott Shawcroft <[email protected]>2018-11-23 11:15:39 -0800
commit6aa0146c72fec825fcd55584bc9088cbd30fadec (patch)
treecd8e3ea636992678ccc99182e60cff18b4681d70
parenta1c596490aa40863cd5f1e36a821157ffeab2af6 (diff)
Reset USB peripheral and wait for startup
-rw-r--r--src/portable/microchip/samd21/dcd_samd21.c11
-rw-r--r--src/portable/microchip/samd51/dcd_samd51.c10
2 files changed, 19 insertions, 2 deletions
diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c
index c6101f312..93425b63c 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;
diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c
index 6e8053e59..705e06e61 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;