STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f7xx_hal_hcd.c
Go to the documentation of this file.
1 
74 /* Includes ------------------------------------------------------------------*/
75 #include "stm32f7xx_hal.h"
76 
86 #ifdef HAL_HCD_MODULE_ENABLED
87 
88 /* Private typedef -----------------------------------------------------------*/
89 /* Private define ------------------------------------------------------------*/
90 /* Private macro -------------------------------------------------------------*/
91 /* Private variables ---------------------------------------------------------*/
92 /* Private function ----------------------------------------------------------*/
96 static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
97 static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
98 static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd);
99 static void HCD_Port_IRQHandler(HCD_HandleTypeDef *hhcd);
104 /* Exported functions --------------------------------------------------------*/
128 {
129  /* Check the HCD handle allocation */
130  if(hhcd == NULL)
131  {
132  return HAL_ERROR;
133  }
134 
135  /* Check the parameters */
137 
138  hhcd->State = HAL_HCD_STATE_BUSY;
139 
140  /* Init the low level hardware : GPIO, CLOCK, NVIC... */
141  HAL_HCD_MspInit(hhcd);
142 
143  /* Disable the Interrupts */
144  __HAL_HCD_DISABLE(hhcd);
145 
146  /*Init the Core (common init.) */
147  USB_CoreInit(hhcd->Instance, hhcd->Init);
148 
149  /* Force Host Mode*/
151 
152  /* Init Host */
153  USB_HostInit(hhcd->Instance, hhcd->Init);
154 
155  hhcd->State= HAL_HCD_STATE_READY;
156 
157  return HAL_OK;
158 }
159 
185  uint8_t ch_num,
186  uint8_t epnum,
187  uint8_t dev_address,
188  uint8_t speed,
189  uint8_t ep_type,
190  uint16_t mps)
191 {
192  HAL_StatusTypeDef status = HAL_OK;
193 
194  __HAL_LOCK(hhcd);
195 
196  hhcd->hc[ch_num].dev_addr = dev_address;
197  hhcd->hc[ch_num].max_packet = mps;
198  hhcd->hc[ch_num].ch_num = ch_num;
199  hhcd->hc[ch_num].ep_type = ep_type;
200  hhcd->hc[ch_num].ep_num = epnum & 0x7F;
201  hhcd->hc[ch_num].ep_is_in = ((epnum & 0x80) == 0x80);
202  hhcd->hc[ch_num].speed = speed;
203 
204  status = USB_HC_Init(hhcd->Instance,
205  ch_num,
206  epnum,
207  dev_address,
208  speed,
209  ep_type,
210  mps);
211  __HAL_UNLOCK(hhcd);
212 
213  return status;
214 }
215 
224 {
225  HAL_StatusTypeDef status = HAL_OK;
226 
227  __HAL_LOCK(hhcd);
228  USB_HC_Halt(hhcd->Instance, ch_num);
229  __HAL_UNLOCK(hhcd);
230 
231  return status;
232 }
233 
240 {
241  /* Check the HCD handle allocation */
242  if(hhcd == NULL)
243  {
244  return HAL_ERROR;
245  }
246 
247  hhcd->State = HAL_HCD_STATE_BUSY;
248 
249  /* DeInit the low level hardware */
250  HAL_HCD_MspDeInit(hhcd);
251 
252  __HAL_HCD_DISABLE(hhcd);
253 
254  hhcd->State = HAL_HCD_STATE_RESET;
255 
256  return HAL_OK;
257 }
258 
264 __weak void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
265 {
266  /* Prevent unused argument(s) compilation warning */
267  UNUSED(hhcd);
268 
269  /* NOTE : This function Should not be modified, when the callback is needed,
270  the HAL_HCD_MspInit could be implemented in the user file
271  */
272 }
273 
279 __weak void HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd)
280 {
281  /* Prevent unused argument(s) compilation warning */
282  UNUSED(hhcd);
283 
284  /* NOTE : This function Should not be modified, when the callback is needed,
285  the HAL_HCD_MspDeInit could be implemented in the user file
286  */
287 }
288 
332  uint8_t ch_num,
333  uint8_t direction ,
334  uint8_t ep_type,
335  uint8_t token,
336  uint8_t* pbuff,
337  uint16_t length,
338  uint8_t do_ping)
339 {
340  hhcd->hc[ch_num].ep_is_in = direction;
341  hhcd->hc[ch_num].ep_type = ep_type;
342 
343  if(token == 0)
344  {
345  hhcd->hc[ch_num].data_pid = HC_PID_SETUP;
346  }
347  else
348  {
349  hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
350  }
351 
352  /* Manage Data Toggle */
353  switch(ep_type)
354  {
355  case EP_TYPE_CTRL:
356  if((token == 1) && (direction == 0)) /*send data */
357  {
358  if ( length == 0 )
359  { /* For Status OUT stage, Length==0, Status Out PID = 1 */
360  hhcd->hc[ch_num].toggle_out = 1;
361  }
362 
363  /* Set the Data Toggle bit as per the Flag */
364  if ( hhcd->hc[ch_num].toggle_out == 0)
365  { /* Put the PID 0 */
366  hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
367  }
368  else
369  { /* Put the PID 1 */
370  hhcd->hc[ch_num].data_pid = HC_PID_DATA1 ;
371  }
372  if(hhcd->hc[ch_num].urb_state != URB_NOTREADY)
373  {
374  hhcd->hc[ch_num].do_ping = do_ping;
375  }
376  }
377  break;
378 
379  case EP_TYPE_BULK:
380  if(direction == 0)
381  {
382  /* Set the Data Toggle bit as per the Flag */
383  if ( hhcd->hc[ch_num].toggle_out == 0)
384  { /* Put the PID 0 */
385  hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
386  }
387  else
388  { /* Put the PID 1 */
389  hhcd->hc[ch_num].data_pid = HC_PID_DATA1 ;
390  }
391  if(hhcd->hc[ch_num].urb_state != URB_NOTREADY)
392  {
393  hhcd->hc[ch_num].do_ping = do_ping;
394  }
395  }
396  else
397  {
398  if( hhcd->hc[ch_num].toggle_in == 0)
399  {
400  hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
401  }
402  else
403  {
404  hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
405  }
406  }
407 
408  break;
409  case EP_TYPE_INTR:
410  if(direction == 0)
411  {
412  /* Set the Data Toggle bit as per the Flag */
413  if ( hhcd->hc[ch_num].toggle_out == 0)
414  { /* Put the PID 0 */
415  hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
416  }
417  else
418  { /* Put the PID 1 */
419  hhcd->hc[ch_num].data_pid = HC_PID_DATA1 ;
420  }
421  }
422  else
423  {
424  if( hhcd->hc[ch_num].toggle_in == 0)
425  {
426  hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
427  }
428  else
429  {
430  hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
431  }
432  }
433  break;
434 
435  case EP_TYPE_ISOC:
436  hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
437  break;
438  }
439 
440  hhcd->hc[ch_num].xfer_buff = pbuff;
441  hhcd->hc[ch_num].xfer_len = length;
442  hhcd->hc[ch_num].urb_state = URB_IDLE;
443  hhcd->hc[ch_num].xfer_count = 0 ;
444  hhcd->hc[ch_num].ch_num = ch_num;
445  hhcd->hc[ch_num].state = HC_IDLE;
446 
447  return USB_HC_StartXfer(hhcd->Instance, &(hhcd->hc[ch_num]), hhcd->Init.dma_enable);
448 }
449 
456 {
457  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
458  uint32_t i = 0 , interrupt = 0;
459 
460  /* ensure that we are in device mode */
461  if (USB_GetMode(hhcd->Instance) == USB_OTG_MODE_HOST)
462  {
463  /* avoid spurious interrupt */
465  {
466  return;
467  }
468 
470  {
471  /* incorrect mode, acknowledge the interrupt */
473  }
474 
476  {
477  /* incorrect mode, acknowledge the interrupt */
479  }
480 
482  {
483  /* incorrect mode, acknowledge the interrupt */
485  }
486 
488  {
489  /* incorrect mode, acknowledge the interrupt */
491  }
492 
493  /* Handle Host Disconnect Interrupts */
495  {
496 
497  /* Cleanup HPRT */
499  USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
500 
501  /* Handle Host Port Interrupts */
505  }
506 
507  /* Handle Host Port Interrupts */
509  {
510  HCD_Port_IRQHandler (hhcd);
511  }
512 
513  /* Handle Host SOF Interrupts */
515  {
516  HAL_HCD_SOF_Callback(hhcd);
518  }
519 
520  /* Handle Host channel Interrupts */
522  {
523  interrupt = USB_HC_ReadInterrupt(hhcd->Instance);
524  for (i = 0; i < hhcd->Init.Host_channels ; i++)
525  {
526  if (interrupt & (1 << i))
527  {
528  if ((USBx_HC(i)->HCCHAR) & USB_OTG_HCCHAR_EPDIR)
529  {
530  HCD_HC_IN_IRQHandler (hhcd, i);
531  }
532  else
533  {
534  HCD_HC_OUT_IRQHandler (hhcd, i);
535  }
536  }
537  }
539  }
540 
541  /* Handle Rx Queue Level Interrupts */
543  {
545 
546  HCD_RXQLVL_IRQHandler (hhcd);
547 
549  }
550  }
551 }
552 
558 __weak void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
559 {
560  /* Prevent unused argument(s) compilation warning */
561  UNUSED(hhcd);
562 
563  /* NOTE : This function Should not be modified, when the callback is needed,
564  the HAL_HCD_SOF_Callback could be implemented in the user file
565  */
566 }
567 
574 {
575  /* Prevent unused argument(s) compilation warning */
576  UNUSED(hhcd);
577 
578  /* NOTE : This function Should not be modified, when the callback is needed,
579  the HAL_HCD_Connect_Callback could be implemented in the user file
580  */
581 }
582 
589 {
590  /* Prevent unused argument(s) compilation warning */
591  UNUSED(hhcd);
592 
593  /* NOTE : This function Should not be modified, when the callback is needed,
594  the HAL_HCD_Disconnect_Callback could be implemented in the user file
595  */
596 }
597 
613 __weak void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
614 {
615  /* Prevent unused argument(s) compilation warning */
616  UNUSED(hhcd);
617 
618  /* NOTE : This function Should not be modified, when the callback is needed,
619  the HAL_HCD_HC_NotifyURBChange_Callback could be implemented in the user file
620  */
621 }
622 
648 {
649  __HAL_LOCK(hhcd);
650  __HAL_HCD_ENABLE(hhcd);
651  USB_DriveVbus(hhcd->Instance, 1);
652  __HAL_UNLOCK(hhcd);
653  return HAL_OK;
654 }
655 
663 {
664  __HAL_LOCK(hhcd);
665  USB_StopHost(hhcd->Instance);
666  __HAL_UNLOCK(hhcd);
667  return HAL_OK;
668 }
669 
676 {
677  return (USB_ResetPort(hhcd->Instance));
678 }
679 
705 {
706  return hhcd->State;
707 }
708 
724 {
725  return hhcd->hc[chnum].urb_state;
726 }
727 
728 
736 uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum)
737 {
738  return hhcd->hc[chnum].xfer_count;
739 }
740 
759 {
760  return hhcd->hc[chnum].state;
761 }
762 
769 {
770  return (USB_GetCurrentFrame(hhcd->Instance));
771 }
772 
779 {
780  return (USB_GetHostSpeed(hhcd->Instance));
781 }
782 
801 static void HCD_HC_IN_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum)
802 {
803  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
804  uint32_t tmpreg = 0;
805 
806  if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_AHBERR)
807  {
808  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
810  }
811  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_ACK)
812  {
813  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
814  }
815 
816  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_STALL)
817  {
819  hhcd->hc[chnum].state = HC_STALL;
821  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
822  USB_HC_Halt(hhcd->Instance, chnum);
823  }
824  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_DTERR)
825  {
827  USB_HC_Halt(hhcd->Instance, chnum);
829  hhcd->hc[chnum].state = HC_DATATGLERR;
830  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
831  }
832 
833  if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_FRMOR)
834  {
836  USB_HC_Halt(hhcd->Instance, chnum);
837  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
838  }
839 
840  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_XFRC)
841  {
842 
843  if (hhcd->Init.dma_enable)
844  {
845  hhcd->hc[chnum].xfer_count = hhcd->hc[chnum].xfer_len - \
846  (USBx_HC(chnum)->HCTSIZ & USB_OTG_HCTSIZ_XFRSIZ);
847  }
848 
849  hhcd->hc[chnum].state = HC_XFRC;
850  hhcd->hc[chnum].ErrCnt = 0;
851  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
852 
853 
854  if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)||
855  (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
856  {
858  USB_HC_Halt(hhcd->Instance, chnum);
860 
861  }
862  else if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
863  {
864  USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM;
865  hhcd->hc[chnum].urb_state = URB_DONE;
866  HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
867  }
868  hhcd->hc[chnum].toggle_in ^= 1;
869 
870  }
871  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH)
872  {
874 
875  if(hhcd->hc[chnum].state == HC_XFRC)
876  {
877  hhcd->hc[chnum].urb_state = URB_DONE;
878  }
879 
880  else if (hhcd->hc[chnum].state == HC_STALL)
881  {
882  hhcd->hc[chnum].urb_state = URB_STALL;
883  }
884 
885  else if((hhcd->hc[chnum].state == HC_XACTERR) ||
886  (hhcd->hc[chnum].state == HC_DATATGLERR))
887  {
888  if(hhcd->hc[chnum].ErrCnt++ > 3)
889  {
890  hhcd->hc[chnum].ErrCnt = 0;
891  hhcd->hc[chnum].urb_state = URB_ERROR;
892  }
893  else
894  {
895  hhcd->hc[chnum].urb_state = URB_NOTREADY;
896  }
897 
898  /* re-activate the channel */
899  tmpreg = USBx_HC(chnum)->HCCHAR;
900  tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
901  tmpreg |= USB_OTG_HCCHAR_CHENA;
902  USBx_HC(chnum)->HCCHAR = tmpreg;
903  }
904  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
905  HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
906  }
907 
908  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR)
909  {
911  hhcd->hc[chnum].ErrCnt++;
912  hhcd->hc[chnum].state = HC_XACTERR;
913  USB_HC_Halt(hhcd->Instance, chnum);
914  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
915  }
916  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NAK)
917  {
918  if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
919  {
921  USB_HC_Halt(hhcd->Instance, chnum);
922  }
923  else if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)||
924  (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
925  {
926  /* re-activate the channel */
927  tmpreg = USBx_HC(chnum)->HCCHAR;
928  tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
929  tmpreg |= USB_OTG_HCCHAR_CHENA;
930  USBx_HC(chnum)->HCCHAR = tmpreg;
931  }
932  hhcd->hc[chnum].state = HC_NAK;
933  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
934  }
935 }
936 
944 static void HCD_HC_OUT_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum)
945 {
946  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
947  uint32_t tmpreg = 0;
948 
949  if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_AHBERR)
950  {
951  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
953  }
954  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_ACK)
955  {
956  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
957 
958  if( hhcd->hc[chnum].do_ping == 1)
959  {
960  hhcd->hc[chnum].state = HC_NYET;
962  USB_HC_Halt(hhcd->Instance, chnum);
963  hhcd->hc[chnum].urb_state = URB_NOTREADY;
964  }
965  }
966 
967  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NYET)
968  {
969  hhcd->hc[chnum].state = HC_NYET;
970  hhcd->hc[chnum].ErrCnt= 0;
972  USB_HC_Halt(hhcd->Instance, chnum);
973  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET);
974 
975  }
976 
977  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_FRMOR)
978  {
980  USB_HC_Halt(hhcd->Instance, chnum);
981  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
982  }
983 
984  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_XFRC)
985  {
986  hhcd->hc[chnum].ErrCnt = 0;
988  USB_HC_Halt(hhcd->Instance, chnum);
989  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
990  hhcd->hc[chnum].state = HC_XFRC;
991 
992  }
993 
994  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_STALL)
995  {
996  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
998  USB_HC_Halt(hhcd->Instance, chnum);
999  hhcd->hc[chnum].state = HC_STALL;
1000  }
1001 
1002  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NAK)
1003  {
1004  hhcd->hc[chnum].ErrCnt = 0;
1006  USB_HC_Halt(hhcd->Instance, chnum);
1007  hhcd->hc[chnum].state = HC_NAK;
1008  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
1009  }
1010 
1011  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR)
1012  {
1014  USB_HC_Halt(hhcd->Instance, chnum);
1015  hhcd->hc[chnum].state = HC_XACTERR;
1016  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
1017  }
1018 
1019  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_DTERR)
1020  {
1022  USB_HC_Halt(hhcd->Instance, chnum);
1023  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
1024  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
1025  hhcd->hc[chnum].state = HC_DATATGLERR;
1026  }
1027 
1028 
1029  else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH)
1030  {
1032 
1033  if(hhcd->hc[chnum].state == HC_XFRC)
1034  {
1035  hhcd->hc[chnum].urb_state = URB_DONE;
1036  if (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)
1037  {
1038  hhcd->hc[chnum].toggle_out ^= 1;
1039  }
1040  }
1041  else if (hhcd->hc[chnum].state == HC_NAK)
1042  {
1043  hhcd->hc[chnum].urb_state = URB_NOTREADY;
1044  }
1045 
1046  else if (hhcd->hc[chnum].state == HC_NYET)
1047  {
1048  hhcd->hc[chnum].urb_state = URB_NOTREADY;
1049  hhcd->hc[chnum].do_ping = 0;
1050  }
1051 
1052  else if (hhcd->hc[chnum].state == HC_STALL)
1053  {
1054  hhcd->hc[chnum].urb_state = URB_STALL;
1055  }
1056 
1057  else if((hhcd->hc[chnum].state == HC_XACTERR) ||
1058  (hhcd->hc[chnum].state == HC_DATATGLERR))
1059  {
1060  if(hhcd->hc[chnum].ErrCnt++ > 3)
1061  {
1062  hhcd->hc[chnum].ErrCnt = 0;
1063  hhcd->hc[chnum].urb_state = URB_ERROR;
1064  }
1065  else
1066  {
1067  hhcd->hc[chnum].urb_state = URB_NOTREADY;
1068  }
1069 
1070  /* re-activate the channel */
1071  tmpreg = USBx_HC(chnum)->HCCHAR;
1072  tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1073  tmpreg |= USB_OTG_HCCHAR_CHENA;
1074  USBx_HC(chnum)->HCCHAR = tmpreg;
1075  }
1076 
1077  __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
1078  HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
1079  }
1080 }
1081 
1087 static void HCD_RXQLVL_IRQHandler (HCD_HandleTypeDef *hhcd)
1088 {
1089  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
1090  uint8_t channelnum =0;
1091  uint32_t pktsts;
1092  uint32_t pktcnt;
1093  uint32_t temp = 0;
1094  uint32_t tmpreg = 0;
1095 
1096  temp = hhcd->Instance->GRXSTSP ;
1097  channelnum = temp & USB_OTG_GRXSTSP_EPNUM;
1098  pktsts = (temp & USB_OTG_GRXSTSP_PKTSTS) >> 17;
1099  pktcnt = (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
1100 
1101  switch (pktsts)
1102  {
1103  case GRXSTS_PKTSTS_IN:
1104  /* Read the data into the host buffer. */
1105  if ((pktcnt > 0) && (hhcd->hc[channelnum].xfer_buff != (void *)0))
1106  {
1107 
1108  USB_ReadPacket(hhcd->Instance, hhcd->hc[channelnum].xfer_buff, pktcnt);
1109 
1110  /*manage multiple Xfer */
1111  hhcd->hc[channelnum].xfer_buff += pktcnt;
1112  hhcd->hc[channelnum].xfer_count += pktcnt;
1113 
1114  if((USBx_HC(channelnum)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) > 0)
1115  {
1116  /* re-activate the channel when more packets are expected */
1117  tmpreg = USBx_HC(channelnum)->HCCHAR;
1118  tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1119  tmpreg |= USB_OTG_HCCHAR_CHENA;
1120  USBx_HC(channelnum)->HCCHAR = tmpreg;
1121  hhcd->hc[channelnum].toggle_in ^= 1;
1122  }
1123  }
1124  break;
1125 
1127  break;
1130  default:
1131  break;
1132  }
1133 }
1134 
1140 static void HCD_Port_IRQHandler (HCD_HandleTypeDef *hhcd)
1141 {
1142  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
1143  __IO uint32_t hprt0, hprt0_dup;
1144 
1145  /* Handle Host Port Interrupts */
1146  hprt0 = USBx_HPRT0;
1147  hprt0_dup = USBx_HPRT0;
1148 
1149  hprt0_dup &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
1150  USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
1151 
1152  /* Check whether Port Connect detected */
1153  if((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET)
1154  {
1155  if((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS)
1156  {
1159  }
1160  hprt0_dup |= USB_OTG_HPRT_PCDET;
1161 
1162  }
1163 
1164  /* Check whether Port Enable Changed */
1165  if((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG)
1166  {
1167  hprt0_dup |= USB_OTG_HPRT_PENCHNG;
1168 
1169  if((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA)
1170  {
1171  if(hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY)
1172  {
1173  if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17))
1174  {
1176  }
1177  else
1178  {
1180  }
1181  }
1182  else
1183  {
1184  if(hhcd->Init.speed == HCD_SPEED_FULL)
1185  {
1186  USBx_HOST->HFIR = (uint32_t)60000;
1187  }
1188  }
1190 
1191  }
1192  else
1193  {
1194  /* Cleanup HPRT */
1195  USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
1196  USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
1197 
1199  }
1200  }
1201 
1202  /* Check For an overcurrent */
1203  if((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG)
1204  {
1205  hprt0_dup |= USB_OTG_HPRT_POCCHNG;
1206  }
1207 
1208  /* Clear Port Interrupts */
1209  USBx_HPRT0 = hprt0_dup;
1210 }
1211 
1220 #endif /* HAL_HCD_MODULE_ENABLED */
1221 
1229 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define USB_OTG_GINTSTS_HCINT
Definition: stm32f745xx.h:8309
#define GRXSTS_PKTSTS_IN_XFER_COMP
#define USB_OTG_GINTSTS_RXFLVL
Definition: stm32f745xx.h:8292
#define USB_OTG_GINTSTS_IISOIXFR
Definition: stm32f745xx.h:8304
void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef *USBx)
#define HC_PID_SETUP
#define assert_param(expr)
Include module&#39;s header file.
#define USB_OTG_EMBEDDED_PHY
#define __HAL_HCD_MASK_HALT_HC_INT(chnum)
#define USB_OTG_HPRT_PCSTS
Definition: stm32f745xx.h:8542
uint32_t USB_HC_ReadInterrupt(USB_OTG_GlobalTypeDef *USBx)
uint32_t HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd)
USB_OTG_URBStateTypeDef urb_state
#define USB_OTG_GINTSTS_MMIS
Definition: stm32f745xx.h:8289
HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, uint8_t pipe, uint8_t direction, uint8_t ep_type, uint8_t token, uint8_t *pbuff, uint16_t length, uint8_t do_ping)
void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
#define USB_OTG_GINTSTS_PTXFE
Definition: stm32f745xx.h:8310
HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num, uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
#define __HAL_UNLOCK(__HANDLE__)
#define IS_HCD_ALL_INSTANCE(INSTANCE)
HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_OTG_ModeTypeDef mode)
#define USB_OTG_HPRT_POCCHNG
Definition: stm32f745xx.h:8547
#define USB_OTG_MODE_HOST
HCD_TypeDef * Instance
uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum)
#define USB_OTG_HCTSIZ_PKTCNT
Definition: stm32f745xx.h:8710
#define GRXSTS_PKTSTS_CH_HALTED
#define __HAL_HCD_GET_FLAG(__HANDLE__, __INTERRUPT__)
__IO uint32_t GRXSTSP
Definition: stm32f745xx.h:984
#define USB_OTG_GINTSTS_DISCINT
Definition: stm32f745xx.h:8313
#define USB_OTG_HCTSIZ_XFRSIZ
Definition: stm32f745xx.h:8709
void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
#define USB_OTG_GRXSTSP_PKTSTS
Definition: stm32f745xx.h:8358
HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx)
#define HCFG_6_MHZ
HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd)
HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
#define USB_OTG_GINTSTS_SOF
Definition: stm32f745xx.h:8291
#define USB_OTG_HCINT_TXERR
Definition: stm32f745xx.h:8672
#define USB_OTG_HCCHAR_CHDIS
Definition: stm32f745xx.h:8635
#define USB_OTG_HCINT_NYET
Definition: stm32f745xx.h:8671
USB_OTG_Core_Registers.
Definition: stm32f745xx.h:974
#define EP_TYPE_CTRL
#define __HAL_HCD_CLEAR_HC_INT(chnum, __INTERRUPT__)
void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd)
#define USBx_HPRT0
#define EP_TYPE_BULK
HAL_StatusTypeDef HAL_HCD_Start(HCD_HandleTypeDef *hhcd)
#define __HAL_LOCK(__HANDLE__)
USB_OTG_HCStateTypeDef
Host channel States definition.
#define USBx_HC(i)
#define USB_OTG_HPRT_PENA
Definition: stm32f745xx.h:8544
#define NULL
Definition: usbd_def.h:53
#define __HAL_HCD_ENABLE(__HANDLE__)
HAL_StatusTypeDef HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd)
#define USB_OTG_HCINT_XFRC
Definition: stm32f745xx.h:8665
#define __HAL_HCD_DISABLE(__HANDLE__)
#define USB_OTG_GRXSTSP_BCNT
Definition: stm32f745xx.h:8356
#define HCFG_48_MHZ
#define __IO
Definition: core_cm0.h:213
HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd)
__IO HCD_StateTypeDef State
#define USB_OTG_HCINT_FRMOR
Definition: stm32f745xx.h:8674
This file contains all the functions prototypes for the HAL module driver.
#define GRXSTS_PKTSTS_DATA_TOGGLE_ERR
#define USB_OTG_HCINT_DTERR
Definition: stm32f745xx.h:8675
#define USBx_HOST
void HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd)
HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx, uint8_t freq)
uint32_t HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd)
#define __HAL_HCD_IS_INVALID_INTERRUPT(__HANDLE__)
uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef *USBx)
#define USB_OTG_GINTSTS_PXFR_INCOMPISOOUT
Definition: stm32f745xx.h:8305
#define HC_PID_DATA0
HCD_StateTypeDef
HCD_HCTypeDef hc[15]
HCD_StateTypeDef HAL_HCD_GetState(HCD_HandleTypeDef *hhcd)
#define UNUSED(x)
#define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__)
#define USB_OTG_HCINT_ACK
Definition: stm32f745xx.h:8670
HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc, uint8_t dma)
#define EP_TYPE_ISOC
HCD_HCStateTypeDef HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
#define HC_PID_DATA1
#define USB_OTG_HPRT_PCDET
Definition: stm32f745xx.h:8543
#define __HAL_HCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__)
HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num)
#define USB_OTG_GRXSTSP_EPNUM
Definition: stm32f745xx.h:8355
HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx)
#define USB_OTG_HCINT_CHH
Definition: stm32f745xx.h:8666
#define USB_OTG_HCINT_STALL
Definition: stm32f745xx.h:8668
#define __HAL_HCD_UNMASK_HALT_HC_INT(chnum)
HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd)
#define EP_TYPE_INTR
void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef Init)
HAL_StatusTypeDef
HAL Status structures definition.
#define USB_OTG_HCCHAR_CHENA
Definition: stm32f745xx.h:8636
HAL_StatusTypeDef HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd, uint8_t ch_num)
void * USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
#define HPRT0_PRTSPD_LOW_SPEED
#define USB_OTG_HPRT_PENCHNG
Definition: stm32f745xx.h:8545
#define USB_OTG_HCINT_NAK
Definition: stm32f745xx.h:8669
HCD_InitTypeDef Init
#define USB_OTG_GINTSTS_HPRTINT
Definition: stm32f745xx.h:8308
#define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__)
USB_OTG_HCStateTypeDef state
void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
#define USB_OTG_HPRT_PSPD
Definition: stm32f745xx.h:8563
#define USB_OTG_HCCHAR_EPDIR
Definition: stm32f745xx.h:8615
#define GRXSTS_PKTSTS_IN
USB_OTG_URBStateTypeDef
URB States definition.
HAL_StatusTypeDef USB_DriveVbus(USB_OTG_GlobalTypeDef *USBx, uint8_t state)
#define HCD_SPEED_FULL
uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx)
HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, uint8_t ch_num, uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
#define USB_OTG_HCCHAR_ODDFRM
Definition: stm32f745xx.h:8634
#define USB_OTG_HCINT_AHBERR
Definition: stm32f745xx.h:8667