DM: mostly fixed usb enumeration delay
This commit is contained in:
parent
b5c2b6483b
commit
4810822d26
4 changed files with 62 additions and 7 deletions
Binary file not shown.
|
|
@ -81,6 +81,25 @@ public:
|
|||
inline void enableStartOfFrameInterrupt() { usb.INTENSET.bit.SOF = 1; }
|
||||
inline void disableStartOfFrameInterrupt() { usb.INTENCLR.bit.SOF = 1; }
|
||||
|
||||
#if defined(__SAMD51P20A__) || defined(__SAMD51G19A__)
|
||||
//inline void isLpmSuspInterrupt() { return usb.INTFLAG.bit.LPMSUSP; }
|
||||
|
||||
inline bool isRamErrInterrupt() { return usb.INTFLAG.bit.RAMACER; }
|
||||
inline void ackRamErrInterrupt() { usb.INTFLAG.reg = USB_DEVICE_INTFLAG_RAMACER; }
|
||||
inline void enableRamErrInterrupt() { usb.INTENSET.reg = USB_DEVICE_INTFLAG_RAMACER; }
|
||||
inline void disableRamErrInterrupt() { usb.INTENCLR.reg = USB_DEVICE_INTFLAG_RAMACER; }
|
||||
|
||||
inline bool isWakeupInterrupt() { return usb.INTFLAG.reg & (USB_DEVICE_INTFLAG_UPRSM | USB_DEVICE_INTFLAG_EORSM | USB_DEVICE_INTFLAG_WAKEUP); }
|
||||
inline void ackWakeupInterrupt() { usb.INTFLAG.reg = USB_DEVICE_INTFLAG_UPRSM | USB_DEVICE_INTFLAG_EORSM | USB_DEVICE_INTFLAG_WAKEUP; }
|
||||
inline void enableUSBWakeupInterrupts() { usb.INTENSET.reg = USB_DEVICE_INTENSET_UPRSM | USB_DEVICE_INTENSET_EORSM | USB_DEVICE_INTENSET_WAKEUP; }
|
||||
inline void disableUSBWakeuptInterrupts() { usb.INTENCLR.reg = USB_DEVICE_INTENCLR_UPRSM | USB_DEVICE_INTENCLR_EORSM | USB_DEVICE_INTENCLR_WAKEUP; }
|
||||
|
||||
inline bool isSuspendInterrupt() { return usb.INTFLAG.bit.SUSPEND; }
|
||||
inline void ackSuspendInterrupt() { usb.INTFLAG.reg = USB_DEVICE_INTFLAG_SUSPEND; }
|
||||
inline void enableUSBSuspendInterrupts() { usb.INTENSET.reg = (USB_DEVICE_INTFLAG_LPMSUSP | USB_DEVICE_INTFLAG_SUSPEND); }
|
||||
inline void disableUSBSuspendInterrupts() { usb.INTENCLR.reg = (USB_DEVICE_INTFLAG_LPMSUSP | USB_DEVICE_INTFLAG_SUSPEND); }
|
||||
#endif
|
||||
|
||||
// USB Address
|
||||
inline void setAddress(uint32_t addr) { usb.DADD.bit.DADD = addr; usb.DADD.bit.ADDEN = 1; }
|
||||
inline void unsetAddress() { usb.DADD.bit.DADD = 0; usb.DADD.bit.ADDEN = 0; }
|
||||
|
|
@ -180,7 +199,7 @@ private:
|
|||
void USBDevice_SAMD21G18x::reset() {
|
||||
usb.CTRLA.bit.SWRST = 1;
|
||||
memset(EP, 0, sizeof(EP));
|
||||
while (usb.SYNCBUSY.bit.SWRST) {}
|
||||
while (usb.SYNCBUSY.bit.SWRST || usb.SYNCBUSY.bit.ENABLE) {}
|
||||
usb.DESCADD.reg = (uint32_t)(&EP);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -380,10 +380,16 @@ void USBDeviceClass::init()
|
|||
usbd.setFullSpeed();
|
||||
|
||||
// Configure interrupts
|
||||
#if defined(__SAMD51P20A__) || defined(__SAMD51G19A__) //TODO: verify the correct interrupts
|
||||
#if defined(__SAMD51P20A__) || defined(__SAMD51G19A__)
|
||||
/* Attach to the USB host */
|
||||
NVIC_SetPriority((IRQn_Type) USB_0_IRQn, 0UL);
|
||||
NVIC_EnableIRQ((IRQn_Type) USB_0_IRQn);
|
||||
NVIC_SetPriority(USB_0_IRQn, 0UL);
|
||||
NVIC_SetPriority(USB_1_IRQn, 0UL);
|
||||
NVIC_SetPriority(USB_2_IRQn, 0UL);
|
||||
NVIC_SetPriority(USB_3_IRQn, 0UL);
|
||||
NVIC_EnableIRQ(USB_0_IRQn);
|
||||
NVIC_EnableIRQ(USB_1_IRQn);
|
||||
NVIC_EnableIRQ(USB_2_IRQn);
|
||||
NVIC_EnableIRQ(USB_3_IRQn);
|
||||
#else
|
||||
NVIC_SetPriority((IRQn_Type) USB_IRQn, 0UL);
|
||||
NVIC_EnableIRQ((IRQn_Type) USB_IRQn);
|
||||
|
|
@ -400,6 +406,7 @@ bool USBDeviceClass::attach()
|
|||
return false;
|
||||
|
||||
usbd.attach();
|
||||
|
||||
usbd.enableEndOfResetInterrupt();
|
||||
usbd.enableStartOfFrameInterrupt();
|
||||
|
||||
|
|
@ -947,6 +954,20 @@ void USBDeviceClass::ISRHandler()
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__SAMD51P20A__) || defined(__SAMD51G19A__)
|
||||
if (usbd.isRamErrInterrupt()){
|
||||
usbd.ackRamErrInterrupt();
|
||||
//TODO: do something about this error
|
||||
}
|
||||
if (usbd.isWakeupInterrupt()){
|
||||
usbd.ackWakeupInterrupt();
|
||||
}
|
||||
|
||||
if (usbd.isSuspendInterrupt()){
|
||||
usbd.ackSuspendInterrupt();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Endpoint 0 Received Setup interrupt
|
||||
if (usbd.epBank0IsSetupReceived(0))
|
||||
|
|
|
|||
|
|
@ -127,9 +127,9 @@ void SERCOM7_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Han
|
|||
void SERCOM7_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||
void SERCOM7_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||
void USB_0_Handler ( void ) __attribute__ ((weak));
|
||||
void USB_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||
void USB_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||
void USB_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||
void USB_1_Handler ( void ) __attribute__ ((weak));
|
||||
void USB_2_Handler ( void ) __attribute__ ((weak));
|
||||
void USB_3_Handler ( void ) __attribute__ ((weak));
|
||||
void TCC0_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||
void TCC0_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||
void TCC0_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
|
||||
|
|
@ -506,6 +506,21 @@ void USB_0_Handler(void)
|
|||
if (usb_isr)
|
||||
usb_isr();
|
||||
}
|
||||
void USB_1_Handler(void)
|
||||
{
|
||||
if (usb_isr)
|
||||
usb_isr();
|
||||
}
|
||||
void USB_2_Handler(void)
|
||||
{
|
||||
if (usb_isr)
|
||||
usb_isr();
|
||||
}
|
||||
void USB_3_Handler(void)
|
||||
{
|
||||
if (usb_isr)
|
||||
usb_isr();
|
||||
}
|
||||
#else
|
||||
void USB_Handler(void)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue