APM:Libraries
usb_dcd_int.c
Go to the documentation of this file.
1 
28 //#pragma GCC optimize ("Og")
29 
30 /* Includes ------------------------------------------------------------------*/
31 #include "usb_dcd_int.h"
78 /* static functions */
79 static uint32_t DCD_ReadDevInEP (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum);
80 
81 /* Interrupt Handlers */
82 static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev);
83 static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev);
84 static uint32_t DCD_HandleSof_ISR(USB_OTG_CORE_HANDLE *pdev);
85 
87 static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev , uint32_t epnum);
88 
89 static uint32_t DCD_HandleUsbReset_ISR(USB_OTG_CORE_HANDLE *pdev);
90 static uint32_t DCD_HandleEnumDone_ISR(USB_OTG_CORE_HANDLE *pdev);
91 static uint32_t DCD_HandleResume_ISR(USB_OTG_CORE_HANDLE *pdev);
92 static uint32_t DCD_HandleUSBSuspend_ISR(USB_OTG_CORE_HANDLE *pdev);
93 
94 static uint32_t DCD_IsoINIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev);
95 static uint32_t DCD_IsoOUTIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev);
96 #ifdef VBUS_SENSING_ENABLED
97 static uint32_t DCD_SessionRequest_ISR(USB_OTG_CORE_HANDLE *pdev);
98 static uint32_t DCD_OTG_ISR(USB_OTG_CORE_HANDLE *pdev);
99 #endif
100 
111 #ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
112 
118 uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
119 {
120 
121  USB_OTG_DOEPINTn_TypeDef doepint;
122  USB_OTG_DEPXFRSIZ_TypeDef deptsiz;
123 
124  doepint.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[1]->DOEPINT);
125  doepint.d32&= USB_OTG_READ_REG32(&pdev->regs.DREGS->DOUTEP1MSK);
126 
127  /* Transfer complete */
128  if ( doepint.b.xfercompl )
129  {
130  /* Clear the bit in DOEPINTn for this interrupt */
131  CLEAR_OUT_EP_INTR(1, xfercompl);
132  if (pdev->cfg.dma_enable == 1)
133  {
134  deptsiz.d32 = USB_OTG_READ_REG32(&(pdev->regs.OUTEP_REGS[1]->DOEPTSIZ));
135  /*ToDo : handle more than one single MPS size packet */
136  pdev->dev.out_ep[1].xfer_count = pdev->dev.out_ep[1].maxpacket - \
137  deptsiz.b.xfersize;
138  }
139  /* Inform upper layer: data ready */
140  /* RX COMPLETE */
141  USBD_DCD_INT_fops->DataOutStage(pdev , 1);
142 
143  }
144 
145  /* Endpoint disable */
146  if ( doepint.b.epdisabled )
147  {
148  /* Clear the bit in DOEPINTn for this interrupt */
149  CLEAR_OUT_EP_INTR(1, epdisabled);
150  }
151 
152  return 1;
153 }
154 
161 uint32_t USBD_OTG_EP1IN_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
162 {
163 
164  USB_OTG_DIEPINTn_TypeDef diepint;
165  uint32_t fifoemptymsk, msk, emp;
166 
167  msk = USB_OTG_READ_REG32(&pdev->regs.DREGS->DINEP1MSK);
168  emp = USB_OTG_READ_REG32(&pdev->regs.DREGS->DIEPEMPMSK);
169  msk |= ((emp >> 1 ) & 0x1) << 7;
170  diepint.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[1]->DIEPINT) & msk;
171 
172  if ( diepint.b.xfercompl )
173  {
174  fifoemptymsk = 0x1 << 1;
175  USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);
176  CLEAR_IN_EP_INTR(1, xfercompl);
177  /* TX COMPLETE */
178  USBD_DCD_INT_fops->DataInStage(pdev , 1);
179  }
180  if ( diepint.b.epdisabled )
181  {
182  CLEAR_IN_EP_INTR(1, epdisabled);
183  }
184  if ( diepint.b.timeout )
185  {
186  CLEAR_IN_EP_INTR(1, timeout);
187  }
188  if (diepint.b.intktxfemp)
189  {
190  CLEAR_IN_EP_INTR(1, intktxfemp);
191  }
192  if (diepint.b.inepnakeff)
193  {
194  CLEAR_IN_EP_INTR(1, inepnakeff);
195  }
196  if (diepint.b.emptyintr)
197  {
198  DCD_WriteEmptyTxFifo(pdev , 1);
199  CLEAR_IN_EP_INTR(1, emptyintr);
200  }
201  return 1;
202 }
203 #endif
204 
212 {
213  USB_OTG_GINTSTS_TypeDef gintr_status;
214  uint32_t retval = 0;
215 
216  if (USB_OTG_IsDeviceMode(pdev)) { /* ensure that we are in device mode */
217  gintr_status.d32 = USB_OTG_ReadCoreItr(pdev);
218 
219 //40000
220  if (!gintr_status.d32) /* avoid spurious interrupt */
221  {
222  return 0;
223  }
224 
225  if (gintr_status.b.outepintr)
226  {
227  retval |= DCD_HandleOutEP_ISR(pdev);
228  }
229 
230  if (gintr_status.b.inepint)
231  {
232  retval |= DCD_HandleInEP_ISR(pdev);
233  }
234 
235  if (gintr_status.b.modemismatch)
236  {
237  USB_OTG_GINTSTS_TypeDef gintsts;
238 
239  /* Clear interrupt */
240  gintsts.d32 = 0;
241  gintsts.b.modemismatch = 1;
242  USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
243  }
244 
245  if (gintr_status.b.wkupintr)
246  {
247  retval |= DCD_HandleResume_ISR(pdev);
248  }
249 
250  if (gintr_status.b.usbsuspend)
251  {
252  retval |= DCD_HandleUSBSuspend_ISR(pdev);
253  }
254 
255  if (gintr_status.b.sofintr)
256  {
257  retval |= DCD_HandleSof_ISR(pdev);
258 
259  }
260 
261  if (gintr_status.b.rxstsqlvl)
262  {
263  retval |= DCD_HandleRxStatusQueueLevel_ISR(pdev);
264 
265  }
266 
267  if (gintr_status.b.usbreset)
268  {
269  retval |= DCD_HandleUsbReset_ISR(pdev);
270 
271  }
272  if (gintr_status.b.enumdone)
273  {
274  retval |= DCD_HandleEnumDone_ISR(pdev);
275  }
276 
277  if (gintr_status.b.incomplisoin)
278  {
279  retval |= DCD_IsoINIncomplete_ISR(pdev);
280  }
281 
282  if (gintr_status.b.incomplisoout)
283  {
284  retval |= DCD_IsoOUTIncomplete_ISR(pdev);
285  }
286 #ifdef VBUS_SENSING_ENABLED
287  if (gintr_status.b.sessreqintr)
288  {
289  retval |= DCD_SessionRequest_ISR(pdev);
290  }
291 
292  if (gintr_status.b.otgintr)
293  {
294  retval |= DCD_OTG_ISR(pdev);
295  }
296 #endif
297  } // not device mode - don't do anything BUGBUGBUG!!! We MUST clear all available sources of interrupt or program will hang
298  else { //[ @NG
299 #define USB_OTG_GAHBCFG_GINT_Pos (0U)
300 #define USB_OTG_GAHBCFG_GINT_Msk (0x1U << USB_OTG_GAHBCFG_GINT_Pos)
301 #define USB_OTG_GAHBCFG_GINT USB_OTG_GAHBCFG_GINT_Msk
302  *(__IO uint32_t *)(&pdev->regs.GREGS->GAHBCFG) &= USB_OTG_GAHBCFG_GINT; // disable global interrupt - from F4 Arduino
303 
304  /* Clear ALL interrupts */
305  USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, 0xffffffff);
306 /*
307  USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGINT, 0xffffffff);
308 
309  USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DAINT, 0xffffffff);
310  USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DEACHINT, 0xffffffff);
311 
312  USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HFIR, 0xffffffff);
313 
314  uint8_t i;
315  for(i=0;i<USB_OTG_MAX_TX_FIFOS; i++){
316  USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[i]->DIEPINT, 0xffffffff);
317  USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[i]->DOEPINT, 0xffffffff);
318  USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[i]->HCINT, 0xffffffff);
319  }
320 */
321  } //]
322 
323  return retval;
324 }
325 
326 #ifdef VBUS_SENSING_ENABLED
327 
333 static uint32_t DCD_SessionRequest_ISR(USB_OTG_CORE_HANDLE *pdev)
334 {
335  USB_OTG_GINTSTS_TypeDef gintsts;
337 
338  /* Clear interrupt */
339  gintsts.d32 = 0;
340  gintsts.b.sessreqintr = 1;
341  USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32);
342  return 1;
343 }
344 
352 static uint32_t DCD_OTG_ISR(USB_OTG_CORE_HANDLE *pdev)
353 {
354 
355  USB_OTG_GOTGINT_TypeDef gotgint;
356 
357  gotgint.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGINT);
358 
359  if (gotgint.b.sesenddet)
360  {
362  }
363  /* Clear OTG interrupt */
364  USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGINT, gotgint.d32);
365  return 1;
366 }
367 #endif
368 
376 {
377  USB_OTG_GINTSTS_TypeDef gintsts;
378  USB_OTG_DCTL_TypeDef devctl;
380 
381  if(pdev->cfg.low_power)
382  {
383  /* un-gate USB Core clock */
384  power.d32 = USB_OTG_READ_REG32(&pdev->regs.PCGCCTL);
385  power.b.gatehclk = 0;
386  power.b.stoppclk = 0;
387  USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
388  }
389 
390  /* Clear the Remote Wake-up Signaling */
391  devctl.d32 = 0;
392  devctl.b.rmtwkupsig = 1;
393  USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, devctl.d32, 0);
394 
395  /* Inform upper layer by the Resume Event */
396  USBD_DCD_INT_fops->Resume (pdev);
397 
398  /* Clear interrupt */
399  gintsts.d32 = 0;
400  gintsts.b.wkupintr = 1;
401  USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32);
402  return 1;
403 }
404 
412 {
413  USB_OTG_GINTSTS_TypeDef gintsts;
416  __IO uint8_t prev_status = 0;
417 
418  prev_status = pdev->dev.device_status;
419  USBD_DCD_INT_fops->Suspend (pdev);
420 
421  dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS);
422 
423  /* Clear interrupt */
424  gintsts.d32 = 0;
425  gintsts.b.usbsuspend = 1;
426  USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
427 
428  if((pdev->cfg.low_power) && (dsts.b.suspsts == 1) &&
429  (pdev->dev.connection_status == 1) &&
430  (prev_status == USB_OTG_CONFIGURED))
431  {
432  /* switch-off the clocks */
433  power.d32 = 0;
434  power.b.stoppclk = 1;
435  USB_OTG_MODIFY_REG32(pdev->regs.PCGCCTL, 0, power.d32);
436 
437  power.b.gatehclk = 1;
438  USB_OTG_MODIFY_REG32(pdev->regs.PCGCCTL, 0, power.d32);
439 
440  /* Request to enter Sleep mode after exit from current ISR */
441  SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk);
442  }
443  return 1;
444 }
445 
453 {
454  USB_OTG_DIEPINTn_TypeDef diepint;
455 
456  uint32_t ep_intr;
457  uint32_t epnum = 0;
458  uint32_t fifoemptymsk;
459  diepint.d32 = 0;
460  ep_intr = USB_OTG_ReadDevAllInEPItr(pdev);
461 
462  while ( ep_intr )
463  {
464  if (ep_intr&0x1) /* In ITR */
465  {
466  diepint.d32 = DCD_ReadDevInEP(pdev , epnum); /* Get In ITR status */
467  if ( diepint.b.xfercompl )
468  {
469  fifoemptymsk = 0x1 << epnum;
470  USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);
471  CLEAR_IN_EP_INTR(epnum, xfercompl);
472  /* TX COMPLETE */
473  USBD_DCD_INT_fops->DataInStage(pdev , epnum);
474 
475  if (pdev->cfg.dma_enable == 1)
476  {
477  if((epnum == 0) && (pdev->dev.device_state == USB_OTG_EP0_STATUS_IN))
478  {
479  /* prepare to rx more setup packets */
480  USB_OTG_EP0_OutStart(pdev);
481  }
482  }
483  }
484  if ( diepint.b.timeout )
485  {
486  CLEAR_IN_EP_INTR(epnum, timeout);
487  }
488  if (diepint.b.intktxfemp)
489  {
490  CLEAR_IN_EP_INTR(epnum, intktxfemp);
491  }
492  if (diepint.b.inepnakeff)
493  {
494  CLEAR_IN_EP_INTR(epnum, inepnakeff);
495  }
496  if ( diepint.b.epdisabled )
497  {
498  CLEAR_IN_EP_INTR(epnum, epdisabled);
499  }
500  if (diepint.b.emptyintr)
501  {
502 
503  DCD_WriteEmptyTxFifo(pdev , epnum);
504 
505  CLEAR_IN_EP_INTR(epnum, emptyintr);
506  }
507  }
508  epnum++;
509  ep_intr >>= 1;
510  }
511 
512  return 1;
513 }
514 
522 {
523  uint32_t ep_intr;
524  USB_OTG_DOEPINTn_TypeDef doepint;
526  uint32_t epnum = 0;
527 
528  doepint.d32 = 0;
529 
530  /* Read in the device interrupt bits */
531  ep_intr = USB_OTG_ReadDevAllOutEp_itr(pdev);
532 
533  while ( ep_intr )
534  {
535  if (ep_intr&0x1)
536  {
537 
538  doepint.d32 = USB_OTG_ReadDevOutEP_itr(pdev, epnum);
539 
540  /* Transfer complete */
541  if ( doepint.b.xfercompl )
542  {
543  /* Clear the bit in DOEPINTn for this interrupt */
544  CLEAR_OUT_EP_INTR(epnum, xfercompl);
545  if (pdev->cfg.dma_enable == 1)
546  {
547  deptsiz.d32 = USB_OTG_READ_REG32(&(pdev->regs.OUTEP_REGS[epnum]->DOEPTSIZ));
548  /*ToDo : handle more than one single MPS size packet */
549  pdev->dev.out_ep[epnum].xfer_count = pdev->dev.out_ep[epnum].maxpacket - \
550  deptsiz.b.xfersize;
551  }
552  /* Inform upper layer: data ready */
553  /* RX COMPLETE */
554  USBD_DCD_INT_fops->DataOutStage(pdev , epnum);
555 
556  if (pdev->cfg.dma_enable == 1)
557  {
558  if((epnum == 0) && (pdev->dev.device_state == USB_OTG_EP0_STATUS_OUT))
559  {
560  /* prepare to rx more setup packets */
561  USB_OTG_EP0_OutStart(pdev);
562  }
563  }
564  }
565  /* Endpoint disable */
566  if ( doepint.b.epdisabled )
567  {
568  /* Clear the bit in DOEPINTn for this interrupt */
569  CLEAR_OUT_EP_INTR(epnum, epdisabled);
570  }
571  /* Setup Phase Done (control EPs) */
572  if ( doepint.b.setup )
573  {
574 
575  /* inform the upper layer that a setup packet is available */
576  /* SETUP COMPLETE */
578  CLEAR_OUT_EP_INTR(epnum, setup);
579  }
580  }
581  epnum++;
582  ep_intr >>= 1;
583  }
584  return 1;
585 }
586 
594 {
595  USB_OTG_GINTSTS_TypeDef GINTSTS;
596 
597 
598  USBD_DCD_INT_fops->SOF(pdev);
599 
600  /* Clear interrupt */
601  GINTSTS.d32 = 0;
602  GINTSTS.b.sofintr = 1;
603  USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, GINTSTS.d32);
604 
605  return 1;
606 }
607 
615 {
616  USB_OTG_GINTMSK_TypeDef int_mask;
617  USB_OTG_DRXSTS_TypeDef status;
618  USB_OTG_EP *ep;
619 
620  /* Disable the Rx Status Queue Level interrupt */
621  int_mask.d32 = 0;
622  int_mask.b.rxstsqlvl = 1;
623  USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, int_mask.d32, 0);
624 
625  /* Get the Status from the top of the FIFO */
626  status.d32 = USB_OTG_READ_REG32( &pdev->regs.GREGS->GRXSTSP );
627 
628  ep = &pdev->dev.out_ep[status.b.epnum];
629 
630  switch (status.b.pktsts)
631  {
632  case STS_GOUT_NAK:
633  break;
634  case STS_DATA_UPDT:
635  if (status.b.bcnt)
636  {
637  USB_OTG_ReadPacket(pdev,ep->xfer_buff, status.b.bcnt);
638  ep->xfer_buff += status.b.bcnt;
639  ep->xfer_count += status.b.bcnt;
640  }
641  break;
642  case STS_XFER_COMP:
643  break;
644  case STS_SETUP_COMP:
645  break;
646  case STS_SETUP_UPDT:
647  /* Copy the setup packet received in FIFO into the setup buffer in RAM */
648  USB_OTG_ReadPacket(pdev , pdev->dev.setup_packet, 8);
649  ep->xfer_count += status.b.bcnt;
650  break;
651  default:
652  break;
653  }
654 
655  /* Enable the Rx Status Queue Level interrupt */
656  USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, int_mask.d32);
657 
658  return 1;
659 }
660 
667 static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t epnum)
668 {
669  USB_OTG_DTXFSTSn_TypeDef txstatus;
670  USB_OTG_EP *ep;
671  uint32_t len = 0;
672  uint32_t len32b;
673  txstatus.d32 = 0;
674 
675  ep = &pdev->dev.in_ep[epnum];
676 
677  len = ep->xfer_len - ep->xfer_count;
678 
679  if (len > ep->maxpacket)
680  {
681  len = ep->maxpacket;
682  }
683 
684  len32b = (len + 3) / 4;
685  txstatus.d32 = USB_OTG_READ_REG32( &pdev->regs.INEP_REGS[epnum]->DTXFSTS);
686 
687 
688 
689  while (txstatus.b.txfspcavail > len32b &&
690  ep->xfer_count < ep->xfer_len &&
691  ep->xfer_len != 0)
692  {
693  /* Write the FIFO */
694  len = ep->xfer_len - ep->xfer_count;
695 
696  if (len > ep->maxpacket)
697  {
698  len = ep->maxpacket;
699  }
700  len32b = (len + 3) / 4;
701 
702  USB_OTG_WritePacket (pdev , ep->xfer_buff, epnum, len);
703 
704  ep->xfer_buff += len;
705  ep->xfer_count += len;
706 
707  if( ep->xfer_count >= ep->xfer_len) {
708  uint32_t fifoemptymsk = 1 << ep->num;
709  USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);
710  break;
711  }
712 
713  txstatus.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[epnum]->DTXFSTS);
714  }
715 
716  return 1;
717 }
718 
726 {
727  USB_OTG_DAINT_TypeDef daintmsk;
728  USB_OTG_DOEPMSK_TypeDef doepmsk;
729  USB_OTG_DIEPMSK_TypeDef diepmsk;
732  USB_OTG_GINTSTS_TypeDef gintsts;
733  uint32_t i;
734 
735  dctl.d32 = 0;
736  daintmsk.d32 = 0;
737  doepmsk.d32 = 0;
738  diepmsk.d32 = 0;
739  dcfg.d32 = 0;
740  gintsts.d32 = 0;
741 
742  /* Clear the Remote Wake-up Signaling */
743  dctl.b.rmtwkupsig = 1;
744  USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, dctl.d32, 0 );
745 
746  /* Flush the Tx FIFO */
747  USB_OTG_FlushTxFifo(pdev , 0 );
748 
749  for (i = 0; i < pdev->cfg.dev_endpoints ; i++)
750  {
751  USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[i]->DIEPINT, 0xFF);
752  USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[i]->DOEPINT, 0xFF);
753  }
754  USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINT, 0xFFFFFFFF );
755 
756  daintmsk.ep.in = 1;
757  daintmsk.ep.out = 1;
758  USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINTMSK, daintmsk.d32 );
759 
760  doepmsk.b.setup = 1;
761  doepmsk.b.xfercompl = 1;
762  doepmsk.b.epdisabled = 1;
763  USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOEPMSK, doepmsk.d32 );
764 #ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
765  USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOUTEP1MSK, doepmsk.d32 );
766 #endif
767  diepmsk.b.xfercompl = 1;
768  diepmsk.b.timeout = 1;
769  diepmsk.b.epdisabled = 1;
770 
771  USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DIEPMSK, diepmsk.d32 );
772 #ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
773  USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DINEP1MSK, diepmsk.d32 );
774 #endif
775  /* Reset Device Address */
776  dcfg.d32 = USB_OTG_READ_REG32( &pdev->regs.DREGS->DCFG);
777  dcfg.b.devaddr = 0;
778  USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DCFG, dcfg.d32);
779 
780 
781  /* setup EP0 to receive SETUP packets */
782  USB_OTG_EP0_OutStart(pdev);
783 
784  /* Clear interrupt */
785  gintsts.d32 = 0;
786  gintsts.b.usbreset = 1;
787  USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32);
788 
789  /*Reset internal state machine */
790  USBD_DCD_INT_fops->Reset(pdev);
791  return 1;
792 }
793 
801 {
802  USB_OTG_GINTSTS_TypeDef gintsts;
803  USB_OTG_GUSBCFG_TypeDef gusbcfg;
804 
805  USB_OTG_EP0Activate(pdev);
806 
807  /* Set USB turn-around time based on device speed and PHY interface. */
808  gusbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);
809 
810  /* Full or High speed */
812  {
813  pdev->cfg.speed = USB_OTG_SPEED_HIGH;
815  gusbcfg.b.usbtrdtim = 9;
816  }
817  else
818  {
819  pdev->cfg.speed = USB_OTG_SPEED_FULL;
821  gusbcfg.b.usbtrdtim = 5;
822  }
823 
824  USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, gusbcfg.d32);
825 
826  /* Clear interrupt */
827  gintsts.d32 = 0;
828  gintsts.b.enumdone = 1;
829  USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTSTS, gintsts.d32 );
830  return 1;
831 }
832 
833 
841 {
842  USB_OTG_GINTSTS_TypeDef gintsts;
843 
844  gintsts.d32 = 0;
845 
847 
848  /* Clear interrupt */
849  gintsts.b.incomplisoin = 1;
850  USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
851 
852  return 1;
853 }
854 
862 {
863  USB_OTG_GINTSTS_TypeDef gintsts;
864 
865  gintsts.d32 = 0;
866 
868 
869  /* Clear interrupt */
870  gintsts.b.incomplisoout = 1;
871  USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
872  return 1;
873 }
880 static uint32_t DCD_ReadDevInEP (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
881 {
882  uint32_t v, msk, emp;
883  msk = USB_OTG_READ_REG32(&pdev->regs.DREGS->DIEPMSK);
884  emp = USB_OTG_READ_REG32(&pdev->regs.DREGS->DIEPEMPMSK);
885  msk |= ((emp >> epnum) & 0x1) << 7;
886  v = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[epnum]->DIEPINT) & msk;
887  return v;
888 }
889 
890 
891 
904 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
USB_OTG_STS USB_OTG_FlushTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t num)
USB_OTG_FlushTxFifo : Flush a Tx FIFO.
Definition: usb_core.c:461
uint32_t USB_OTG_ReadDevAllOutEp_itr(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_ReadDevAllOutEp_itr : returns OUT endpoint interrupt bits.
Definition: usb_core.c:1875
uint8_t(* IsoOUTIncomplete)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:61
struct _USB_OTG_GINTMSK_TypeDef::@56 b
#define USB_OTG_EP0_STATUS_IN
Definition: usb_core.h:56
USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev, const uint8_t *src, uint8_t ch_ep_num, uint16_t len)
USB_OTG_WritePacket : Writes a packet into the Tx FIFO associated with the EP.
Definition: usb_core.c:169
uint32_t USB_OTG_ReadDevOutEP_itr(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
USB_OTG_ReadDevOutEP_itr : returns Device OUT EP Interrupt register.
Definition: usb_core.c:1890
USBD_DCD_INT_cb_TypeDef * USBD_DCD_INT_fops
Definition: usbd_core.c:116
#define USB_OTG_HS_MAX_PACKET_SIZE
Definition: usb_regs.h:69
__IO uint32_t DIEPINT
Definition: usb_regs.h:149
static uint32_t DCD_HandleUSBSuspend_ISR(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_HandleUSBSuspend_ISR Indicates that SUSPEND state has been detected on the USB...
Definition: usb_dcd_int.c:411
__IO uint32_t DCFG
Definition: usb_regs.h:115
uint8_t num
Definition: usb_core.h:138
struct _USB_OTG_DOEPINTn_TypeDef::@69 b
void USB_OTG_EP0_OutStart(USB_OTG_CORE_HANDLE *pdev)
configures EPO to receive SETUP packets
Definition: usb_core.c:1917
uint8_t setup_packet[8 *3]
Definition: usb_core.h:264
struct _USB_OTG_DRXSTS_TypeDef::@58 b
uint8_t(* Reset)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:57
USB_OTG_STS USB_OTG_EP0Activate(USB_OTG_CORE_HANDLE *pdev)
enables EP0 OUT to receive SETUP packets and configures EP0 for transmitting packets ...
Definition: usb_core.c:1445
#define STS_GOUT_NAK
Definition: usb_defines.h:146
uint8_t(* DevConnected)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:63
uint8_t(* IsoINIncomplete)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:60
static uint32_t DCD_ReadDevInEP(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
DCD_ReadDevInEP Reads ep flags.
Definition: usb_dcd_int.c:880
#define USB_OTG_EP0_STATUS_OUT
Definition: usb_core.h:57
struct _USB_OTG_DIEPINTn_TypeDef::@68 b
__IO uint32_t DOEPINT
Definition: usb_regs.h:169
enum USB_OTG_SPEED USB_OTG_GetDeviceSpeed(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_GetDeviceSpeed Get the device speed from the device status register.
Definition: usb_core.c:1414
static uint32_t DCD_HandleUsbReset_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_HandleUsbReset_ISR This interrupt occurs when a USB Reset is detected.
Definition: usb_dcd_int.c:725
__IO uint32_t DOEPTSIZ
Definition: usb_regs.h:171
__IO uint32_t DOEPMSK
Definition: usb_regs.h:120
uint8_t USB_OTG_IsDeviceMode(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_IsDeviceMode : Check if it is device mode.
Definition: usb_core.c:562
__IO uint32_t GINTMSK
Definition: usb_regs.h:91
struct _USB_OTG_DSTS_TypeDef::@67 b
static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t epnum)
DCD_WriteEmptyTxFifo check FIFO for the next packet to be loaded.
Definition: usb_dcd_int.c:667
static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_HandleInEP_ISR Indicates that an IN EP has a pending Interrupt.
Definition: usb_dcd_int.c:452
uint8_t device_state
Definition: usb_core.h:255
static uint32_t DCD_IsoINIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_IsoINIncomplete_ISR handle the ISO IN incomplete interrupt.
Definition: usb_dcd_int.c:840
#define CLEAR_OUT_EP_INTR(epnum, intr)
Definition: usb_dcd_int.h:90
#define USB_OTG_SPEED_FULL
Definition: usb_defines.h:62
uint8_t dev_endpoints
Definition: usb_core.h:165
#define CLEAR_IN_EP_INTR(epnum, intr)
Definition: usb_dcd_int.h:85
USB_OTG_INEPREGS * INEP_REGS[USB_OTG_MAX_TX_FIFOS]
Definition: usb_regs.h:227
__IO uint32_t DIEPMSK
Definition: usb_regs.h:119
#define STS_XFER_COMP
Definition: usb_defines.h:148
uint32_t USB_OTG_ReadDevAllInEPItr(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_ReadDevAllInEPItr : Get int status register.
Definition: usb_core.c:1904
USB_OTG_OUTEPREGS * OUTEP_REGS[USB_OTG_MAX_TX_FIFOS]
Definition: usb_regs.h:228
USB_OTG_CORE_CFGS cfg
Definition: usb_core.h:298
struct _USB_OTG_DTXFSTSn_TypeDef::@63 b
Peripheral Device Interface Layer.
struct _USB_OTG_GOTGINT_TypeDef::@52 b
uint16_t mps
Definition: usb_core.h:168
uint8_t speed
Definition: usb_core.h:166
#define USB_OTG_SPEED_HIGH
Definition: usb_defines.h:61
__IO uint32_t GOTGINT
Definition: usb_regs.h:86
USB_OTG_EP in_ep[USB_OTG_MAX_TX_FIFOS]
Definition: usb_core.h:262
uint8_t(* DataInStage)(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
Definition: usb_dcd_int.h:54
__IO uint32_t DIEPEMPMSK
Definition: usb_regs.h:128
#define USB_OTG_FS_MAX_PACKET_SIZE
Definition: usb_regs.h:70
static uint32_t DCD_HandleRxStatusQueueLevel_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_HandleRxStatusQueueLevel_ISR Handles the Rx Status Queue Level Interrupt.
Definition: usb_dcd_int.c:614
#define USB_OTG_WRITE_REG32(reg, value)
Definition: usb_defines.h:222
uint8_t * xfer_buff
Definition: usb_core.h:147
uint32_t xfer_len
Definition: usb_core.h:149
struct _USB_OTG_DCFG_TypeDef::@65 b
uint8_t(* DevDisconnected)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:64
uint32_t USB_OTG_ReadCoreItr(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_ReadCoreItr : returns the Core Interrupt register.
Definition: usb_core.c:584
struct _USB_OTG_DAINT_TypeDef::@70 ep
__IO uint32_t DTXFSTS
Definition: usb_regs.h:153
static uint32_t DCD_HandleSof_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_HandleSof_ISR Handles the SOF Interrupts.
Definition: usb_dcd_int.c:593
__IO uint32_t GRXSTSP
Definition: usb_regs.h:93
__IO uint32_t DCTL
Definition: usb_regs.h:116
#define USB_OTG_READ_REG32(reg)
Definition: usb_defines.h:221
struct _USB_OTG_DCTL_TypeDef::@66 b
__IO uint32_t * PCGCCTL
Definition: usb_regs.h:232
USB_OTG_GREGS * GREGS
Definition: usb_regs.h:224
__IO uint32_t DAINTMSK
Definition: usb_regs.h:122
struct _USB_OTG_GUSBCFG_TypeDef::@54 b
__IO uint32_t DAINT
Definition: usb_regs.h:121
#define STS_DATA_UPDT
Definition: usb_defines.h:147
DCD_DEV dev
Definition: usb_core.h:301
static uint32_t DCD_HandleResume_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_HandleResume_ISR Indicates that the USB_OTG controller has detected a resume or remote Wake-up se...
Definition: usb_dcd_int.c:375
float v
Definition: Printf.cpp:15
__IO uint32_t GUSBCFG
Definition: usb_regs.h:88
__IO uint32_t GINTSTS
Definition: usb_regs.h:90
uint8_t connection_status
Definition: usb_core.h:259
uint8_t dma_enable
Definition: usb_core.h:167
uint32_t maxpacket
Definition: usb_core.h:145
__IO uint32_t DINEP1MSK
Definition: usb_regs.h:132
uint8_t(* DataOutStage)(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
Definition: usb_dcd_int.h:53
static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_HandleOutEP_ISR Indicates that an OUT EP has a pending Interrupt.
Definition: usb_dcd_int.c:521
#define STS_SETUP_COMP
Definition: usb_defines.h:149
USB_OTG_EP out_ep[USB_OTG_MAX_TX_FIFOS]
Definition: usb_core.h:263
__IO uint32_t DOUTEP1MSK
Definition: usb_regs.h:134
#define STS_SETUP_UPDT
Definition: usb_defines.h:150
void * USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, uint8_t *dest, uint16_t len)
USB_OTG_ReadPacket : Reads a packet from the Rx FIFO.
Definition: usb_core.c:198
struct _USB_OTG_GINTSTS_TypeDef::@57 b
uint8_t(* SOF)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:56
uint8_t device_status
Definition: usb_core.h:256
static uint32_t DCD_IsoOUTIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_IsoOUTIncomplete_ISR handle the ISO OUT incomplete interrupt.
Definition: usb_dcd_int.c:861
uint8_t(* Suspend)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:58
static uint32_t DCD_HandleEnumDone_ISR(USB_OTG_CORE_HANDLE *pdev)
DCD_HandleEnumDone_ISR Read the device status register and set the device speed.
Definition: usb_dcd_int.c:800
__IO uint32_t DSTS
Definition: usb_regs.h:117
uint8_t(* SetupStage)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:55
#define USB_OTG_CONFIGURED
Definition: usb_dcd.h:58
void setup()
Definition: AC_PID_test.cpp:26
uint8_t low_power
Definition: usb_core.h:172
struct _USB_OTG_PCGCCTL_TypeDef::@88 b
USB_OTG_CORE_REGS regs
Definition: usb_core.h:299
uint32_t USBD_OTG_ISR_Handler(USB_OTG_CORE_HANDLE *pdev)
STM32_USBF_OTG_ISR_Handler handles all USB Interrupts.
Definition: usb_dcd_int.c:211
uint32_t xfer_count
Definition: usb_core.h:150
uint8_t(* Resume)(USB_OTG_CORE_HANDLE *pdev)
Definition: usb_dcd_int.h:59
#define USB_OTG_MODIFY_REG32(reg, clear_mask, set_mask)
Definition: usb_defines.h:223
USB_OTG_DREGS * DREGS
Definition: usb_regs.h:225