EFM32 Happy Gecko Software Documentation  efm32hg-doc-4.2.1
em_usbd.c
Go to the documentation of this file.
1 /**************************************************************************/
16 #include "em_device.h"
17 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
18 #include "em_usb.h"
19 #if defined( USB_DEVICE )
20 
21 #include "em_cmu.h"
22 #include "em_usbtypes.h"
23 #include "em_usbhal.h"
24 #include "em_usbd.h"
25 
28 static USBD_Device_TypeDef device;
29 USBD_Device_TypeDef *dev = &device;
30 
31 static const char *stateNames[] =
32 {
33  [ USBD_STATE_NONE ] = "NONE ",
34  [ USBD_STATE_ATTACHED ] = "ATTACHED ",
35  [ USBD_STATE_POWERED ] = "POWERED ",
36  [ USBD_STATE_DEFAULT ] = "DEFAULT ",
37  [ USBD_STATE_ADDRESSED ] = "ADDRESSED ",
38  [ USBD_STATE_CONFIGURED ] = "CONFIGURED",
39  [ USBD_STATE_SUSPENDED ] = "SUSPENDED ",
40  [ USBD_STATE_LASTMARKER ] = "UNDEFINED "
41 };
42 
45 /***************************************************************************/
54 {
55  INT_Disable();
56  USBDHAL_AbortAllTransfers( USB_STATUS_EP_ABORTED );
57  INT_Enable();
58 }
59 
60 /***************************************************************************/
67 int USBD_AbortTransfer( int epAddr )
68 {
70  USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
71 
72  if ( ep == NULL )
73  {
74  DEBUG_USB_API_PUTS( "\nUSBD_AbortTransfer(), Illegal endpoint" );
75  EFM_ASSERT( false );
76  return USB_STATUS_ILLEGAL;
77  }
78 
79  if ( ep->num == 0 )
80  {
81  DEBUG_USB_API_PUTS( "\nUSBD_AbortTransfer(), Illegal endpoint" );
82  EFM_ASSERT( false );
83  return USB_STATUS_ILLEGAL;
84  }
85 
86  INT_Disable();
87  if ( ep->state == D_EP_IDLE )
88  {
89  INT_Enable();
90  return USB_STATUS_OK;
91  }
92 
93  USBD_AbortEp( ep );
94 
95  ep->state = D_EP_IDLE;
96  if ( ep->xferCompleteCb )
97  {
98  callback = ep->xferCompleteCb;
99  ep->xferCompleteCb = NULL;
100 
101  if ( ( dev->lastState == USBD_STATE_CONFIGURED ) &&
102  ( dev->state == USBD_STATE_ADDRESSED ) )
103  {
104  USBDHAL_DeactivateEp( ep );
105  }
106 
107  DEBUG_TRACE_ABORT( USB_STATUS_EP_ABORTED );
108  callback( USB_STATUS_EP_ABORTED, ep->xferred, ep->remaining );
109  }
110 
111  INT_Enable();
112  return USB_STATUS_OK;
113 }
114 
115 /***************************************************************************/
123 void USBD_Connect( void )
124 {
125  INT_Disable();
126  USBDHAL_Connect();
127  INT_Enable();
128 }
129 
130 /***************************************************************************/
138 void USBD_Disconnect( void )
139 {
140  INT_Disable();
141  USBDHAL_Disconnect();
142  INT_Enable();
143 }
144 
145 /***************************************************************************/
155 bool USBD_EpIsBusy( int epAddr )
156 {
157  USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
158 
159  if ( ep == NULL )
160  {
161  DEBUG_USB_API_PUTS( "\nUSBD_EpIsBusy(), Illegal endpoint" );
162  EFM_ASSERT( false );
163  return USB_STATUS_ILLEGAL;
164  }
165 
166  if ( ep->state == D_EP_IDLE )
167  return false;
168 
169  return true;
170 }
171 
172 /***************************************************************************/
180 {
181  return dev->state;
182 }
183 
184 /***************************************************************************/
195 {
196  if ( state > USBD_STATE_LASTMARKER )
197  state = USBD_STATE_LASTMARKER;
198 
199  return stateNames[ state ];
200 }
201 
202 /***************************************************************************/
219 {
220  int numEps;
221  USBD_Ep_TypeDef *ep;
222  uint8_t txFifoNum;
223  uint8_t *conf, *confEnd;
226  uint32_t totalRxFifoSize, totalTxFifoSize, numInEps, numOutEps;
227 
228 #if !defined( USB_CORECLK_HFRCO ) || !defined( CMU_OSCENCMD_USHFRCOEN )
229  /* Devices supporting crystal-less USB can use HFRCO or HFXO as core clock. */
230  /* All other devices must use HFXO as core clock. */
232  {
234  }
235 #endif
236 
237 #if !defined( CMU_OSCENCMD_USHFRCOEN )
238 #if ( USB_USBC_32kHz_CLK == USB_USBC_32kHz_CLK_LFXO )
239  CMU_OscillatorEnable(cmuOsc_LFXO, true, false);
240 #else
241  CMU_OscillatorEnable(cmuOsc_LFRCO, true, false);
242 #endif
243 
244 #else
246  /* LFC clock is needed to detect USB suspend when LEMIDLE is activated. */
247 #if ( USB_USBC_32kHz_CLK == USB_USBC_32kHz_CLK_LFXO )
249 #else
251 #endif
253 #endif
254 
255  USBTIMER_Init();
256 
257  memset( dev, 0, sizeof( USBD_Device_TypeDef ) );
258 
259  dev->setup = dev->setupPkt;
260  dev->deviceDescriptor = p->deviceDescriptor;
261  dev->configDescriptor = (USB_ConfigurationDescriptor_TypeDef*)
262  p->configDescriptor;
263  dev->stringDescriptors = p->stringDescriptors;
264  dev->numberOfStrings = p->numberOfStrings;
265  dev->state = USBD_STATE_LASTMARKER;
266  dev->savedState = USBD_STATE_NONE;
267  dev->lastState = USBD_STATE_NONE;
268  dev->callbacks = p->callbacks;
269  dev->remoteWakeupEnabled = false;
270 
271  /* Initialize EP0 */
272 
273  ep = &dev->ep[ 0 ];
274  ep->in = false;
275  ep->buf = NULL;
276  ep->num = 0;
277  ep->mask = 1;
278  ep->addr = 0;
279  ep->type = USB_EPTYPE_CTRL;
280  ep->txFifoNum = 0;
281  ep->packetSize = p->deviceDescriptor->bMaxPacketSize0;
282 
283  if ( ep->packetSize == 32 )
284  {
285  dev->ep0MpsCode = _USB_DOEP0CTL_MPS_32B;
286  }
287  else if ( ep->packetSize == 64 )
288  {
289  dev->ep0MpsCode = _USB_DOEP0CTL_MPS_64B;
290  }
291  else
292  {
293  return USB_STATUS_ILLEGAL;
294  }
295 
296  ep->remaining = 0;
297  ep->xferred = 0;
298  ep->state = D_EP_IDLE;
299  ep->xferCompleteCb = NULL;
300  ep->fifoSize = ep->packetSize / 4;
301 
302  totalTxFifoSize = ep->fifoSize * p->bufferingMultiplier[ 0 ];
303  totalRxFifoSize = (ep->fifoSize + 1) * p->bufferingMultiplier[ 0 ];
304 
305 #if defined( DEBUG_USB_API )
306  /* Do a sanity check on the configuration descriptor */
307  {
308  int i;
309 
310  /* Check if bLength's adds up exactly to wTotalLength */
311  i = 0;
312  conf = (uint8_t*)dev->configDescriptor;
313  confEnd = conf + dev->configDescriptor->wTotalLength;
314 
315  while ( conf < confEnd )
316  {
317  if ( *conf == 0 )
318  break;
319 
320  i += *conf;
321  conf += *conf;
322  }
323 
324  if ( ( conf != confEnd ) ||
325  ( i != dev->configDescriptor->wTotalLength ) )
326  {
327  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal configuration descriptor" );
328  EFM_ASSERT( false );
329  return USB_STATUS_ILLEGAL;
330  }
331  }
332 #endif /* defined( DEBUG_USB_API ) */
333 
334  /* Parse configuration decriptor */
335  numEps = 0;
336  numInEps = 0;
337  numOutEps = 0;
338  conf = (uint8_t*)dev->configDescriptor;
339  confEnd = conf + dev->configDescriptor->wTotalLength;
340 
341  txFifoNum = 1;
342  while ( conf < confEnd )
343  {
344  if ( *conf == 0 )
345  {
346  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal configuration descriptor" );
347  EFM_ASSERT( false );
348  return USB_STATUS_ILLEGAL;
349  }
350 
351  if ( *(conf + 1) == USB_ENDPOINT_DESCRIPTOR )
352  {
353  numEps++;
354  epd = (USB_EndpointDescriptor_TypeDef*)conf;
355 
356 #if defined( __GNUC__ )
357 #pragma GCC diagnostic push
358 #pragma GCC diagnostic ignored "-Warray-bounds"
359 #endif
360  ep = &dev->ep[ numEps ];
361 #if defined( __GNUC__ )
362 #pragma GCC diagnostic pop
363 #endif
364 
365  ep->in = ( epd->bEndpointAddress & USB_SETUP_DIR_MASK ) != 0;
366  ep->buf = NULL;
367  ep->addr = epd->bEndpointAddress;
368  ep->num = ep->addr & USB_EPNUM_MASK;
369  ep->mask = 1 << ep->num;
370  ep->type = epd->bmAttributes & CONFIG_DESC_BM_TRANSFERTYPE;
371  ep->packetSize = epd->wMaxPacketSize;
372  ep->remaining = 0;
373  ep->xferred = 0;
374  ep->state = D_EP_IDLE;
375  ep->xferCompleteCb = NULL;
376 
377  if ( p->bufferingMultiplier[ numEps ] == 0 )
378  {
379  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal EP fifo buffer configuration" );
380  EFM_ASSERT( false );
381  return USB_STATUS_ILLEGAL;
382  }
383 
384  if ( ep->in )
385  {
386  numInEps++;
387  ep->txFifoNum = txFifoNum++;
388  ep->fifoSize = ( ( ep->packetSize + 3 ) / 4 )
389  * p->bufferingMultiplier[ numEps ];
390  dev->inEpAddr2EpIndex[ ep->num ] = numEps;
391  totalTxFifoSize += ep->fifoSize;
392  if ( ep->num > MAX_NUM_IN_EPS )
393  {
394  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal IN EP address" );
395  EFM_ASSERT( false );
396  return USB_STATUS_ILLEGAL;
397  }
398  }
399  else
400  {
401  numOutEps++;
402  ep->fifoSize = ( ( ( ep->packetSize + 3 ) / 4 ) + 1 )
403  * p->bufferingMultiplier[ numEps ];
404  dev->outEpAddr2EpIndex[ ep->num ] = numEps;
405  totalRxFifoSize += ep->fifoSize;
406  if ( ep->num > MAX_NUM_OUT_EPS )
407  {
408  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal OUT EP address" );
409  EFM_ASSERT( false );
410  return USB_STATUS_ILLEGAL;
411  }
412  }
413  }
414  else if ( *(conf + 1) == USB_INTERFACE_DESCRIPTOR )
415  {
417 
418  if ( id->bAlternateSetting == 0 ) // Only check default interfaces
419  {
420  if ( dev->numberOfInterfaces != id->bInterfaceNumber )
421  {
422  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal interface number" );
423  EFM_ASSERT( false );
424  return USB_STATUS_ILLEGAL;
425  }
426  dev->numberOfInterfaces++;
427  }
428  }
429 
430  conf += *conf;
431  }
432 
433  /* Rx-FIFO size: SETUP packets : 4*n + 6 n=#CTRL EP's
434  * GOTNAK : 1
435  * Status info : 2*n n=#OUT EP's (EP0 included) in HW
436  */
437  totalRxFifoSize += 10 + 1 + ( 2 * (MAX_NUM_OUT_EPS + 1) );
438 
439  if ( dev->configDescriptor->bNumInterfaces != dev->numberOfInterfaces )
440  {
441  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal interface count" );
442  EFM_ASSERT( false );
443  return USB_STATUS_ILLEGAL;
444  }
445 
446  if ( numEps != NUM_EP_USED )
447  {
448  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal EP count" );
449  EFM_ASSERT( false );
450  return USB_STATUS_ILLEGAL;
451  }
452 
453  if ( numInEps > MAX_NUM_IN_EPS )
454  {
455  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal IN EP count" );
456  EFM_ASSERT( false );
457  return USB_STATUS_ILLEGAL;
458  }
459 
460  if ( numOutEps > MAX_NUM_OUT_EPS )
461  {
462  DEBUG_USB_API_PUTS( "\nUSBD_Init(), Illegal OUT EP count" );
463  EFM_ASSERT( false );
464  return USB_STATUS_ILLEGAL;
465  }
466 
467  INT_Disable();
468 
469  /* Enable USB clock */
471 
472 #if defined( CMU_OSCENCMD_USHFRCOEN )
473  CMU->USHFRCOCONF = CMU_USHFRCOCONF_BAND_48MHZ;
475 
476  /* Enable USHFRCO Clock Recovery mode. */
477  CMU->USBCRCTRL |= CMU_USBCRCTRL_EN;
478 
479  /* Turn on Low Energy Mode (LEM) features. */
483 #else
485 #endif
486 
487  USBHAL_DisableGlobalInt();
488 
489  if ( USBDHAL_CoreInit( totalRxFifoSize, totalTxFifoSize ) == USB_STATUS_OK )
490  {
491  USBDHAL_EnableUsbResetAndSuspendInt();
492  USBHAL_EnableGlobalInt();
493  NVIC_ClearPendingIRQ( USB_IRQn );
494  NVIC_EnableIRQ( USB_IRQn );
495  }
496  else
497  {
498  INT_Enable();
499  DEBUG_USB_API_PUTS( "\nUSBD_Init(), FIFO setup error" );
500  EFM_ASSERT( false );
501  return USB_STATUS_ILLEGAL;
502  }
503 
504 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF )
505  if ( USBHAL_VbusIsOn() )
506  {
507  USBD_SetUsbState( USBD_STATE_POWERED );
508  }
509  else
510 #endif
511  {
512  USBD_SetUsbState( USBD_STATE_NONE );
513  }
514 
515  INT_Enable();
516  return USB_STATUS_OK;
517 }
518 
519 /***************************************************************************/
545 int USBD_Read( int epAddr, void *data, int byteCount,
546  USB_XferCompleteCb_TypeDef callback )
547 {
548  USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
549 
550  if ( ep == NULL )
551  {
552  DEBUG_USB_API_PUTS( "\nUSBD_Read(), Illegal endpoint" );
553  EFM_ASSERT( false );
554  return USB_STATUS_ILLEGAL;
555  }
556 
557  if ( ( byteCount > MAX_XFER_LEN ) ||
558  ( ( byteCount / ep->packetSize ) > MAX_PACKETS_PR_XFER ) )
559  {
560  DEBUG_USB_API_PUTS( "\nUSBD_Read(), Illegal transfer size" );
561  EFM_ASSERT( false );
562  return USB_STATUS_ILLEGAL;
563  }
564 
565  if ( (uint32_t)data & 3 )
566  {
567  DEBUG_USB_API_PUTS( "\nUSBD_Read(), Misaligned data buffer" );
568  EFM_ASSERT( false );
569  return USB_STATUS_ILLEGAL;
570  }
571 
572  INT_Disable();
573  if ( USBDHAL_EpIsStalled( ep ) )
574  {
575  INT_Enable();
576  DEBUG_USB_API_PUTS( "\nUSBD_Read(), Endpoint is halted" );
577  return USB_STATUS_EP_STALLED;
578  }
579 
580  if ( ep->state != D_EP_IDLE )
581  {
582  INT_Enable();
583  DEBUG_USB_API_PUTS( "\nUSBD_Read(), Endpoint is busy" );
584  return USB_STATUS_EP_BUSY;
585  }
586 
587  if ( ( ep->num > 0 ) && ( USBD_GetUsbState() != USBD_STATE_CONFIGURED ) )
588  {
589  INT_Enable();
590  DEBUG_USB_API_PUTS( "\nUSBD_Read(), Device not configured" );
592  }
593 
594  ep->buf = (uint8_t*)data;
595  ep->remaining = byteCount;
596  ep->xferred = 0;
597 
598  if ( ep->num == 0 )
599  {
600  ep->in = false;
601  }
602  else if ( ep->in != false )
603  {
604  INT_Enable();
605  DEBUG_USB_API_PUTS( "\nUSBD_Read(), Illegal EP direction" );
606  EFM_ASSERT( false );
607  return USB_STATUS_ILLEGAL;
608  }
609 
610  ep->state = D_EP_RECEIVING;
611  ep->xferCompleteCb = callback;
612 
613  USBD_ArmEp( ep );
614  INT_Enable();
615  return USB_STATUS_OK;
616 }
617 
618 /***************************************************************************/
631 int USBD_RemoteWakeup( void )
632 {
633  INT_Disable();
634 
635  if ( ( dev->state != USBD_STATE_SUSPENDED ) ||
636  ( dev->remoteWakeupEnabled == false ) )
637  {
638  INT_Enable();
639  DEBUG_USB_API_PUTS( "\nUSBD_RemoteWakeup(), Illegal remote wakeup" );
640  return USB_STATUS_ILLEGAL;
641  }
642 
643  USBDHAL_SetRemoteWakeup();
644  INT_Enable();
645  USBTIMER_DelayMs( 10 );
646  INT_Disable();
647  USBDHAL_ClearRemoteWakeup();
648  INT_Enable();
649  return USB_STATUS_OK;
650 }
651 
652 /***************************************************************************/
666 {
667 #if ( USB_PWRSAVE_MODE )
668  return USBD_poweredDown ? true : false;
669 #else
670  return false;
671 #endif
672 }
673 
676 void USBD_SetUsbState( USBD_State_TypeDef newState )
677 {
678  USBD_State_TypeDef currentState;
679 
680  currentState = dev->state;
681  if ( newState == USBD_STATE_SUSPENDED )
682  {
683  dev->savedState = currentState;
684  }
685 
686  dev->lastState = dev->state;
687  dev->state = newState;
688 
689  if ( ( dev->callbacks->usbStateChange ) &&
690  ( currentState != newState ) )
691  {
692  dev->callbacks->usbStateChange( currentState, newState );
693  }
694 }
695 
698 /***************************************************************************/
708 int USBD_StallEp( int epAddr )
709 {
710  USB_Status_TypeDef retVal;
711  USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
712 
713  if ( ep == NULL )
714  {
715  DEBUG_USB_API_PUTS( "\nUSBD_StallEp(), Illegal request" );
716  EFM_ASSERT( false );
717  return USB_STATUS_ILLEGAL;
718  }
719 
720  if ( ep->num == 0 )
721  {
722  DEBUG_USB_API_PUTS( "\nUSBD_StallEp(), Illegal endpoint" );
723  EFM_ASSERT( false );
724  return USB_STATUS_ILLEGAL;
725  }
726 
727  INT_Disable();
728  retVal = USBDHAL_StallEp( ep );
729  INT_Enable();
730 
731  if ( retVal != USB_STATUS_OK )
732  {
733  retVal = USB_STATUS_ILLEGAL;
734  }
735 
736  return retVal;
737 }
738 
739 /***************************************************************************/
747 void USBD_Stop( void )
748 {
749  USBD_Disconnect();
750  NVIC_DisableIRQ( USB_IRQn );
751  USBHAL_DisableGlobalInt();
752  USBHAL_DisableUsbInt();
753  USBHAL_DisablePhyPins();
754  USBD_SetUsbState( USBD_STATE_NONE );
755  /* Turn off USB clocks. */
756  CMU->HFCORECLKEN0 &= ~(CMU_HFCORECLKEN0_USB | CMU_HFCORECLKEN0_USBC);
757 }
758 
759 /***************************************************************************/
769 int USBD_UnStallEp( int epAddr )
770 {
771  USB_Status_TypeDef retVal;
772  USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
773 
774  if ( ep == NULL )
775  {
776  DEBUG_USB_API_PUTS( "\nUSBD_UnStallEp(), Illegal request" );
777  EFM_ASSERT( false );
778  return USB_STATUS_ILLEGAL;
779  }
780 
781  if ( ep->num == 0 )
782  {
783  DEBUG_USB_API_PUTS( "\nUSBD_UnStallEp(), Illegal endpoint" );
784  EFM_ASSERT( false );
785  return USB_STATUS_ILLEGAL;
786  }
787 
788  INT_Disable();
789  retVal = USBDHAL_UnStallEp( ep );
790  INT_Enable();
791 
792  if ( retVal != USB_STATUS_OK )
793  {
794  retVal = USB_STATUS_ILLEGAL;
795  }
796 
797  return retVal;
798 }
799 
800 /***************************************************************************/
820 int USBD_Write( int epAddr, void *data, int byteCount,
821  USB_XferCompleteCb_TypeDef callback )
822 {
823  USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
824 
825  if ( ep == NULL )
826  {
827  DEBUG_USB_API_PUTS( "\nUSBD_Write(), Illegal endpoint" );
828  EFM_ASSERT( false );
829  return USB_STATUS_ILLEGAL;
830  }
831 
832  if ( ( byteCount > MAX_XFER_LEN ) ||
833  ( ( byteCount / ep->packetSize ) > MAX_PACKETS_PR_XFER ) )
834  {
835  DEBUG_USB_API_PUTS( "\nUSBD_Write(), Illegal transfer size" );
836  EFM_ASSERT( false );
837  return USB_STATUS_ILLEGAL;
838  }
839 
840  if ( (uint32_t)data & 3 )
841  {
842  DEBUG_USB_API_PUTS( "\nUSBD_Write(), Misaligned data buffer" );
843  EFM_ASSERT( false );
844  return USB_STATUS_ILLEGAL;
845  }
846 
847  INT_Disable();
848  if ( USBDHAL_EpIsStalled( ep ) )
849  {
850  INT_Enable();
851  DEBUG_USB_API_PUTS( "\nUSBD_Write(), Endpoint is halted" );
852  return USB_STATUS_EP_STALLED;
853  }
854 
855  if ( ep->state != D_EP_IDLE )
856  {
857  INT_Enable();
858  DEBUG_USB_API_PUTS( "\nUSBD_Write(), Endpoint is busy" );
859  return USB_STATUS_EP_BUSY;
860  }
861 
862  if ( ( ep->num > 0 ) && ( USBD_GetUsbState() != USBD_STATE_CONFIGURED ) )
863  {
864  INT_Enable();
865  DEBUG_USB_API_PUTS( "\nUSBD_Write(), Device not configured" );
867  }
868 
869  ep->buf = (uint8_t*)data;
870  ep->remaining = byteCount;
871  ep->xferred = 0;
872 
873  if ( ep->num == 0 )
874  {
875  ep->in = true;
876  }
877  else if ( ep->in != true )
878  {
879  INT_Enable();
880  DEBUG_USB_API_PUTS( "\nUSBD_Write(), Illegal EP direction" );
881  EFM_ASSERT( false );
882  return USB_STATUS_ILLEGAL;
883  }
884 
885  ep->state = D_EP_TRANSMITTING;
886  ep->xferCompleteCb = callback;
887 
888  USBD_ArmEp( ep );
889  INT_Enable();
890  return USB_STATUS_OK;
891 }
892 
893 /******** THE REST OF THE FILE IS DOCUMENTATION ONLY !**********************/
1392 #endif /* defined( USB_DEVICE ) */
1393 #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
USB protocol stack library API for EFM32/EZR32.
Clock management unit (CMU) API.
void CMU_ClockSelectSet(CMU_Clock_TypeDef clock, CMU_Select_TypeDef ref)
Select reference clock/oscillator used for a clock branch.
Definition: em_cmu.c:2406
const uint8_t * bufferingMultiplier
Definition: em_usb.h:782
#define CMU_HFCORECLKEN0_USB
Definition: efm32hg_cmu.h:892
#define USB_EPNUM_MASK
Definition: em_usb.h:179
USB Device stack initialization structure.
Definition: em_usb.h:776
#define USB
__STATIC_INLINE uint32_t INT_Enable(void)
Enable interrupts.
Definition: em_int.h:94
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define USB_SETUP_DIR_MASK
Definition: em_usb.h:60
const USB_DeviceDescriptor_TypeDef * deviceDescriptor
Definition: em_usb.h:778
void USBD_Connect(void)
Start USB device operation.
Definition: em_usbd.c:123
void USBTIMER_DelayMs(uint32_t msec)
Active wait millisecond delay function. Can also be used inside interrupt handlers.
Definition: em_usbtimer.c:135
USB Interface Descriptor.
Definition: em_usb.h:457
int USBD_Init(const USBD_Init_TypeDef *p)
Initializes USB device hardware and internal protocol stack data structures, then connects the data-l...
Definition: em_usbd.c:218
USBD_State_TypeDef
USB device state enumerator.
Definition: em_usb.h:356
int(* USB_XferCompleteCb_TypeDef)(USB_Status_TypeDef status, uint32_t xferred, uint32_t remaining)
USB transfer callback function.
Definition: em_usb.h:663
void USBD_AbortAllTransfers(void)
Abort all pending transfers.
Definition: em_usbd.c:53
USB_Status_TypeDef
USB transfer status enumerator.
Definition: em_usb.h:316
const uint8_t * configDescriptor
Definition: em_usb.h:779
const void *const * stringDescriptors
Definition: em_usb.h:780
#define USB_EPTYPE_CTRL
Definition: em_usb.h:169
int USBD_AbortTransfer(int epAddr)
Abort a pending transfer on a specific endpoint.
Definition: em_usbd.c:67
#define _USB_DOEP0CTL_MPS_32B
Definition: efm32hg_usb.h:1419
#define CONFIG_DESC_BM_TRANSFERTYPE
Definition: em_usb.h:186
USB protocol stack library API for EFM32/EZR32.
USB Endpoint Descriptor.
Definition: em_usb.h:498
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
Definition: em_cmu.c:1369
USBD_Callbacks_TypeDef_Pointer callbacks
Definition: em_usb.h:787
#define CMU_HFCORECLKEN0_USBC
Definition: efm32hg_cmu.h:887
int USBD_RemoteWakeup(void)
Perform a remote wakeup signalling sequence.
Definition: em_usbd.c:631
int USBD_StallEp(int epAddr)
Set an endpoint in the stalled (halted) state.
Definition: em_usbd.c:708
#define CMU_USBCRCTRL_EN
Definition: efm32hg_cmu.h:1146
USBD_State_TypeDef USBD_GetUsbState(void)
Get current USB device state.
Definition: em_usbd.c:179
#define USB_INTERFACE_DESCRIPTOR
Definition: em_usb.h:120
#define USB_CTRL_LEMIDLEEN
Definition: efm32hg_usb.h:161
void CMU_OscillatorEnable(CMU_Osc_TypeDef osc, bool enable, bool wait)
Enable/disable oscillator.
Definition: em_cmu.c:3394
int USBD_Write(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a write (IN) transfer on an endpoint.
Definition: em_usbd.c:820
int USBD_UnStallEp(int epAddr)
Reset stall state on a stalled (halted) endpoint.
Definition: em_usbd.c:769
const uint8_t numberOfStrings
Definition: em_usb.h:781
void USBD_Stop(void)
Stop USB device stack operation.
Definition: em_usbd.c:747
#define USB_CTRL_LEMOSCCTRL_GATE
Definition: efm32hg_usb.h:149
USB protocol stack library, low level USB peripheral access.
void USBD_Disconnect(void)
Stop USB device operation.
Definition: em_usbd.c:138
void USBTIMER_Init(void)
Activate the hardware timer used to pace the 1 millisecond timer system.
Definition: em_usbtimer.c:190
USB Configuration Descriptor.
Definition: em_usb.h:428
#define CMU_USHFRCOCONF_BAND_48MHZ
Definition: efm32hg_cmu.h:1196
#define USB_CTRL_LEMPHYCTRL
Definition: efm32hg_usb.h:152
const char * USBD_GetUsbStateName(USBD_State_TypeDef state)
Get a string naming a device USB state.
Definition: em_usbd.c:194
#define _USB_DOEP0CTL_MPS_64B
Definition: efm32hg_usb.h:1418
__STATIC_INLINE uint32_t INT_Disable(void)
Disable interrupts.
Definition: em_int.h:71
USB protocol stack library, internal type definitions.
bool USBD_SafeToEnterEM2(void)
Check if it is ok to enter energy mode EM2.
Definition: em_usbd.c:665
#define USB_ENDPOINT_DESCRIPTOR
Definition: em_usb.h:121
bool USBD_EpIsBusy(int epAddr)
Check if an endpoint is busy doing a transfer.
Definition: em_usbd.c:155
#define CMU
int USBD_Read(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a read (OUT) transfer on an endpoint.
Definition: em_usbd.c:545
CMU_Select_TypeDef CMU_ClockSelectGet(CMU_Clock_TypeDef clock)
Get currently selected reference clock used for a clock branch.
Definition: em_cmu.c:2048