Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 6 | ||
---|---|---|---|
Line 86... | Line 86... | ||
86 | /** @defgroup PCD_Private_Functions PCD Private Functions |
86 | /** @defgroup PCD_Private_Functions PCD Private Functions |
87 | * @{ |
87 | * @{ |
88 | */ |
88 | */ |
89 | 89 | ||
90 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd); |
90 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd); |
- | 91 | static HAL_StatusTypeDef HAL_PCD_EP_DB_Transmit(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep, uint16_t wEPVal); |
|
- | 92 | static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep, uint16_t wEPVal); |
|
91 | 93 | ||
92 | /** |
94 | /** |
93 | * @} |
95 | * @} |
94 | */ |
96 | */ |
95 | 97 | ||
Line 97... | Line 99... | ||
97 | /** @defgroup PCD_Exported_Functions PCD Exported Functions |
99 | /** @defgroup PCD_Exported_Functions PCD Exported Functions |
98 | * @{ |
100 | * @{ |
99 | */ |
101 | */ |
100 | 102 | ||
101 | /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions |
103 | /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions |
102 | * @brief Initialization and Configuration functions |
104 | * @brief Initialization and Configuration functions |
103 | * |
105 | * |
104 | @verbatim |
106 | @verbatim |
105 | =============================================================================== |
107 | =============================================================================== |
106 | ##### Initialization and de-initialization functions ##### |
108 | ##### Initialization and de-initialization functions ##### |
107 | =============================================================================== |
109 | =============================================================================== |
108 | [..] This section provides functions allowing to: |
110 | [..] This section provides functions allowing to: |
Line 196... | Line 198... | ||
196 | /* Init Device */ |
198 | /* Init Device */ |
197 | (void)USB_DevInit(hpcd->Instance, hpcd->Init); |
199 | (void)USB_DevInit(hpcd->Instance, hpcd->Init); |
198 | 200 | ||
199 | hpcd->USB_Address = 0U; |
201 | hpcd->USB_Address = 0U; |
200 | hpcd->State = HAL_PCD_STATE_READY; |
202 | hpcd->State = HAL_PCD_STATE_READY; |
201 | 203 | ||
202 | /* Activate LPM */ |
204 | /* Activate LPM */ |
203 | if (hpcd->Init.lpm_enable == 1U) |
205 | if (hpcd->Init.lpm_enable == 1U) |
204 | { |
206 | { |
205 | (void)HAL_PCDEx_ActivateLPM(hpcd); |
207 | (void)HAL_PCDEx_ActivateLPM(hpcd); |
206 | } |
208 | } |
207 | 209 | ||
208 | return HAL_OK; |
210 | return HAL_OK; |
209 | } |
211 | } |
210 | 212 | ||
211 | /** |
213 | /** |
212 | * @brief DeInitializes the PCD peripheral. |
214 | * @brief DeInitializes the PCD peripheral. |
Line 222... | Line 224... | ||
222 | } |
224 | } |
223 | 225 | ||
224 | hpcd->State = HAL_PCD_STATE_BUSY; |
226 | hpcd->State = HAL_PCD_STATE_BUSY; |
225 | 227 | ||
226 | /* Stop Device */ |
228 | /* Stop Device */ |
- | 229 | if (USB_StopDevice(hpcd->Instance) != HAL_OK) |
|
- | 230 | { |
|
227 | (void)HAL_PCD_Stop(hpcd); |
231 | return HAL_ERROR; |
- | 232 | } |
|
228 | 233 | ||
229 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
234 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
230 | if (hpcd->MspDeInitCallback == NULL) |
235 | if (hpcd->MspDeInitCallback == NULL) |
231 | { |
236 | { |
232 | hpcd->MspDeInitCallback = HAL_PCD_MspDeInit; /* Legacy weak MspDeInit */ |
237 | hpcd->MspDeInitCallback = HAL_PCD_MspDeInit; /* Legacy weak MspDeInit */ |
Line 291... | Line 296... | ||
291 | * @arg @ref HAL_PCD_MSPINIT_CB_ID MspDeInit callback ID |
296 | * @arg @ref HAL_PCD_MSPINIT_CB_ID MspDeInit callback ID |
292 | * @arg @ref HAL_PCD_MSPDEINIT_CB_ID MspDeInit callback ID |
297 | * @arg @ref HAL_PCD_MSPDEINIT_CB_ID MspDeInit callback ID |
293 | * @param pCallback pointer to the Callback function |
298 | * @param pCallback pointer to the Callback function |
294 | * @retval HAL status |
299 | * @retval HAL status |
295 | */ |
300 | */ |
296 | HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID, pPCD_CallbackTypeDef pCallback) |
301 | HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd, |
- | 302 | HAL_PCD_CallbackIDTypeDef CallbackID, |
|
- | 303 | pPCD_CallbackTypeDef pCallback) |
|
297 | { |
304 | { |
298 | HAL_StatusTypeDef status = HAL_OK; |
305 | HAL_StatusTypeDef status = HAL_OK; |
299 | 306 | ||
300 | if (pCallback == NULL) |
307 | if (pCallback == NULL) |
301 | { |
308 | { |
Line 501... | Line 508... | ||
501 | * To be used instead of the weak HAL_PCD_DataOutStageCallback() predefined callback |
508 | * To be used instead of the weak HAL_PCD_DataOutStageCallback() predefined callback |
502 | * @param hpcd PCD handle |
509 | * @param hpcd PCD handle |
503 | * @param pCallback pointer to the USB PCD Data OUT Stage Callback function |
510 | * @param pCallback pointer to the USB PCD Data OUT Stage Callback function |
504 | * @retval HAL status |
511 | * @retval HAL status |
505 | */ |
512 | */ |
506 | HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataOutStageCallbackTypeDef pCallback) |
513 | HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd, |
- | 514 | pPCD_DataOutStageCallbackTypeDef pCallback) |
|
507 | { |
515 | { |
508 | HAL_StatusTypeDef status = HAL_OK; |
516 | HAL_StatusTypeDef status = HAL_OK; |
509 | 517 | ||
510 | if (pCallback == NULL) |
518 | if (pCallback == NULL) |
511 | { |
519 | { |
Line 536... | Line 544... | ||
536 | 544 | ||
537 | return status; |
545 | return status; |
538 | } |
546 | } |
539 | 547 | ||
540 | /** |
548 | /** |
541 | * @brief UnRegister the USB PCD Data OUT Stage Callback |
549 | * @brief Unregister the USB PCD Data OUT Stage Callback |
542 | * USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataOutStageCallback() predefined callback |
550 | * USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataOutStageCallback() predefined callback |
543 | * @param hpcd PCD handle |
551 | * @param hpcd PCD handle |
544 | * @retval HAL status |
552 | * @retval HAL status |
545 | */ |
553 | */ |
546 | HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd) |
554 | HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd) |
Line 574... | Line 582... | ||
574 | * To be used instead of the weak HAL_PCD_DataInStageCallback() predefined callback |
582 | * To be used instead of the weak HAL_PCD_DataInStageCallback() predefined callback |
575 | * @param hpcd PCD handle |
583 | * @param hpcd PCD handle |
576 | * @param pCallback pointer to the USB PCD Data IN Stage Callback function |
584 | * @param pCallback pointer to the USB PCD Data IN Stage Callback function |
577 | * @retval HAL status |
585 | * @retval HAL status |
578 | */ |
586 | */ |
579 | HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataInStageCallbackTypeDef pCallback) |
587 | HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd, |
- | 588 | pPCD_DataInStageCallbackTypeDef pCallback) |
|
580 | { |
589 | { |
581 | HAL_StatusTypeDef status = HAL_OK; |
590 | HAL_StatusTypeDef status = HAL_OK; |
582 | 591 | ||
583 | if (pCallback == NULL) |
592 | if (pCallback == NULL) |
584 | { |
593 | { |
Line 609... | Line 618... | ||
609 | 618 | ||
610 | return status; |
619 | return status; |
611 | } |
620 | } |
612 | 621 | ||
613 | /** |
622 | /** |
614 | * @brief UnRegister the USB PCD Data IN Stage Callback |
623 | * @brief Unregister the USB PCD Data IN Stage Callback |
615 | * USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataInStageCallback() predefined callback |
624 | * USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataInStageCallback() predefined callback |
616 | * @param hpcd PCD handle |
625 | * @param hpcd PCD handle |
617 | * @retval HAL status |
626 | * @retval HAL status |
618 | */ |
627 | */ |
619 | HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd) |
628 | HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd) |
Line 647... | Line 656... | ||
647 | * To be used instead of the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback |
656 | * To be used instead of the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback |
648 | * @param hpcd PCD handle |
657 | * @param hpcd PCD handle |
649 | * @param pCallback pointer to the USB PCD Iso OUT incomplete Callback function |
658 | * @param pCallback pointer to the USB PCD Iso OUT incomplete Callback function |
650 | * @retval HAL status |
659 | * @retval HAL status |
651 | */ |
660 | */ |
652 | HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoOutIncpltCallbackTypeDef pCallback) |
661 | HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd, |
- | 662 | pPCD_IsoOutIncpltCallbackTypeDef pCallback) |
|
653 | { |
663 | { |
654 | HAL_StatusTypeDef status = HAL_OK; |
664 | HAL_StatusTypeDef status = HAL_OK; |
655 | 665 | ||
656 | if (pCallback == NULL) |
666 | if (pCallback == NULL) |
657 | { |
667 | { |
Line 682... | Line 692... | ||
682 | 692 | ||
683 | return status; |
693 | return status; |
684 | } |
694 | } |
685 | 695 | ||
686 | /** |
696 | /** |
687 | * @brief UnRegister the USB PCD Iso OUT incomplete Callback |
697 | * @brief Unregister the USB PCD Iso OUT incomplete Callback |
- | 698 | * USB PCD Iso OUT incomplete Callback is redirected |
|
688 | * USB PCD Iso OUT incomplete Callback is redirected to the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback |
699 | * to the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback |
689 | * @param hpcd PCD handle |
700 | * @param hpcd PCD handle |
690 | * @retval HAL status |
701 | * @retval HAL status |
691 | */ |
702 | */ |
692 | HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd) |
703 | HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd) |
693 | { |
704 | { |
Line 720... | Line 731... | ||
720 | * To be used instead of the weak HAL_PCD_ISOINIncompleteCallback() predefined callback |
731 | * To be used instead of the weak HAL_PCD_ISOINIncompleteCallback() predefined callback |
721 | * @param hpcd PCD handle |
732 | * @param hpcd PCD handle |
722 | * @param pCallback pointer to the USB PCD Iso IN incomplete Callback function |
733 | * @param pCallback pointer to the USB PCD Iso IN incomplete Callback function |
723 | * @retval HAL status |
734 | * @retval HAL status |
724 | */ |
735 | */ |
725 | HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoInIncpltCallbackTypeDef pCallback) |
736 | HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd, |
- | 737 | pPCD_IsoInIncpltCallbackTypeDef pCallback) |
|
726 | { |
738 | { |
727 | HAL_StatusTypeDef status = HAL_OK; |
739 | HAL_StatusTypeDef status = HAL_OK; |
728 | 740 | ||
729 | if (pCallback == NULL) |
741 | if (pCallback == NULL) |
730 | { |
742 | { |
Line 755... | Line 767... | ||
755 | 767 | ||
756 | return status; |
768 | return status; |
757 | } |
769 | } |
758 | 770 | ||
759 | /** |
771 | /** |
760 | * @brief UnRegister the USB PCD Iso IN incomplete Callback |
772 | * @brief Unregister the USB PCD Iso IN incomplete Callback |
- | 773 | * USB PCD Iso IN incomplete Callback is redirected |
|
761 | * USB PCD Iso IN incomplete Callback is redirected to the weak HAL_PCD_ISOINIncompleteCallback() predefined callback |
774 | * to the weak HAL_PCD_ISOINIncompleteCallback() predefined callback |
762 | * @param hpcd PCD handle |
775 | * @param hpcd PCD handle |
763 | * @retval HAL status |
776 | * @retval HAL status |
764 | */ |
777 | */ |
765 | HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd) |
778 | HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd) |
766 | { |
779 | { |
Line 828... | Line 841... | ||
828 | 841 | ||
829 | return status; |
842 | return status; |
830 | } |
843 | } |
831 | 844 | ||
832 | /** |
845 | /** |
833 | * @brief UnRegister the USB PCD BCD Callback |
846 | * @brief Unregister the USB PCD BCD Callback |
834 | * USB BCD Callback is redirected to the weak HAL_PCDEx_BCD_Callback() predefined callback |
847 | * USB BCD Callback is redirected to the weak HAL_PCDEx_BCD_Callback() predefined callback |
835 | * @param hpcd PCD handle |
848 | * @param hpcd PCD handle |
836 | * @retval HAL status |
849 | * @retval HAL status |
837 | */ |
850 | */ |
838 | HAL_StatusTypeDef HAL_PCD_UnRegisterBcdCallback(PCD_HandleTypeDef *hpcd) |
851 | HAL_StatusTypeDef HAL_PCD_UnRegisterBcdCallback(PCD_HandleTypeDef *hpcd) |
Line 901... | Line 914... | ||
901 | 914 | ||
902 | return status; |
915 | return status; |
903 | } |
916 | } |
904 | 917 | ||
905 | /** |
918 | /** |
906 | * @brief UnRegister the USB PCD LPM Callback |
919 | * @brief Unregister the USB PCD LPM Callback |
907 | * USB LPM Callback is redirected to the weak HAL_PCDEx_LPM_Callback() predefined callback |
920 | * USB LPM Callback is redirected to the weak HAL_PCDEx_LPM_Callback() predefined callback |
908 | * @param hpcd PCD handle |
921 | * @param hpcd PCD handle |
909 | * @retval HAL status |
922 | * @retval HAL status |
910 | */ |
923 | */ |
911 | HAL_StatusTypeDef HAL_PCD_UnRegisterLpmCallback(PCD_HandleTypeDef *hpcd) |
924 | HAL_StatusTypeDef HAL_PCD_UnRegisterLpmCallback(PCD_HandleTypeDef *hpcd) |
Line 938... | Line 951... | ||
938 | /** |
951 | /** |
939 | * @} |
952 | * @} |
940 | */ |
953 | */ |
941 | 954 | ||
942 | /** @defgroup PCD_Exported_Functions_Group2 Input and Output operation functions |
955 | /** @defgroup PCD_Exported_Functions_Group2 Input and Output operation functions |
943 | * @brief Data transfers functions |
956 | * @brief Data transfers functions |
944 | * |
957 | * |
945 | @verbatim |
958 | @verbatim |
946 | =============================================================================== |
959 | =============================================================================== |
947 | ##### IO operation functions ##### |
960 | ##### IO operation functions ##### |
948 | =============================================================================== |
961 | =============================================================================== |
949 | [..] |
962 | [..] |
Line 960... | Line 973... | ||
960 | * @retval HAL status |
973 | * @retval HAL status |
961 | */ |
974 | */ |
962 | HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd) |
975 | HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd) |
963 | { |
976 | { |
964 | __HAL_LOCK(hpcd); |
977 | __HAL_LOCK(hpcd); |
965 | (void)USB_DevConnect(hpcd->Instance); |
- | |
966 | __HAL_PCD_ENABLE(hpcd); |
978 | __HAL_PCD_ENABLE(hpcd); |
- | 979 | (void)USB_DevConnect(hpcd->Instance); |
|
967 | __HAL_UNLOCK(hpcd); |
980 | __HAL_UNLOCK(hpcd); |
- | 981 | ||
968 | return HAL_OK; |
982 | return HAL_OK; |
969 | } |
983 | } |
970 | 984 | ||
971 | /** |
985 | /** |
972 | * @brief Stop the USB device. |
986 | * @brief Stop the USB device. |
Line 975... | Line 989... | ||
975 | */ |
989 | */ |
976 | HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd) |
990 | HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd) |
977 | { |
991 | { |
978 | __HAL_LOCK(hpcd); |
992 | __HAL_LOCK(hpcd); |
979 | __HAL_PCD_DISABLE(hpcd); |
993 | __HAL_PCD_DISABLE(hpcd); |
980 | - | ||
981 | (void)USB_StopDevice(hpcd->Instance); |
994 | (void)USB_DevDisconnect(hpcd->Instance); |
982 | - | ||
983 | __HAL_UNLOCK(hpcd); |
995 | __HAL_UNLOCK(hpcd); |
984 | 996 | ||
985 | return HAL_OK; |
997 | return HAL_OK; |
986 | } |
998 | } |
987 | 999 | ||
Line 1048... | Line 1060... | ||
1048 | } |
1060 | } |
1049 | 1061 | ||
1050 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_SUSP)) |
1062 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_SUSP)) |
1051 | { |
1063 | { |
1052 | /* Force low-power mode in the macrocell */ |
1064 | /* Force low-power mode in the macrocell */ |
1053 | hpcd->Instance->CNTR |= USB_CNTR_FSUSP; |
1065 | hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_FSUSP; |
1054 | 1066 | ||
1055 | /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ |
1067 | /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ |
1056 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP); |
1068 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP); |
1057 | 1069 | ||
1058 | hpcd->Instance->CNTR |= USB_CNTR_LPMODE; |
1070 | hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_LPMODE; |
1059 | 1071 | ||
1060 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_WKUP) == 0U) |
- | |
1061 | { |
- | |
1062 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1072 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1063 | hpcd->SuspendCallback(hpcd); |
1073 | hpcd->SuspendCallback(hpcd); |
1064 | #else |
1074 | #else |
1065 | HAL_PCD_SuspendCallback(hpcd); |
1075 | HAL_PCD_SuspendCallback(hpcd); |
1066 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1076 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1067 | } |
- | |
1068 | } |
1077 | } |
1069 | 1078 | ||
1070 | /* Handle LPM Interrupt */ |
1079 | /* Handle LPM Interrupt */ |
1071 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_L1REQ)) |
1080 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_L1REQ)) |
1072 | { |
1081 | { |
1073 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_L1REQ); |
1082 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_L1REQ); |
1074 | if (hpcd->LPM_State == LPM_L0) |
1083 | if (hpcd->LPM_State == LPM_L0) |
1075 | { |
1084 | { |
1076 | /* Force suspend and low-power mode before going to L1 state*/ |
1085 | /* Force suspend and low-power mode before going to L1 state*/ |
1077 | hpcd->Instance->CNTR |= USB_CNTR_LPMODE; |
1086 | hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_LPMODE; |
1078 | hpcd->Instance->CNTR |= USB_CNTR_FSUSP; |
1087 | hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_FSUSP; |
1079 | 1088 | ||
1080 | hpcd->LPM_State = LPM_L1; |
1089 | hpcd->LPM_State = LPM_L1; |
1081 | hpcd->BESL = ((uint32_t)hpcd->Instance->LPMCSR & USB_LPMCSR_BESL) >> 2; |
1090 | hpcd->BESL = ((uint32_t)hpcd->Instance->LPMCSR & USB_LPMCSR_BESL) >> 2; |
1082 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1091 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1083 | hpcd->LPMCallback(hpcd, PCD_LPM_L1_ACTIVE); |
1092 | hpcd->LPMCallback(hpcd, PCD_LPM_L1_ACTIVE); |
Line 1289... | Line 1298... | ||
1289 | /** |
1298 | /** |
1290 | * @} |
1299 | * @} |
1291 | */ |
1300 | */ |
1292 | 1301 | ||
1293 | /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions |
1302 | /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions |
1294 | * @brief management functions |
1303 | * @brief management functions |
1295 | * |
1304 | * |
1296 | @verbatim |
1305 | @verbatim |
1297 | =============================================================================== |
1306 | =============================================================================== |
1298 | ##### Peripheral Control functions ##### |
1307 | ##### Peripheral Control functions ##### |
1299 | =============================================================================== |
1308 | =============================================================================== |
1300 | [..] |
1309 | [..] |
Line 1313... | Line 1322... | ||
1313 | HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd) |
1322 | HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd) |
1314 | { |
1323 | { |
1315 | __HAL_LOCK(hpcd); |
1324 | __HAL_LOCK(hpcd); |
1316 | (void)USB_DevConnect(hpcd->Instance); |
1325 | (void)USB_DevConnect(hpcd->Instance); |
1317 | __HAL_UNLOCK(hpcd); |
1326 | __HAL_UNLOCK(hpcd); |
- | 1327 | ||
1318 | return HAL_OK; |
1328 | return HAL_OK; |
1319 | } |
1329 | } |
1320 | 1330 | ||
1321 | /** |
1331 | /** |
1322 | * @brief Disconnect the USB device. |
1332 | * @brief Disconnect the USB device. |
Line 1326... | Line 1336... | ||
1326 | HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd) |
1336 | HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd) |
1327 | { |
1337 | { |
1328 | __HAL_LOCK(hpcd); |
1338 | __HAL_LOCK(hpcd); |
1329 | (void)USB_DevDisconnect(hpcd->Instance); |
1339 | (void)USB_DevDisconnect(hpcd->Instance); |
1330 | __HAL_UNLOCK(hpcd); |
1340 | __HAL_UNLOCK(hpcd); |
- | 1341 | ||
1331 | return HAL_OK; |
1342 | return HAL_OK; |
1332 | } |
1343 | } |
1333 | 1344 | ||
1334 | /** |
1345 | /** |
1335 | * @brief Set the USB Device address. |
1346 | * @brief Set the USB Device address. |
Line 1341... | Line 1352... | ||
1341 | { |
1352 | { |
1342 | __HAL_LOCK(hpcd); |
1353 | __HAL_LOCK(hpcd); |
1343 | hpcd->USB_Address = address; |
1354 | hpcd->USB_Address = address; |
1344 | (void)USB_SetDevAddress(hpcd->Instance, address); |
1355 | (void)USB_SetDevAddress(hpcd->Instance, address); |
1345 | __HAL_UNLOCK(hpcd); |
1356 | __HAL_UNLOCK(hpcd); |
- | 1357 | ||
1346 | return HAL_OK; |
1358 | return HAL_OK; |
1347 | } |
1359 | } |
1348 | /** |
1360 | /** |
1349 | * @brief Open and configure an endpoint. |
1361 | * @brief Open and configure an endpoint. |
1350 | * @param hpcd PCD handle |
1362 | * @param hpcd PCD handle |
1351 | * @param ep_addr endpoint address |
1363 | * @param ep_addr endpoint address |
1352 | * @param ep_mps endpoint max packet size |
1364 | * @param ep_mps endpoint max packet size |
1353 | * @param ep_type endpoint type |
1365 | * @param ep_type endpoint type |
1354 | * @retval HAL status |
1366 | * @retval HAL status |
1355 | */ |
1367 | */ |
1356 | HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type) |
1368 | HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, |
- | 1369 | uint16_t ep_mps, uint8_t ep_type) |
|
1357 | { |
1370 | { |
1358 | HAL_StatusTypeDef ret = HAL_OK; |
1371 | HAL_StatusTypeDef ret = HAL_OK; |
1359 | PCD_EPTypeDef *ep; |
1372 | PCD_EPTypeDef *ep; |
1360 | 1373 | ||
1361 | if ((ep_addr & 0x80U) == 0x80U) |
1374 | if ((ep_addr & 0x80U) == 0x80U) |
Line 1478... | Line 1491... | ||
1478 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
1491 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
1479 | 1492 | ||
1480 | /*setup and start the Xfer */ |
1493 | /*setup and start the Xfer */ |
1481 | ep->xfer_buff = pBuf; |
1494 | ep->xfer_buff = pBuf; |
1482 | ep->xfer_len = len; |
1495 | ep->xfer_len = len; |
- | 1496 | ep->xfer_fill_db = 1U; |
|
- | 1497 | ep->xfer_len_db = len; |
|
1483 | ep->xfer_count = 0U; |
1498 | ep->xfer_count = 0U; |
1484 | ep->is_in = 1U; |
1499 | ep->is_in = 1U; |
1485 | ep->num = ep_addr & EP_ADDR_MSK; |
1500 | ep->num = ep_addr & EP_ADDR_MSK; |
1486 | 1501 | ||
1487 | if ((ep_addr & EP_ADDR_MSK) == 0U) |
1502 | if ((ep_addr & EP_ADDR_MSK) == 0U) |
Line 1526... | Line 1541... | ||
1526 | ep->num = ep_addr & EP_ADDR_MSK; |
1541 | ep->num = ep_addr & EP_ADDR_MSK; |
1527 | 1542 | ||
1528 | __HAL_LOCK(hpcd); |
1543 | __HAL_LOCK(hpcd); |
1529 | 1544 | ||
1530 | (void)USB_EPSetStall(hpcd->Instance, ep); |
1545 | (void)USB_EPSetStall(hpcd->Instance, ep); |
1531 | if ((ep_addr & EP_ADDR_MSK) == 0U) |
- | |
1532 | { |
- | |
1533 | (void)USB_EP0_OutStart(hpcd->Instance, (uint8_t *)hpcd->Setup); |
- | |
1534 | } |
1546 | |
1535 | __HAL_UNLOCK(hpcd); |
1547 | __HAL_UNLOCK(hpcd); |
1536 | 1548 | ||
1537 | return HAL_OK; |
1549 | return HAL_OK; |
1538 | } |
1550 | } |
1539 | 1551 | ||
Line 1611... | Line 1623... | ||
1611 | /** |
1623 | /** |
1612 | * @} |
1624 | * @} |
1613 | */ |
1625 | */ |
1614 | 1626 | ||
1615 | /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions |
1627 | /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions |
1616 | * @brief Peripheral State functions |
1628 | * @brief Peripheral State functions |
1617 | * |
1629 | * |
1618 | @verbatim |
1630 | @verbatim |
1619 | =============================================================================== |
1631 | =============================================================================== |
1620 | ##### Peripheral State functions ##### |
1632 | ##### Peripheral State functions ##### |
1621 | =============================================================================== |
1633 | =============================================================================== |
1622 | [..] |
1634 | [..] |
Line 1657... | Line 1669... | ||
1657 | * @retval HAL status |
1669 | * @retval HAL status |
1658 | */ |
1670 | */ |
1659 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd) |
1671 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd) |
1660 | { |
1672 | { |
1661 | PCD_EPTypeDef *ep; |
1673 | PCD_EPTypeDef *ep; |
1662 | uint16_t count; |
- | |
1663 | uint16_t wIstr; |
- | |
1664 | uint16_t wEPVal; |
1674 | uint16_t count, wIstr, wEPVal, TxByteNbre; |
1665 | uint8_t epindex; |
1675 | uint8_t epindex; |
1666 | 1676 | ||
1667 | /* stay in loop while pending interrupts */ |
1677 | /* stay in loop while pending interrupts */ |
1668 | while ((hpcd->Instance->ISTR & USB_ISTR_CTR) != 0U) |
1678 | while ((hpcd->Instance->ISTR & USB_ISTR_CTR) != 0U) |
1669 | { |
1679 | { |
1670 | wIstr = hpcd->Instance->ISTR; |
1680 | wIstr = hpcd->Instance->ISTR; |
- | 1681 | ||
1671 | /* extract highest priority endpoint number */ |
1682 | /* extract highest priority endpoint number */ |
1672 | epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID); |
1683 | epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID); |
1673 | 1684 | ||
1674 | if (epindex == 0U) |
1685 | if (epindex == 0U) |
1675 | { |
1686 | { |
Line 1678... | Line 1689... | ||
1678 | /* DIR bit = origin of the interrupt */ |
1689 | /* DIR bit = origin of the interrupt */ |
1679 | if ((wIstr & USB_ISTR_DIR) == 0U) |
1690 | if ((wIstr & USB_ISTR_DIR) == 0U) |
1680 | { |
1691 | { |
1681 | /* DIR = 0 */ |
1692 | /* DIR = 0 */ |
1682 | 1693 | ||
1683 | /* DIR = 0 => IN int */ |
1694 | /* DIR = 0 => IN int */ |
1684 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ |
1695 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ |
1685 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
1696 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
1686 | ep = &hpcd->IN_ep[0]; |
1697 | ep = &hpcd->IN_ep[0]; |
1687 | 1698 | ||
1688 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
1699 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
1689 | ep->xfer_buff += ep->xfer_count; |
1700 | ep->xfer_buff += ep->xfer_count; |
Line 1703... | Line 1714... | ||
1703 | } |
1714 | } |
1704 | else |
1715 | else |
1705 | { |
1716 | { |
1706 | /* DIR = 1 */ |
1717 | /* DIR = 1 */ |
1707 | 1718 | ||
1708 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ |
1719 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ |
1709 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ |
1720 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ |
1710 | ep = &hpcd->OUT_ep[0]; |
1721 | ep = &hpcd->OUT_ep[0]; |
1711 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0); |
1722 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0); |
1712 | 1723 | ||
1713 | if ((wEPVal & USB_EP_SETUP) != 0U) |
1724 | if ((wEPVal & USB_EP_SETUP) != 0U) |
1714 | { |
1725 | { |
1715 | /* Get SETUP Packet*/ |
1726 | /* Get SETUP Packet */ |
1716 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
1727 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
1717 | 1728 | ||
1718 | USB_ReadPMA(hpcd->Instance, (uint8_t *)hpcd->Setup, |
1729 | USB_ReadPMA(hpcd->Instance, (uint8_t *)hpcd->Setup, |
1719 | ep->pmaadress, (uint16_t)ep->xfer_count); |
1730 | ep->pmaadress, (uint16_t)ep->xfer_count); |
1720 | 1731 | ||
1721 | /* SETUP bit kept frozen while CTR_RX = 1*/ |
1732 | /* SETUP bit kept frozen while CTR_RX = 1 */ |
1722 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
1733 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
1723 | 1734 | ||
1724 | /* Process SETUP Packet*/ |
1735 | /* Process SETUP Packet*/ |
1725 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1736 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1726 | hpcd->SetupStageCallback(hpcd); |
1737 | hpcd->SetupStageCallback(hpcd); |
1727 | #else |
1738 | #else |
1728 | HAL_PCD_SetupStageCallback(hpcd); |
1739 | HAL_PCD_SetupStageCallback(hpcd); |
1729 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1740 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1730 | } |
1741 | } |
1731 | - | ||
1732 | else if ((wEPVal & USB_EP_CTR_RX) != 0U) |
1742 | else if ((wEPVal & USB_EP_CTR_RX) != 0U) |
1733 | { |
1743 | { |
1734 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
1744 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
1735 | 1745 | ||
1736 | /* Get Control Data OUT Packet*/ |
1746 | /* Get Control Data OUT Packet */ |
1737 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
1747 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
1738 | 1748 | ||
1739 | if ((ep->xfer_count != 0U) && (ep->xfer_buff != 0U)) |
1749 | if ((ep->xfer_count != 0U) && (ep->xfer_buff != 0U)) |
1740 | { |
1750 | { |
1741 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, |
1751 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, |
1742 | ep->pmaadress, (uint16_t)ep->xfer_count); |
1752 | ep->pmaadress, (uint16_t)ep->xfer_count); |
1743 | 1753 | ||
1744 | ep->xfer_buff += ep->xfer_count; |
1754 | ep->xfer_buff += ep->xfer_count; |
1745 | 1755 | ||
1746 | /* Process Control Data OUT Packet*/ |
1756 | /* Process Control Data OUT Packet */ |
1747 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1757 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1748 | hpcd->DataOutStageCallback(hpcd, 0U); |
1758 | hpcd->DataOutStageCallback(hpcd, 0U); |
1749 | #else |
1759 | #else |
1750 | HAL_PCD_DataOutStageCallback(hpcd, 0U); |
1760 | HAL_PCD_DataOutStageCallback(hpcd, 0U); |
1751 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1761 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1752 | } |
1762 | } |
1753 | 1763 | ||
- | 1764 | if ((PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0) & USB_EP_SETUP) == 0U) |
|
- | 1765 | { |
|
1754 | PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket); |
1766 | PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket); |
1755 | PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID); |
1767 | PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID); |
- | 1768 | } |
|
1756 | } |
1769 | } |
1757 | } |
1770 | } |
1758 | } |
1771 | } |
1759 | else |
1772 | else |
1760 | { |
1773 | { |
1761 | /* Decode and service non control endpoints interrupt */ |
1774 | /* Decode and service non control endpoints interrupt */ |
1762 | - | ||
1763 | /* process related endpoint register */ |
1775 | /* process related endpoint register */ |
1764 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, epindex); |
1776 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, epindex); |
- | 1777 | ||
1765 | if ((wEPVal & USB_EP_CTR_RX) != 0U) |
1778 | if ((wEPVal & USB_EP_CTR_RX) != 0U) |
1766 | { |
1779 | { |
1767 | /* clear int flag */ |
1780 | /* clear int flag */ |
1768 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, epindex); |
1781 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, epindex); |
1769 | ep = &hpcd->OUT_ep[epindex]; |
1782 | ep = &hpcd->OUT_ep[epindex]; |
1770 | 1783 | ||
1771 | /* OUT double Buffering*/ |
1784 | /* OUT Single Buffering */ |
1772 | if (ep->doublebuffer == 0U) |
1785 | if (ep->doublebuffer == 0U) |
1773 | { |
1786 | { |
1774 | count = (uint16_t)PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
1787 | count = (uint16_t)PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
- | 1788 | ||
1775 | if (count != 0U) |
1789 | if (count != 0U) |
1776 | { |
1790 | { |
1777 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count); |
1791 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count); |
1778 | } |
1792 | } |
1779 | } |
1793 | } |
1780 | else |
1794 | else |
1781 | { |
1795 | { |
- | 1796 | /* manage double buffer bulk out */ |
|
1782 | if ((PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX) != 0U) |
1797 | if (ep->type == EP_TYPE_BULK) |
1783 | { |
1798 | { |
1784 | /*read from endpoint BUF0Addr buffer*/ |
- | |
1785 | count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
1799 | count = HAL_PCD_EP_DB_Receive(hpcd, ep, wEPVal); |
1786 | if (count != 0U) |
- | |
1787 | { |
- | |
1788 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count); |
- | |
1789 | } |
- | |
1790 | } |
1800 | } |
1791 | else |
1801 | else /* manage double buffer iso out */ |
1792 | { |
1802 | { |
- | 1803 | /* free EP OUT Buffer */ |
|
- | 1804 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U); |
|
- | 1805 | ||
- | 1806 | if ((PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX) != 0U) |
|
- | 1807 | { |
|
1793 | /*read from endpoint BUF1Addr buffer*/ |
1808 | /* read from endpoint BUF0Addr buffer */ |
1794 | count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
1809 | count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
- | 1810 | ||
1795 | if (count != 0U) |
1811 | if (count != 0U) |
- | 1812 | { |
|
- | 1813 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count); |
|
- | 1814 | } |
|
- | 1815 | } |
|
- | 1816 | else |
|
1796 | { |
1817 | { |
- | 1818 | /* read from endpoint BUF1Addr buffer */ |
|
- | 1819 | count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
|
- | 1820 | ||
- | 1821 | if (count != 0U) |
|
- | 1822 | { |
|
1797 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count); |
1823 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count); |
- | 1824 | } |
|
1798 | } |
1825 | } |
1799 | } |
1826 | } |
1800 | /* free EP OUT Buffer */ |
- | |
1801 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U); |
- | |
1802 | } |
1827 | } |
1803 | /*multi-packet on the NON control OUT endpoint*/ |
1828 | /* multi-packet on the NON control OUT endpoint */ |
1804 | ep->xfer_count += count; |
1829 | ep->xfer_count += count; |
1805 | ep->xfer_buff += count; |
1830 | ep->xfer_buff += count; |
1806 | 1831 | ||
1807 | if ((ep->xfer_len == 0U) || (count < ep->maxpacket)) |
1832 | if ((ep->xfer_len == 0U) || (count < ep->maxpacket)) |
1808 | { |
1833 | { |
Line 1813... | Line 1838... | ||
1813 | HAL_PCD_DataOutStageCallback(hpcd, ep->num); |
1838 | HAL_PCD_DataOutStageCallback(hpcd, ep->num); |
1814 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1839 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1815 | } |
1840 | } |
1816 | else |
1841 | else |
1817 | { |
1842 | { |
1818 | (void)HAL_PCD_EP_Receive(hpcd, ep->num, ep->xfer_buff, ep->xfer_len); |
1843 | (void) USB_EPStartXfer(hpcd->Instance, ep); |
1819 | } |
1844 | } |
1820 | - | ||
1821 | } /* if((wEPVal & EP_CTR_RX) */ |
1845 | } |
1822 | 1846 | ||
1823 | if ((wEPVal & USB_EP_CTR_TX) != 0U) |
1847 | if ((wEPVal & USB_EP_CTR_TX) != 0U) |
1824 | { |
1848 | { |
1825 | ep = &hpcd->IN_ep[epindex]; |
1849 | ep = &hpcd->IN_ep[epindex]; |
1826 | 1850 | ||
1827 | /* clear int flag */ |
1851 | /* clear int flag */ |
1828 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex); |
1852 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex); |
1829 | 1853 | ||
1830 | /*multi-packet on the NON control IN endpoint*/ |
- | |
1831 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
- | |
1832 | ep->xfer_buff += ep->xfer_count; |
- | |
1833 | - | ||
1834 | /* Zero Length Packet? */ |
- | |
1835 | if (ep->xfer_len == 0U) |
1854 | if (ep->type != EP_TYPE_BULK) |
1836 | { |
1855 | { |
- | 1856 | ep->xfer_len = 0U; |
|
- | 1857 | ||
- | 1858 | if ((wEPVal & USB_EP_DTOG_TX) != 0U) |
|
- | 1859 | { |
|
- | 1860 | PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, 0U); |
|
- | 1861 | } |
|
- | 1862 | else |
|
- | 1863 | { |
|
- | 1864 | PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, 0U); |
|
- | 1865 | } |
|
- | 1866 | ||
1837 | /* TX COMPLETE */ |
1867 | /* TX COMPLETE */ |
1838 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1868 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
1839 | hpcd->DataInStageCallback(hpcd, ep->num); |
1869 | hpcd->DataInStageCallback(hpcd, ep->num); |
1840 | #else |
1870 | #else |
1841 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
1871 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
1842 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1872 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
1843 | } |
1873 | } |
1844 | else |
1874 | else |
- | 1875 | /* Manage Bulk Single Buffer Transaction */ |
|
- | 1876 | if ((ep->type == EP_TYPE_BULK) && ((wEPVal & USB_EP_KIND) == 0U)) |
|
1845 | { |
1877 | { |
- | 1878 | /* multi-packet on the NON control IN endpoint */ |
|
- | 1879 | TxByteNbre = (uint16_t)PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
|
- | 1880 | ||
- | 1881 | if (ep->xfer_len > TxByteNbre) |
|
- | 1882 | { |
|
- | 1883 | ep->xfer_len -= TxByteNbre; |
|
- | 1884 | } |
|
- | 1885 | else |
|
- | 1886 | { |
|
- | 1887 | ep->xfer_len = 0U; |
|
- | 1888 | } |
|
- | 1889 | ||
- | 1890 | /* Zero Length Packet? */ |
|
- | 1891 | if (ep->xfer_len == 0U) |
|
- | 1892 | { |
|
- | 1893 | /* TX COMPLETE */ |
|
- | 1894 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1895 | hpcd->DataInStageCallback(hpcd, ep->num); |
|
- | 1896 | #else |
|
- | 1897 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
|
- | 1898 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 1899 | } |
|
- | 1900 | else |
|
- | 1901 | { |
|
- | 1902 | /* Transfer is not yet Done */ |
|
- | 1903 | ep->xfer_buff += TxByteNbre; |
|
- | 1904 | ep->xfer_count += TxByteNbre; |
|
- | 1905 | (void)USB_EPStartXfer(hpcd->Instance, ep); |
|
- | 1906 | } |
|
- | 1907 | } |
|
- | 1908 | /* Double Buffer bulk IN (bulk transfer Len > Ep_Mps) */ |
|
- | 1909 | else |
|
- | 1910 | { |
|
1846 | (void)HAL_PCD_EP_Transmit(hpcd, ep->num, ep->xfer_buff, ep->xfer_len); |
1911 | (void)HAL_PCD_EP_DB_Transmit(hpcd, ep, wEPVal); |
1847 | } |
1912 | } |
1848 | } |
1913 | } |
1849 | } |
1914 | } |
1850 | } |
1915 | } |
- | 1916 | ||
1851 | return HAL_OK; |
1917 | return HAL_OK; |
1852 | } |
1918 | } |
1853 | 1919 | ||
1854 | 1920 | ||
1855 | /** |
1921 | /** |
- | 1922 | * @brief Manage double buffer bulk out transaction from ISR |
|
- | 1923 | * @param hpcd PCD handle |
|
- | 1924 | * @param ep current endpoint handle |
|
- | 1925 | * @param wEPVal Last snapshot of EPRx register value taken in ISR |
|
- | 1926 | * @retval HAL status |
|
- | 1927 | */ |
|
- | 1928 | static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd, |
|
- | 1929 | PCD_EPTypeDef *ep, uint16_t wEPVal) |
|
- | 1930 | { |
|
- | 1931 | uint16_t count; |
|
- | 1932 | ||
- | 1933 | /* Manage Buffer0 OUT */ |
|
- | 1934 | if ((wEPVal & USB_EP_DTOG_RX) != 0U) |
|
- | 1935 | { |
|
- | 1936 | /* Get count of received Data on buffer0 */ |
|
- | 1937 | count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
|
- | 1938 | ||
- | 1939 | if (ep->xfer_len >= count) |
|
- | 1940 | { |
|
- | 1941 | ep->xfer_len -= count; |
|
- | 1942 | } |
|
- | 1943 | else |
|
- | 1944 | { |
|
- | 1945 | ep->xfer_len = 0U; |
|
- | 1946 | } |
|
- | 1947 | ||
- | 1948 | if (ep->xfer_len == 0U) |
|
- | 1949 | { |
|
- | 1950 | /* set NAK to OUT endpoint since double buffer is enabled */ |
|
- | 1951 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_NAK); |
|
- | 1952 | } |
|
- | 1953 | ||
- | 1954 | /* Check if Buffer1 is in blocked sate which requires to toggle */ |
|
- | 1955 | if ((wEPVal & USB_EP_DTOG_TX) != 0U) |
|
- | 1956 | { |
|
- | 1957 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U); |
|
- | 1958 | } |
|
- | 1959 | ||
- | 1960 | if (count != 0U) |
|
- | 1961 | { |
|
- | 1962 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count); |
|
- | 1963 | } |
|
- | 1964 | } |
|
- | 1965 | /* Manage Buffer 1 DTOG_RX=0 */ |
|
- | 1966 | else |
|
- | 1967 | { |
|
- | 1968 | /* Get count of received data */ |
|
- | 1969 | count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
|
- | 1970 | ||
- | 1971 | if (ep->xfer_len >= count) |
|
- | 1972 | { |
|
- | 1973 | ep->xfer_len -= count; |
|
- | 1974 | } |
|
- | 1975 | else |
|
- | 1976 | { |
|
- | 1977 | ep->xfer_len = 0U; |
|
- | 1978 | } |
|
- | 1979 | ||
- | 1980 | if (ep->xfer_len == 0U) |
|
- | 1981 | { |
|
- | 1982 | /* set NAK on the current endpoint */ |
|
- | 1983 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_NAK); |
|
- | 1984 | } |
|
- | 1985 | ||
- | 1986 | /*Need to FreeUser Buffer*/ |
|
- | 1987 | if ((wEPVal & USB_EP_DTOG_TX) == 0U) |
|
- | 1988 | { |
|
- | 1989 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U); |
|
- | 1990 | } |
|
- | 1991 | ||
- | 1992 | if (count != 0U) |
|
- | 1993 | { |
|
- | 1994 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count); |
|
- | 1995 | } |
|
- | 1996 | } |
|
- | 1997 | ||
- | 1998 | return count; |
|
- | 1999 | } |
|
- | 2000 | ||
- | 2001 | ||
- | 2002 | /** |
|
- | 2003 | * @brief Manage double buffer bulk IN transaction from ISR |
|
- | 2004 | * @param hpcd PCD handle |
|
- | 2005 | * @param ep current endpoint handle |
|
- | 2006 | * @param wEPVal Last snapshot of EPRx register value taken in ISR |
|
- | 2007 | * @retval HAL status |
|
- | 2008 | */ |
|
- | 2009 | static HAL_StatusTypeDef HAL_PCD_EP_DB_Transmit(PCD_HandleTypeDef *hpcd, |
|
- | 2010 | PCD_EPTypeDef *ep, uint16_t wEPVal) |
|
- | 2011 | { |
|
- | 2012 | uint32_t len; |
|
- | 2013 | uint16_t TxByteNbre; |
|
- | 2014 | ||
- | 2015 | /* Data Buffer0 ACK received */ |
|
- | 2016 | if ((wEPVal & USB_EP_DTOG_TX) != 0U) |
|
- | 2017 | { |
|
- | 2018 | /* multi-packet on the NON control IN endpoint */ |
|
- | 2019 | TxByteNbre = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
|
- | 2020 | ||
- | 2021 | if (ep->xfer_len > TxByteNbre) |
|
- | 2022 | { |
|
- | 2023 | ep->xfer_len -= TxByteNbre; |
|
- | 2024 | } |
|
- | 2025 | else |
|
- | 2026 | { |
|
- | 2027 | ep->xfer_len = 0U; |
|
- | 2028 | } |
|
- | 2029 | /* Transfer is completed */ |
|
- | 2030 | if (ep->xfer_len == 0U) |
|
- | 2031 | { |
|
- | 2032 | PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, 0U); |
|
- | 2033 | PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, 0U); |
|
- | 2034 | ||
- | 2035 | /* TX COMPLETE */ |
|
- | 2036 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2037 | hpcd->DataInStageCallback(hpcd, ep->num); |
|
- | 2038 | #else |
|
- | 2039 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
|
- | 2040 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 2041 | ||
- | 2042 | if ((wEPVal & USB_EP_DTOG_RX) != 0U) |
|
- | 2043 | { |
|
- | 2044 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U); |
|
- | 2045 | } |
|
- | 2046 | } |
|
- | 2047 | else /* Transfer is not yet Done */ |
|
- | 2048 | { |
|
- | 2049 | /* need to Free USB Buff */ |
|
- | 2050 | if ((wEPVal & USB_EP_DTOG_RX) != 0U) |
|
- | 2051 | { |
|
- | 2052 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U); |
|
- | 2053 | } |
|
- | 2054 | ||
- | 2055 | /* Still there is data to Fill in the next Buffer */ |
|
- | 2056 | if (ep->xfer_fill_db == 1U) |
|
- | 2057 | { |
|
- | 2058 | ep->xfer_buff += TxByteNbre; |
|
- | 2059 | ep->xfer_count += TxByteNbre; |
|
- | 2060 | ||
- | 2061 | /* Calculate the len of the new buffer to fill */ |
|
- | 2062 | if (ep->xfer_len_db >= ep->maxpacket) |
|
- | 2063 | { |
|
- | 2064 | len = ep->maxpacket; |
|
- | 2065 | ep->xfer_len_db -= len; |
|
- | 2066 | } |
|
- | 2067 | else if (ep->xfer_len_db == 0U) |
|
- | 2068 | { |
|
- | 2069 | len = TxByteNbre; |
|
- | 2070 | ep->xfer_fill_db = 0U; |
|
- | 2071 | } |
|
- | 2072 | else |
|
- | 2073 | { |
|
- | 2074 | ep->xfer_fill_db = 0U; |
|
- | 2075 | len = ep->xfer_len_db; |
|
- | 2076 | ep->xfer_len_db = 0U; |
|
- | 2077 | } |
|
- | 2078 | ||
- | 2079 | /* Write remaining Data to Buffer */ |
|
- | 2080 | /* Set the Double buffer counter for pma buffer1 */ |
|
- | 2081 | PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, len); |
|
- | 2082 | ||
- | 2083 | /* Copy user buffer to USB PMA */ |
|
- | 2084 | USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, (uint16_t)len); |
|
- | 2085 | } |
|
- | 2086 | } |
|
- | 2087 | } |
|
- | 2088 | else /* Data Buffer1 ACK received */ |
|
- | 2089 | { |
|
- | 2090 | /* multi-packet on the NON control IN endpoint */ |
|
- | 2091 | TxByteNbre = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
|
- | 2092 | ||
- | 2093 | if (ep->xfer_len >= TxByteNbre) |
|
- | 2094 | { |
|
- | 2095 | ep->xfer_len -= TxByteNbre; |
|
- | 2096 | } |
|
- | 2097 | else |
|
- | 2098 | { |
|
- | 2099 | ep->xfer_len = 0U; |
|
- | 2100 | } |
|
- | 2101 | ||
- | 2102 | /* Transfer is completed */ |
|
- | 2103 | if (ep->xfer_len == 0U) |
|
- | 2104 | { |
|
- | 2105 | PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, 0U); |
|
- | 2106 | PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, 0U); |
|
- | 2107 | ||
- | 2108 | /* TX COMPLETE */ |
|
- | 2109 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2110 | hpcd->DataInStageCallback(hpcd, ep->num); |
|
- | 2111 | #else |
|
- | 2112 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
|
- | 2113 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 2114 | ||
- | 2115 | /* need to Free USB Buff */ |
|
- | 2116 | if ((wEPVal & USB_EP_DTOG_RX) == 0U) |
|
- | 2117 | { |
|
- | 2118 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U); |
|
- | 2119 | } |
|
- | 2120 | } |
|
- | 2121 | else /* Transfer is not yet Done */ |
|
- | 2122 | { |
|
- | 2123 | /* need to Free USB Buff */ |
|
- | 2124 | if ((wEPVal & USB_EP_DTOG_RX) == 0U) |
|
- | 2125 | { |
|
- | 2126 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U); |
|
- | 2127 | } |
|
- | 2128 | ||
- | 2129 | /* Still there is data to Fill in the next Buffer */ |
|
- | 2130 | if (ep->xfer_fill_db == 1U) |
|
- | 2131 | { |
|
- | 2132 | ep->xfer_buff += TxByteNbre; |
|
- | 2133 | ep->xfer_count += TxByteNbre; |
|
- | 2134 | ||
- | 2135 | /* Calculate the len of the new buffer to fill */ |
|
- | 2136 | if (ep->xfer_len_db >= ep->maxpacket) |
|
- | 2137 | { |
|
- | 2138 | len = ep->maxpacket; |
|
- | 2139 | ep->xfer_len_db -= len; |
|
- | 2140 | } |
|
- | 2141 | else if (ep->xfer_len_db == 0U) |
|
- | 2142 | { |
|
- | 2143 | len = TxByteNbre; |
|
- | 2144 | ep->xfer_fill_db = 0U; |
|
- | 2145 | } |
|
- | 2146 | else |
|
- | 2147 | { |
|
- | 2148 | len = ep->xfer_len_db; |
|
- | 2149 | ep->xfer_len_db = 0U; |
|
- | 2150 | ep->xfer_fill_db = 0; |
|
- | 2151 | } |
|
- | 2152 | ||
- | 2153 | /* Set the Double buffer counter for pmabuffer1 */ |
|
- | 2154 | PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, len); |
|
- | 2155 | ||
- | 2156 | /* Copy the user buffer to USB PMA */ |
|
- | 2157 | USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, (uint16_t)len); |
|
- | 2158 | } |
|
- | 2159 | } |
|
- | 2160 | } |
|
- | 2161 | ||
- | 2162 | /*enable endpoint IN*/ |
|
- | 2163 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_VALID); |
|
- | 2164 | ||
- | 2165 | return HAL_OK; |
|
- | 2166 | } |
|
- | 2167 | ||
- | 2168 | ||
- | 2169 | ||
- | 2170 | /** |
|
1856 | * @} |
2171 | * @} |
1857 | */ |
2172 | */ |
1858 | #endif /* defined (USB) */ |
2173 | #endif /* defined (USB) */ |
1859 | #endif /* HAL_PCD_MODULE_ENABLED */ |
2174 | #endif /* HAL_PCD_MODULE_ENABLED */ |
1860 | 2175 |