20 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
22 #if defined( USB_DEVICE ) || defined( USB_HOST )
30 #define USB_PID_DATA0 0
31 #define USB_PID_DATA2 1
32 #define USB_PID_DATA1 2
33 #define USB_PID_SETUP 3
35 #define HPRT_F_SPEED ( 1 << _USB_HPRT_PRTSPD_SHIFT )
36 #define HPRT_L_SPEED ( 2 << _USB_HPRT_PRTSPD_SHIFT )
37 #define HCFG_PHYCLK_48MHZ 1
38 #define HCFG_PHYCLK_6MHZ 2
40 #define DOEP0_XFERSIZE_PKTCNT_MASK ( _USB_DOEP0TSIZ_XFERSIZE_MASK | \
41 _USB_DOEP0TSIZ_PKTCNT_MASK )
42 #define DOEP_XFERSIZE_PKTCNT_MASK ( _USB_DOEP_TSIZ_XFERSIZE_MASK | \
43 _USB_DOEP_TSIZ_PKTCNT_MASK )
45 #define DIEP0_XFERSIZE_PKTCNT_MASK ( _USB_DIEP0TSIZ_XFERSIZE_MASK | \
46 _USB_DIEP0TSIZ_PKTCNT_MASK )
47 #define DIEP_XFERSIZE_PKTCNT_MASK ( _USB_DIEP_TSIZ_XFERSIZE_MASK | \
48 _USB_DIEP_TSIZ_PKTCNT_MASK | \
49 _USB_DIEP_TSIZ_MC_MASK )
51 #define DIEPCTL_EPTYPE_CONTROL (0 << _USB_DIEP_CTL_EPTYPE_SHIFT )
52 #define DIEPCTL_EPTYPE_ISOC (1 << _USB_DIEP_CTL_EPTYPE_SHIFT )
53 #define DIEPCTL_EPTYPE_BULK (2 << _USB_DIEP_CTL_EPTYPE_SHIFT )
54 #define DIEPCTL_EPTYPE_INTR (3 << _USB_DIEP_CTL_EPTYPE_SHIFT )
56 #define DOEPCTL_EPTYPE_CONTROL (0 << _USB_DOEP_CTL_EPTYPE_SHIFT )
57 #define DOEPCTL_EPTYPE_ISOC (1 << _USB_DOEP_CTL_EPTYPE_SHIFT )
58 #define DOEPCTL_EPTYPE_BULK (2 << _USB_DOEP_CTL_EPTYPE_SHIFT )
59 #define DOEPCTL_EPTYPE_INTR (3 << _USB_DOEP_CTL_EPTYPE_SHIFT )
61 #define HCCHAR_EPTYPE_CTRL (0 << _USB_HC_CHAR_EPTYPE_SHIFT )
62 #define HCCHAR_EPTYPE_ISOC (1 << _USB_HC_CHAR_EPTYPE_SHIFT )
63 #define HCCHAR_EPTYPE_BULK (2 << _USB_HC_CHAR_EPTYPE_SHIFT )
64 #define HCCHAR_EPTYPE_INTR (3 << _USB_HC_CHAR_EPTYPE_SHIFT )
66 #define GRXSTSP_PKTSTS_DEVICE_GOTNAK ( 1 << _USB_GRXSTSP_PKTSTS_SHIFT )
67 #define GRXSTSP_PKTSTS_DEVICE_DATAOUTRECEIVED ( 2 << _USB_GRXSTSP_PKTSTS_SHIFT )
68 #define GRXSTSP_PKTSTS_DEVICE_DATAOUTCOMPLETE ( 3 << _USB_GRXSTSP_PKTSTS_SHIFT )
69 #define GRXSTSP_PKTSTS_DEVICE_SETUPCOMPLETE ( 4 << _USB_GRXSTSP_PKTSTS_SHIFT )
70 #define GRXSTSP_PKTSTS_DEVICE_SETUPRECEIVED ( 6 << _USB_GRXSTSP_PKTSTS_SHIFT )
72 #define GRXSTSP_PKTSTS_HOST_DATAINRECEIVED ( 2 << _USB_GRXSTSP_PKTSTS_SHIFT )
73 #define GRXSTSP_PKTSTS_HOST_DATAINCOMPLETE ( 3 << _USB_GRXSTSP_PKTSTS_SHIFT )
74 #define GRXSTSP_PKTSTS_HOST_DATATOGGLEERROR ( 5 << _USB_GRXSTSP_PKTSTS_SHIFT )
75 #define GRXSTSP_PKTSTS_HOST_CHANNELHALTED ( 7 << _USB_GRXSTSP_PKTSTS_SHIFT )
77 #define DCTL_WO_BITMASK \
78 ( _USB_DCTL_CGOUTNAK_MASK | _USB_DCTL_SGOUTNAK_MASK | \
79 _USB_DCTL_CGNPINNAK_MASK | _USB_DCTL_SGNPINNAK_MASK )
80 #define GUSBCFG_WO_BITMASK ( USB_GUSBCFG_CORRUPTTXPKT )
81 #define DEPCTL_WO_BITMASK \
82 ( USB_DIEP_CTL_CNAK | USB_DIEP_CTL_SNAK | \
83 USB_DIEP_CTL_SETD0PIDEF | USB_DIEP_CTL_SETD1PIDOF )
85 #define HPRT_WC_MASK ( USB_HPRT_PRTCONNDET | USB_HPRT_PRTENA | \
86 USB_HPRT_PRTENCHNG | USB_HPRT_PRTOVRCURRCHNG )
88 typedef __IO uint32_t USB_FIFO_TypeDef[ 0x1000 /
sizeof( uint32_t ) ];
89 typedef __IO uint32_t USB_DIEPTXF_TypeDef;
91 #define USB_DINEPS ((USB_DIEP_TypeDef *) &USB->DIEP0CTL )
92 #define USB_DOUTEPS ((USB_DOEP_TypeDef *) &USB->DOEP0CTL )
93 #define USB_FIFOS ((USB_FIFO_TypeDef *) &USB->FIFO0D )
94 #define USB_DIEPTXFS ((USB_DIEPTXF_TypeDef *) &USB->DIEPTXF1 )
96 void USBHAL_CoreReset(
void );
98 #if defined( USB_DEVICE )
101 const uint32_t totalTxFifoSize );
102 void USBDHAL_Connect(
void );
103 void USBDHAL_Disconnect(
void );
104 void USBDHAL_AbortAllEps(
void );
105 void USBDHAL_AbortEpIn( USBD_Ep_TypeDef *ep );
106 void USBDHAL_AbortEpOut( USBD_Ep_TypeDef *ep );
109 USBD_Ep_TypeDef *ep, uint16_t *halt );
110 __STATIC_INLINE uint32_t USBDHAL_GetInEpInts( USBD_Ep_TypeDef *ep );
111 __STATIC_INLINE uint32_t USBDHAL_GetOutEpInts( USBD_Ep_TypeDef *ep );
112 __STATIC_INLINE
void USBDHAL_SetEPDISNAK( USBD_Ep_TypeDef *ep );
115 #if defined( USB_HOST )
117 const uint32_t nptxFifoSize,
118 const uint32_t ptxFifoSize );
119 void USBHHAL_HCHalt(
int hcnum, uint32_t hcchar );
120 void USBHHAL_HCInit(
int hcnum );
121 void USBHHAL_HCStart(
int hcnum );
124 __STATIC_INLINE
void USBHAL_DisableGlobalInt(
void )
129 __STATIC_INLINE
void USBHAL_DisablePhyPins(
void )
134 __STATIC_INLINE
void USBHAL_DisableUsbInt(
void )
139 __STATIC_INLINE
void USBHAL_EnableGlobalInt(
void )
144 __STATIC_INLINE
void USBHAL_FlushRxFifo(
void )
150 __STATIC_INLINE
void USBHAL_FlushTxFifo( uint8_t fifoNum )
156 __STATIC_INLINE uint32_t USBHAL_GetCoreInts(
void )
160 retVal =
USB->GINTSTS;
161 retVal &=
USB->GINTMSK;
166 __STATIC_INLINE
bool USBHAL_VbusIsOn(
void )
171 #if defined( USB_DEVICE )
172 __STATIC_INLINE
void USBDHAL_ActivateEp( USBD_Ep_TypeDef *ep,
bool forceIdle )
174 #define DIEP_MPS_EPTYPE_TXFNUM_MASK ( _USB_DIEP_CTL_MPS_MASK | \
175 _USB_DIEP_CTL_EPTYPE_MASK | \
176 _USB_DIEP_CTL_TXFNUM_MASK )
177 #define DOEP_MPS_EPTYPE_MASK ( _USB_DOEP_CTL_MPS_MASK | \
178 _USB_DOEP_CTL_EPTYPE_MASK )
179 uint32_t daintmask, depctl;
182 ep->state = D_EP_IDLE;
186 daintmask = ep->mask;
187 depctl = USB_DINEPS[ ep->num ].CTL & ~DEPCTL_WO_BITMASK;
192 ~( DIEP_MPS_EPTYPE_TXFNUM_MASK |
198 USB_DIEP_CTL_USBACTEP |
205 USB_DINEPS[ ep->num ].CTL = depctl;
210 depctl = USB_DOUTEPS[ ep->num ].CTL & ~DEPCTL_WO_BITMASK;
215 ~( DOEP_MPS_EPTYPE_MASK |
220 USB_DOEP_CTL_USBACTEP |
227 USB_DOUTEPS[ ep->num ].CTL = depctl;
231 USB->DAINTMSK |= daintmask;
233 #undef DIEP_MPS_EPTYPE_TXFNUM_MASK
234 #undef DOEP_MPS_EPTYPE_MASK
237 __STATIC_INLINE
void USBDHAL_ClearRemoteWakeup(
void )
242 __STATIC_INLINE
void USBDHAL_DeactivateEp( USBD_Ep_TypeDef *ep )
248 USB_DINEPS[ ep->num ].CTL = 0;
249 daintmask = ep->mask;
253 USB_DOUTEPS[ ep->num ].CTL = 0;
258 USB->DAINTMSK &= ~daintmask;
261 __STATIC_INLINE
void USBDHAL_EnableInts( USBD_Device_TypeDef *dev )
269 USB->GINTSTS = 0xFFFFFFFF;
278 if ( dev->callbacks->sofInt )
286 __STATIC_INLINE
void USBDHAL_EnableUsbResetAndSuspendInt(
void )
294 __STATIC_INLINE
void USBDHAL_Ep0Activate( uint32_t ep0mps )
298 USB->DOEP0CTL = (
USB->DOEP0CTL & ~DEPCTL_WO_BITMASK )
303 __STATIC_INLINE
bool USBDHAL_EpIsStalled( USBD_Ep_TypeDef *ep )
306 uint16_t stallStatus;
308 if ( USBDHAL_GetStallStatusEp( ep, &stallStatus ) ==
USB_STATUS_OK )
310 retVal = stallStatus & 1 ?
true :
false;
315 __STATIC_INLINE uint32_t USBDHAL_GetAllInEpInts(
void )
320 retVal &=
USB->DAINTMSK;
321 return retVal & 0xFFFF;
324 __STATIC_INLINE uint32_t USBDHAL_GetAllOutEpInts(
void )
329 retVal &=
USB->DAINTMSK;
333 __STATIC_INLINE uint32_t USBDHAL_GetInEpInts( USBD_Ep_TypeDef *ep )
335 uint32_t retVal, msk;
338 retVal = USB_DINEPS[ ep->num ].INT;
343 __STATIC_INLINE uint32_t USBDHAL_GetOutEpInts( USBD_Ep_TypeDef *ep )
347 retVal = USB_DOUTEPS[ ep->num ].INT;
348 #if defined( USB_DOEP0INT_STUPPKTRCVD )
349 retVal &=
USB->DOEPMSK | USB_DOEP0INT_STUPPKTRCVD;
351 retVal &=
USB->DOEPMSK;
358 USBD_Ep_TypeDef *ep, uint16_t *halt )
360 uint32_t depctl, eptype;
363 if ( ep->in ==
true )
365 depctl = USB_DINEPS[ ep->num ].CTL;
368 if (( eptype == DIEPCTL_EPTYPE_INTR ) || ( eptype == DIEPCTL_EPTYPE_BULK ))
376 depctl = USB_DOUTEPS[ ep->num ].CTL;
379 if (( eptype == DOEPCTL_EPTYPE_INTR ) || ( eptype == DOEPCTL_EPTYPE_BULK ))
389 __STATIC_INLINE
void USBDHAL_ReenableEp0Setup( USBD_Device_TypeDef *dev )
392 USB->DOEP0DMAADDR = (uint32_t)dev->setupPkt;
393 USB->DOEP0CTL = (
USB->DOEP0CTL & ~DEPCTL_WO_BITMASK )
398 __STATIC_INLINE
void USBDHAL_SetAddr( uint8_t addr )
405 __STATIC_INLINE
void USBDHAL_SetEp0InDmaPtr( uint8_t* addr )
407 USB->DIEP0DMAADDR = (uint32_t)addr;
410 __STATIC_INLINE
void USBDHAL_SetEp0OutDmaPtr( uint8_t* addr )
412 USB->DOEP0DMAADDR = (uint32_t)addr;
415 __STATIC_INLINE
void USBDHAL_SetEPDISNAK( USBD_Ep_TypeDef *ep )
419 USB_DINEPS[ ep->num ].CTL = ( USB_DINEPS[ ep->num ].CTL &
420 ~DEPCTL_WO_BITMASK ) |
426 USB_DOUTEPS[ ep->num ].CTL = ( USB_DOUTEPS[ ep->num ].CTL &
427 ~DEPCTL_WO_BITMASK ) |
430 USB_DOUTEPS[ ep->num ].CTL = ( USB_DOUTEPS[ ep->num ].CTL &
431 ~DEPCTL_WO_BITMASK ) |
437 __STATIC_INLINE
void USBDHAL_SetRemoteWakeup(
void )
444 uint32_t depctl, eptype;
447 if ( ep->in ==
true )
449 depctl = USB_DINEPS[ ep->num ].CTL & ~DEPCTL_WO_BITMASK;
452 if ( eptype != DIEPCTL_EPTYPE_ISOC )
464 depctl = USB_DOUTEPS[ ep->num ].CTL & ~DEPCTL_WO_BITMASK;
467 if ( eptype != DIEPCTL_EPTYPE_ISOC )
477 __STATIC_INLINE
void USBDHAL_StartEp0In( uint32_t len, uint32_t ep0mps )
482 USB->DIEP0CTL = (
USB->DIEP0CTL & ~DEPCTL_WO_BITMASK )
487 __STATIC_INLINE
void USBDHAL_StartEp0Out( uint32_t len, uint32_t ep0mps )
492 USB->DOEP0CTL = (
USB->DOEP0CTL & ~DEPCTL_WO_BITMASK )
497 __STATIC_INLINE
void USBDHAL_StartEp0Setup( USBD_Device_TypeDef *dev )
499 dev->ep[ 0 ].in =
false;
501 #if defined( USB_DOEP0INT_STUPPKTRCVD )
509 dev->setup = dev->setupPkt;
510 USB->DOEP0DMAADDR = (uint32_t)dev->setup;
512 #
if defined( USB_DOEP0INT_STUPPKTRCVD )
513 USB->DOEP0CTL = (
USB->DOEP0CTL & ~DEPCTL_WO_BITMASK )
517 USB->DOEP0CTL = (
USB->DOEP0CTL & ~DEPCTL_WO_BITMASK )
523 __STATIC_INLINE
void USBDHAL_StartEpIn( USBD_Ep_TypeDef *ep )
525 uint32_t pktcnt, xfersize;
527 if ( ep->remaining == 0 )
534 pktcnt = ( ep->remaining - 1 + ep->packetSize ) / ep->packetSize;
535 xfersize = ep->remaining;
538 USB_DINEPS[ ep->num ].TSIZ =
539 ( USB_DINEPS[ ep->num ].TSIZ &
540 ~DIEP_XFERSIZE_PKTCNT_MASK ) |
544 USB_DINEPS[ ep->num ].DMAADDR = (uint32_t)ep->buf;
545 USB_DINEPS[ ep->num ].CTL =
546 ( USB_DINEPS[ ep->num ].CTL & ~DEPCTL_WO_BITMASK ) |
551 __STATIC_INLINE
void USBDHAL_StartEpOut( USBD_Ep_TypeDef *ep )
553 uint32_t pktcnt, xfersize;
555 if ( ep->remaining == 0 )
558 xfersize = ep->packetSize;
562 pktcnt = ( ep->remaining - 1 + ep->packetSize ) / ep->packetSize;
563 xfersize = pktcnt * ep->packetSize;
566 USB_DOUTEPS[ ep->num ].TSIZ =
567 ( USB_DOUTEPS[ ep->num ].TSIZ &
568 ~DOEP_XFERSIZE_PKTCNT_MASK ) |
572 ep->hwXferSize = xfersize;
573 USB_DOUTEPS[ ep->num ].DMAADDR = (uint32_t)ep->buf;
574 USB_DOUTEPS[ ep->num ].CTL =
575 ( USB_DOUTEPS[ ep->num ].CTL &
576 ~DEPCTL_WO_BITMASK ) |
583 uint32_t depctl, eptype;
586 if ( ep->in ==
true )
588 depctl = USB_DINEPS[ ep->num ].CTL & ~DEPCTL_WO_BITMASK;
591 if (( eptype == DIEPCTL_EPTYPE_INTR ) || ( eptype == DIEPCTL_EPTYPE_BULK ))
595 USB_DINEPS[ ep->num ].CTL = depctl;
601 depctl = USB_DOUTEPS[ ep->num ].CTL & ~DEPCTL_WO_BITMASK;
604 if (( eptype == DIEPCTL_EPTYPE_INTR ) || ( eptype == DIEPCTL_EPTYPE_BULK ))
608 USB_DOUTEPS[ ep->num ].CTL = depctl;
617 #if defined( USB_HOST )
618 __STATIC_INLINE
void USBHHAL_HCActivate(
int hcnum, uint32_t hcchar,
bool intep )
624 oddframe =
USB->HFNUM & 1;
626 USB->HC[ hcnum ].CHAR =
642 __STATIC_INLINE
bool USBHHAL_InitializedAndPowered(
void )
650 __STATIC_INLINE
void USBHHAL_EnableInts(
void )
656 USB->GOTGINT = 0xFFFFFFFF;
659 USB->GINTSTS = 0xFFFFFFFF;
666 __STATIC_INLINE uint16_t USBHHAL_GetFrameNum(
void )
671 __STATIC_INLINE uint32_t USBHHAL_GetHcChar( uint8_t hcnum )
673 return USB->HC[ hcnum ].CHAR;
676 __STATIC_INLINE uint32_t USBHHAL_GetHcInts( uint8_t hcnum )
680 retVal =
USB->HC[ hcnum ].INT;
684 __STATIC_INLINE uint32_t USBHHAL_GetHostChannelInts(
void )
689 __STATIC_INLINE uint8_t USBHHAL_GetPortSpeed(
void )
694 __STATIC_INLINE
void USBHHAL_PortReset(
bool on )
698 DEBUG_USB_INT_LO_PUTCHAR(
'+' );
703 DEBUG_USB_INT_LO_PUTCHAR(
'-' );
708 __STATIC_INLINE
void USBHHAL_PortResume(
bool on )
721 __STATIC_INLINE
void USBHHAL_PortSuspend(
void )
726 __STATIC_INLINE
void USBHHAL_VbusOn(
bool on )
731 DEBUG_USB_INT_LO_PUTCHAR(
'/' );
736 DEBUG_USB_INT_LO_PUTCHAR(
'\\' );
#define _USB_DOEP_CTL_EPTYPE_MASK
#define USB_DOEP_CTL_EPDIS
#define USB_DIEP_CTL_EPDIS
#define USB_GINTMSK_WKUPINTMSK
#define USB_GINTMSK_OEPINTMSK
#define USB_DIEP_CTL_EPENA
#define _USB_ROUTE_RESETVALUE
#define _USB_DIEP0TSIZ_XFERSIZE_SHIFT
#define USB_GINTMSK_USBSUSPMSK
#define USB_GINTMSK_DISCONNINTMSK
#define USB_DIEP_CTL_CNAK
#define _USB_DIEP0TSIZ_PKTCNT_SHIFT
#define USB_DOEP_CTL_STALL
#define _USB_DIEP_CTL_TXFNUM_SHIFT
#define USB_DOEP0CTL_EPENA
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define _USB_DIEP_CTL_MPS_SHIFT
#define _USB_DIEP_TSIZ_XFERSIZE_SHIFT
#define USB_DOEP_CTL_SNAK
#define USB_DOEP0CTL_CNAK
#define _USB_DOEP0TSIZ_SUPCNT_SHIFT
#define USB_DOEP_CTL_USBACTEP
#define USB_DOEP_CTL_EPENA
#define _USB_DOEP0TSIZ_PKTCNT_SHIFT
USB_Status_TypeDef
USB transfer status enumerator.
#define _USB_DCFG_DEVADDR_SHIFT
#define USB_GINTMSK_SOFMSK
#define _USB_HPRT_PRTSPD_MASK
#define USB_GRSTCTL_TXFFLSH
#define USB_GRSTCTL_RXFFLSH
#define USB_GINTMSK_HCHINTMSK
#define USB_GINTMSK_ENUMDONEMSK
#define USB_GINTMSK_USBRSTMSK
#define USB_DIEP_CTL_SNAK
#define USB_HC_CHAR_CHENA
#define _USB_DIEP_CTL_EPTYPE_SHIFT
#define USB_GAHBCFG_GLBLINTRMSK
USB protocol stack library API for EFM32/EZR32.
#define USB_DIEP0CTL_CNAK
#define _USB_DOEP_CTL_EPTYPE_SHIFT
#define _USB_HC_CHAR_ODDFRM_MASK
#define USB_DIEP_CTL_STALL
#define USB_STATUS_VREGOS
#define _USB_DIEP_TSIZ_PKTCNT_SHIFT
#define USB_HC_CHAR_ODDFRM
#define USB_DIEP0CTL_EPENA
#define _USB_DIEP_CTL_EPTYPE_MASK
#define USB_DIEP_CTL_USBACTEP
#define _USB_DAINTMSK_OUTEPMSK0_SHIFT
#define _USB_DOEP_TSIZ_PKTCNT_SHIFT
#define USB_DCTL_RMTWKUPSIG
#define _USB_HPRT_PRTSPD_SHIFT
#define _USB_GRSTCTL_TXFNUM_SHIFT
#define _USB_IEN_RESETVALUE
#define _USB_DOEP0TSIZ_XFERSIZE_SHIFT
#define _USB_DOEP_CTL_MPS_SHIFT
#define USB_GINTMSK_IEPINTMSK
#define USB_HC_CHAR_CHDIS
#define USB_DOEP_CTL_SETD0PIDEF
#define USB_GINTMSK_PRTINTMSK
#define USB_DOEP_CTL_CNAK
#define USB_DCTL_CGNPINNAK
#define USB_DIEP_CTL_SETD0PIDEF
#define _USB_DOEP_TSIZ_XFERSIZE_SHIFT
#define _USB_DCFG_DEVADDR_MASK