stm32f1xx_hal_hcd.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_hcd.c
  4. * @author MCD Application Team
  5. * @brief HCD HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the USB Peripheral Controller:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State functions
  12. *
  13. ******************************************************************************
  14. * @attention
  15. *
  16. * Copyright (c) 2016 STMicroelectronics.
  17. * All rights reserved.
  18. *
  19. * This software is licensed under terms that can be found in the LICENSE file
  20. * in the root directory of this software component.
  21. * If no LICENSE file comes with this software, it is provided AS-IS.
  22. *
  23. ******************************************************************************
  24. @verbatim
  25. ==============================================================================
  26. ##### How to use this driver #####
  27. ==============================================================================
  28. [..]
  29. (#)Declare a HCD_HandleTypeDef handle structure, for example:
  30. HCD_HandleTypeDef hhcd;
  31. (#)Fill parameters of Init structure in HCD handle
  32. (#)Call HAL_HCD_Init() API to initialize the HCD peripheral (Core, Host core, ...)
  33. (#)Initialize the HCD low level resources through the HAL_HCD_MspInit() API:
  34. (##) Enable the HCD/USB Low Level interface clock using the following macros
  35. (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  36. (##) Initialize the related GPIO clocks
  37. (##) Configure HCD pin-out
  38. (##) Configure HCD NVIC interrupt
  39. (#)Associate the Upper USB Host stack to the HAL HCD Driver:
  40. (##) hhcd.pData = phost;
  41. (#)Enable HCD transmission and reception:
  42. (##) HAL_HCD_Start();
  43. @endverbatim
  44. ******************************************************************************
  45. */
  46. /* Includes ------------------------------------------------------------------*/
  47. #include "stm32f1xx_hal.h"
  48. /** @addtogroup STM32F1xx_HAL_Driver
  49. * @{
  50. */
  51. #ifdef HAL_HCD_MODULE_ENABLED
  52. #if defined (USB_OTG_FS)
  53. /** @defgroup HCD HCD
  54. * @brief HCD HAL module driver
  55. * @{
  56. */
  57. /* Private typedef -----------------------------------------------------------*/
  58. /* Private define ------------------------------------------------------------*/
  59. /* Private macro -------------------------------------------------------------*/
  60. /* Private variables ---------------------------------------------------------*/
  61. /* Private function prototypes -----------------------------------------------*/
  62. /** @defgroup HCD_Private_Functions HCD Private Functions
  63. * @{
  64. */
  65. static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
  66. static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
  67. static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd);
  68. static void HCD_Port_IRQHandler(HCD_HandleTypeDef *hhcd);
  69. /**
  70. * @}
  71. */
  72. /* Exported functions --------------------------------------------------------*/
  73. /** @defgroup HCD_Exported_Functions HCD Exported Functions
  74. * @{
  75. */
  76. /** @defgroup HCD_Exported_Functions_Group1 Initialization and de-initialization functions
  77. * @brief Initialization and Configuration functions
  78. *
  79. @verbatim
  80. ===============================================================================
  81. ##### Initialization and de-initialization functions #####
  82. ===============================================================================
  83. [..] This section provides functions allowing to:
  84. @endverbatim
  85. * @{
  86. */
  87. /**
  88. * @brief Initialize the host driver.
  89. * @param hhcd HCD handle
  90. * @retval HAL status
  91. */
  92. HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd)
  93. {
  94. /* Check the HCD handle allocation */
  95. if (hhcd == NULL)
  96. {
  97. return HAL_ERROR;
  98. }
  99. /* Check the parameters */
  100. assert_param(IS_HCD_ALL_INSTANCE(hhcd->Instance));
  101. if (hhcd->State == HAL_HCD_STATE_RESET)
  102. {
  103. /* Allocate lock resource and initialize it */
  104. hhcd->Lock = HAL_UNLOCKED;
  105. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  106. hhcd->SOFCallback = HAL_HCD_SOF_Callback;
  107. hhcd->ConnectCallback = HAL_HCD_Connect_Callback;
  108. hhcd->DisconnectCallback = HAL_HCD_Disconnect_Callback;
  109. hhcd->PortEnabledCallback = HAL_HCD_PortEnabled_Callback;
  110. hhcd->PortDisabledCallback = HAL_HCD_PortDisabled_Callback;
  111. hhcd->HC_NotifyURBChangeCallback = HAL_HCD_HC_NotifyURBChange_Callback;
  112. if (hhcd->MspInitCallback == NULL)
  113. {
  114. hhcd->MspInitCallback = HAL_HCD_MspInit;
  115. }
  116. /* Init the low level hardware */
  117. hhcd->MspInitCallback(hhcd);
  118. #else
  119. /* Init the low level hardware : GPIO, CLOCK, NVIC... */
  120. HAL_HCD_MspInit(hhcd);
  121. #endif /* (USE_HAL_HCD_REGISTER_CALLBACKS) */
  122. }
  123. hhcd->State = HAL_HCD_STATE_BUSY;
  124. /* Disable DMA mode for FS instance */
  125. hhcd->Init.dma_enable = 0U;
  126. /* Disable the Interrupts */
  127. __HAL_HCD_DISABLE(hhcd);
  128. /* Init the Core (common init.) */
  129. if (USB_CoreInit(hhcd->Instance, hhcd->Init) != HAL_OK)
  130. {
  131. hhcd->State = HAL_HCD_STATE_ERROR;
  132. return HAL_ERROR;
  133. }
  134. /* Force Host Mode */
  135. if (USB_SetCurrentMode(hhcd->Instance, USB_HOST_MODE) != HAL_OK)
  136. {
  137. hhcd->State = HAL_HCD_STATE_ERROR;
  138. return HAL_ERROR;
  139. }
  140. /* Init Host */
  141. if (USB_HostInit(hhcd->Instance, hhcd->Init) != HAL_OK)
  142. {
  143. hhcd->State = HAL_HCD_STATE_ERROR;
  144. return HAL_ERROR;
  145. }
  146. hhcd->State = HAL_HCD_STATE_READY;
  147. return HAL_OK;
  148. }
  149. /**
  150. * @brief Initialize a host channel.
  151. * @param hhcd HCD handle
  152. * @param ch_num Channel number.
  153. * This parameter can be a value from 1 to 15
  154. * @param epnum Endpoint number.
  155. * This parameter can be a value from 1 to 15
  156. * @param dev_address Current device address
  157. * This parameter can be a value from 0 to 255
  158. * @param speed Current device speed.
  159. * This parameter can be one of these values:
  160. * HCD_DEVICE_SPEED_FULL: Full speed mode,
  161. * HCD_DEVICE_SPEED_LOW: Low speed mode
  162. * @param ep_type Endpoint Type.
  163. * This parameter can be one of these values:
  164. * EP_TYPE_CTRL: Control type,
  165. * EP_TYPE_ISOC: Isochronous type,
  166. * EP_TYPE_BULK: Bulk type,
  167. * EP_TYPE_INTR: Interrupt type
  168. * @param mps Max Packet Size.
  169. * This parameter can be a value from 0 to32K
  170. * @retval HAL status
  171. */
  172. HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, uint8_t ch_num, uint8_t epnum,
  173. uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
  174. {
  175. HAL_StatusTypeDef status;
  176. uint32_t HCcharMps = mps;
  177. __HAL_LOCK(hhcd);
  178. hhcd->hc[ch_num].do_ping = 0U;
  179. hhcd->hc[ch_num].dev_addr = dev_address;
  180. hhcd->hc[ch_num].ch_num = ch_num;
  181. hhcd->hc[ch_num].ep_type = ep_type;
  182. hhcd->hc[ch_num].ep_num = epnum & 0x7FU;
  183. (void)HAL_HCD_HC_ClearHubInfo(hhcd, ch_num);
  184. if ((epnum & 0x80U) == 0x80U)
  185. {
  186. hhcd->hc[ch_num].ep_is_in = 1U;
  187. }
  188. else
  189. {
  190. hhcd->hc[ch_num].ep_is_in = 0U;
  191. }
  192. hhcd->hc[ch_num].speed = speed;
  193. hhcd->hc[ch_num].max_packet = (uint16_t)HCcharMps;
  194. status = USB_HC_Init(hhcd->Instance, ch_num, epnum,
  195. dev_address, speed, ep_type, (uint16_t)HCcharMps);
  196. __HAL_UNLOCK(hhcd);
  197. return status;
  198. }
  199. /**
  200. * @brief Halt a host channel.
  201. * @param hhcd HCD handle
  202. * @param ch_num Channel number.
  203. * This parameter can be a value from 1 to 15
  204. * @retval HAL status
  205. */
  206. HAL_StatusTypeDef HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd, uint8_t ch_num)
  207. {
  208. HAL_StatusTypeDef status = HAL_OK;
  209. __HAL_LOCK(hhcd);
  210. (void)USB_HC_Halt(hhcd->Instance, ch_num);
  211. __HAL_UNLOCK(hhcd);
  212. return status;
  213. }
  214. /**
  215. * @brief DeInitialize the host driver.
  216. * @param hhcd HCD handle
  217. * @retval HAL status
  218. */
  219. HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd)
  220. {
  221. /* Check the HCD handle allocation */
  222. if (hhcd == NULL)
  223. {
  224. return HAL_ERROR;
  225. }
  226. hhcd->State = HAL_HCD_STATE_BUSY;
  227. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  228. if (hhcd->MspDeInitCallback == NULL)
  229. {
  230. hhcd->MspDeInitCallback = HAL_HCD_MspDeInit; /* Legacy weak MspDeInit */
  231. }
  232. /* DeInit the low level hardware */
  233. hhcd->MspDeInitCallback(hhcd);
  234. #else
  235. /* DeInit the low level hardware: CLOCK, NVIC.*/
  236. HAL_HCD_MspDeInit(hhcd);
  237. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  238. __HAL_HCD_DISABLE(hhcd);
  239. hhcd->State = HAL_HCD_STATE_RESET;
  240. return HAL_OK;
  241. }
  242. /**
  243. * @brief Initialize the HCD MSP.
  244. * @param hhcd HCD handle
  245. * @retval None
  246. */
  247. __weak void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
  248. {
  249. /* Prevent unused argument(s) compilation warning */
  250. UNUSED(hhcd);
  251. /* NOTE : This function should not be modified, when the callback is needed,
  252. the HAL_HCD_MspInit could be implemented in the user file
  253. */
  254. }
  255. /**
  256. * @brief DeInitialize the HCD MSP.
  257. * @param hhcd HCD handle
  258. * @retval None
  259. */
  260. __weak void HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd)
  261. {
  262. /* Prevent unused argument(s) compilation warning */
  263. UNUSED(hhcd);
  264. /* NOTE : This function should not be modified, when the callback is needed,
  265. the HAL_HCD_MspDeInit could be implemented in the user file
  266. */
  267. }
  268. /**
  269. * @}
  270. */
  271. /** @defgroup HCD_Exported_Functions_Group2 Input and Output operation functions
  272. * @brief HCD IO operation functions
  273. *
  274. @verbatim
  275. ===============================================================================
  276. ##### IO operation functions #####
  277. ===============================================================================
  278. [..] This subsection provides a set of functions allowing to manage the USB Host Data
  279. Transfer
  280. @endverbatim
  281. * @{
  282. */
  283. /**
  284. * @brief Submit a new URB for processing.
  285. * @param hhcd HCD handle
  286. * @param ch_num Channel number.
  287. * This parameter can be a value from 1 to 15
  288. * @param direction Channel number.
  289. * This parameter can be one of these values:
  290. * 0 : Output / 1 : Input
  291. * @param ep_type Endpoint Type.
  292. * This parameter can be one of these values:
  293. * EP_TYPE_CTRL: Control type/
  294. * EP_TYPE_ISOC: Isochronous type/
  295. * EP_TYPE_BULK: Bulk type/
  296. * EP_TYPE_INTR: Interrupt type/
  297. * @param token Endpoint Type.
  298. * This parameter can be one of these values:
  299. * 0: HC_PID_SETUP / 1: HC_PID_DATA1
  300. * @param pbuff pointer to URB data
  301. * @param length Length of URB data
  302. * @param do_ping activate do ping protocol (for high speed only).
  303. * This parameter can be one of these values:
  304. * 0 : do ping inactive / 1 : do ping active
  305. * @retval HAL status
  306. */
  307. HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd,
  308. uint8_t ch_num,
  309. uint8_t direction,
  310. uint8_t ep_type,
  311. uint8_t token,
  312. uint8_t *pbuff,
  313. uint16_t length,
  314. uint8_t do_ping)
  315. {
  316. hhcd->hc[ch_num].ep_is_in = direction;
  317. hhcd->hc[ch_num].ep_type = ep_type;
  318. if (token == 0U)
  319. {
  320. hhcd->hc[ch_num].data_pid = HC_PID_SETUP;
  321. hhcd->hc[ch_num].do_ping = do_ping;
  322. }
  323. else
  324. {
  325. hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
  326. }
  327. /* Manage Data Toggle */
  328. switch (ep_type)
  329. {
  330. case EP_TYPE_CTRL:
  331. if (token == 1U) /* send data */
  332. {
  333. if (direction == 0U)
  334. {
  335. if (length == 0U)
  336. {
  337. /* For Status OUT stage, Length == 0U, Status Out PID = 1 */
  338. hhcd->hc[ch_num].toggle_out = 1U;
  339. }
  340. /* Set the Data Toggle bit as per the Flag */
  341. if (hhcd->hc[ch_num].toggle_out == 0U)
  342. {
  343. /* Put the PID 0 */
  344. hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
  345. }
  346. else
  347. {
  348. /* Put the PID 1 */
  349. hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
  350. }
  351. }
  352. }
  353. break;
  354. case EP_TYPE_BULK:
  355. if (direction == 0U)
  356. {
  357. /* Set the Data Toggle bit as per the Flag */
  358. if (hhcd->hc[ch_num].toggle_out == 0U)
  359. {
  360. /* Put the PID 0 */
  361. hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
  362. }
  363. else
  364. {
  365. /* Put the PID 1 */
  366. hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
  367. }
  368. }
  369. else
  370. {
  371. if (hhcd->hc[ch_num].toggle_in == 0U)
  372. {
  373. hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
  374. }
  375. else
  376. {
  377. hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
  378. }
  379. }
  380. break;
  381. case EP_TYPE_INTR:
  382. if (direction == 0U)
  383. {
  384. /* Set the Data Toggle bit as per the Flag */
  385. if (hhcd->hc[ch_num].toggle_out == 0U)
  386. {
  387. /* Put the PID 0 */
  388. hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
  389. }
  390. else
  391. {
  392. /* Put the PID 1 */
  393. hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
  394. }
  395. }
  396. else
  397. {
  398. if (hhcd->hc[ch_num].toggle_in == 0U)
  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. break;
  408. case EP_TYPE_ISOC:
  409. hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
  410. break;
  411. default:
  412. break;
  413. }
  414. hhcd->hc[ch_num].xfer_buff = pbuff;
  415. hhcd->hc[ch_num].xfer_len = length;
  416. hhcd->hc[ch_num].urb_state = URB_IDLE;
  417. hhcd->hc[ch_num].xfer_count = 0U;
  418. hhcd->hc[ch_num].ch_num = ch_num;
  419. hhcd->hc[ch_num].state = HC_IDLE;
  420. return USB_HC_StartXfer(hhcd->Instance, &hhcd->hc[ch_num]);
  421. }
  422. /**
  423. * @brief Handle HCD interrupt request.
  424. * @param hhcd HCD handle
  425. * @retval None
  426. */
  427. void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd)
  428. {
  429. USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
  430. uint32_t USBx_BASE = (uint32_t)USBx;
  431. uint32_t i;
  432. uint32_t interrupt;
  433. /* Ensure that we are in device mode */
  434. if (USB_GetMode(hhcd->Instance) == USB_OTG_MODE_HOST)
  435. {
  436. /* Avoid spurious interrupt */
  437. if (__HAL_HCD_IS_INVALID_INTERRUPT(hhcd))
  438. {
  439. return;
  440. }
  441. if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
  442. {
  443. /* Incorrect mode, acknowledge the interrupt */
  444. __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
  445. }
  446. if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR))
  447. {
  448. /* Incorrect mode, acknowledge the interrupt */
  449. __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR);
  450. }
  451. if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE))
  452. {
  453. /* Incorrect mode, acknowledge the interrupt */
  454. __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE);
  455. }
  456. if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_MMIS))
  457. {
  458. /* Incorrect mode, acknowledge the interrupt */
  459. __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_MMIS);
  460. }
  461. /* Handle Host Disconnect Interrupts */
  462. if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT))
  463. {
  464. __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT);
  465. if ((USBx_HPRT0 & USB_OTG_HPRT_PCSTS) == 0U)
  466. {
  467. /* Flush USB Fifo */
  468. (void)USB_FlushTxFifo(USBx, 0x10U);
  469. (void)USB_FlushRxFifo(USBx);
  470. if (hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY)
  471. {
  472. /* Restore FS Clock */
  473. (void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_48_MHZ);
  474. }
  475. /* Handle Host Port Disconnect Interrupt */
  476. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  477. hhcd->DisconnectCallback(hhcd);
  478. #else
  479. HAL_HCD_Disconnect_Callback(hhcd);
  480. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  481. }
  482. }
  483. /* Handle Host Port Interrupts */
  484. if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HPRTINT))
  485. {
  486. HCD_Port_IRQHandler(hhcd);
  487. }
  488. /* Handle Host SOF Interrupt */
  489. if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_SOF))
  490. {
  491. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  492. hhcd->SOFCallback(hhcd);
  493. #else
  494. HAL_HCD_SOF_Callback(hhcd);
  495. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  496. __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_SOF);
  497. }
  498. /* Handle Host channel Interrupt */
  499. if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT))
  500. {
  501. interrupt = USB_HC_ReadInterrupt(hhcd->Instance);
  502. for (i = 0U; i < hhcd->Init.Host_channels; i++)
  503. {
  504. if ((interrupt & (1UL << (i & 0xFU))) != 0U)
  505. {
  506. if ((USBx_HC(i)->HCCHAR & USB_OTG_HCCHAR_EPDIR) == USB_OTG_HCCHAR_EPDIR)
  507. {
  508. HCD_HC_IN_IRQHandler(hhcd, (uint8_t)i);
  509. }
  510. else
  511. {
  512. HCD_HC_OUT_IRQHandler(hhcd, (uint8_t)i);
  513. }
  514. }
  515. }
  516. __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_HCINT);
  517. }
  518. /* Handle Rx Queue Level Interrupts */
  519. if ((__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_RXFLVL)) != 0U)
  520. {
  521. USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
  522. HCD_RXQLVL_IRQHandler(hhcd);
  523. USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
  524. }
  525. }
  526. }
  527. /**
  528. * @brief Handles HCD Wakeup interrupt request.
  529. * @param hhcd HCD handle
  530. * @retval HAL status
  531. */
  532. void HAL_HCD_WKUP_IRQHandler(HCD_HandleTypeDef *hhcd)
  533. {
  534. UNUSED(hhcd);
  535. }
  536. /**
  537. * @brief SOF callback.
  538. * @param hhcd HCD handle
  539. * @retval None
  540. */
  541. __weak void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
  542. {
  543. /* Prevent unused argument(s) compilation warning */
  544. UNUSED(hhcd);
  545. /* NOTE : This function should not be modified, when the callback is needed,
  546. the HAL_HCD_SOF_Callback could be implemented in the user file
  547. */
  548. }
  549. /**
  550. * @brief Connection Event callback.
  551. * @param hhcd HCD handle
  552. * @retval None
  553. */
  554. __weak void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
  555. {
  556. /* Prevent unused argument(s) compilation warning */
  557. UNUSED(hhcd);
  558. /* NOTE : This function should not be modified, when the callback is needed,
  559. the HAL_HCD_Connect_Callback could be implemented in the user file
  560. */
  561. }
  562. /**
  563. * @brief Disconnection Event callback.
  564. * @param hhcd HCD handle
  565. * @retval None
  566. */
  567. __weak void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
  568. {
  569. /* Prevent unused argument(s) compilation warning */
  570. UNUSED(hhcd);
  571. /* NOTE : This function should not be modified, when the callback is needed,
  572. the HAL_HCD_Disconnect_Callback could be implemented in the user file
  573. */
  574. }
  575. /**
  576. * @brief Port Enabled Event callback.
  577. * @param hhcd HCD handle
  578. * @retval None
  579. */
  580. __weak void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd)
  581. {
  582. /* Prevent unused argument(s) compilation warning */
  583. UNUSED(hhcd);
  584. /* NOTE : This function should not be modified, when the callback is needed,
  585. the HAL_HCD_Disconnect_Callback could be implemented in the user file
  586. */
  587. }
  588. /**
  589. * @brief Port Disabled Event callback.
  590. * @param hhcd HCD handle
  591. * @retval None
  592. */
  593. __weak void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd)
  594. {
  595. /* Prevent unused argument(s) compilation warning */
  596. UNUSED(hhcd);
  597. /* NOTE : This function should not be modified, when the callback is needed,
  598. the HAL_HCD_Disconnect_Callback could be implemented in the user file
  599. */
  600. }
  601. /**
  602. * @brief Notify URB state change callback.
  603. * @param hhcd HCD handle
  604. * @param chnum Channel number.
  605. * This parameter can be a value from 1 to 15
  606. * @param urb_state:
  607. * This parameter can be one of these values:
  608. * URB_IDLE/
  609. * URB_DONE/
  610. * URB_NOTREADY/
  611. * URB_NYET/
  612. * URB_ERROR/
  613. * URB_STALL/
  614. * @retval None
  615. */
  616. __weak void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
  617. {
  618. /* Prevent unused argument(s) compilation warning */
  619. UNUSED(hhcd);
  620. UNUSED(chnum);
  621. UNUSED(urb_state);
  622. /* NOTE : This function should not be modified, when the callback is needed,
  623. the HAL_HCD_HC_NotifyURBChange_Callback could be implemented in the user file
  624. */
  625. }
  626. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  627. /**
  628. * @brief Register a User USB HCD Callback
  629. * To be used instead of the weak predefined callback
  630. * @param hhcd USB HCD handle
  631. * @param CallbackID ID of the callback to be registered
  632. * This parameter can be one of the following values:
  633. * @arg @ref HAL_HCD_SOF_CB_ID USB HCD SOF callback ID
  634. * @arg @ref HAL_HCD_CONNECT_CB_ID USB HCD Connect callback ID
  635. * @arg @ref HAL_HCD_DISCONNECT_CB_ID OTG HCD Disconnect callback ID
  636. * @arg @ref HAL_HCD_PORT_ENABLED_CB_ID USB HCD Port Enable callback ID
  637. * @arg @ref HAL_HCD_PORT_DISABLED_CB_ID USB HCD Port Disable callback ID
  638. * @arg @ref HAL_HCD_MSPINIT_CB_ID MspDeInit callback ID
  639. * @arg @ref HAL_HCD_MSPDEINIT_CB_ID MspDeInit callback ID
  640. * @param pCallback pointer to the Callback function
  641. * @retval HAL status
  642. */
  643. HAL_StatusTypeDef HAL_HCD_RegisterCallback(HCD_HandleTypeDef *hhcd,
  644. HAL_HCD_CallbackIDTypeDef CallbackID,
  645. pHCD_CallbackTypeDef pCallback)
  646. {
  647. HAL_StatusTypeDef status = HAL_OK;
  648. if (pCallback == NULL)
  649. {
  650. /* Update the error code */
  651. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  652. return HAL_ERROR;
  653. }
  654. /* Process locked */
  655. __HAL_LOCK(hhcd);
  656. if (hhcd->State == HAL_HCD_STATE_READY)
  657. {
  658. switch (CallbackID)
  659. {
  660. case HAL_HCD_SOF_CB_ID :
  661. hhcd->SOFCallback = pCallback;
  662. break;
  663. case HAL_HCD_CONNECT_CB_ID :
  664. hhcd->ConnectCallback = pCallback;
  665. break;
  666. case HAL_HCD_DISCONNECT_CB_ID :
  667. hhcd->DisconnectCallback = pCallback;
  668. break;
  669. case HAL_HCD_PORT_ENABLED_CB_ID :
  670. hhcd->PortEnabledCallback = pCallback;
  671. break;
  672. case HAL_HCD_PORT_DISABLED_CB_ID :
  673. hhcd->PortDisabledCallback = pCallback;
  674. break;
  675. case HAL_HCD_MSPINIT_CB_ID :
  676. hhcd->MspInitCallback = pCallback;
  677. break;
  678. case HAL_HCD_MSPDEINIT_CB_ID :
  679. hhcd->MspDeInitCallback = pCallback;
  680. break;
  681. default :
  682. /* Update the error code */
  683. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  684. /* Return error status */
  685. status = HAL_ERROR;
  686. break;
  687. }
  688. }
  689. else if (hhcd->State == HAL_HCD_STATE_RESET)
  690. {
  691. switch (CallbackID)
  692. {
  693. case HAL_HCD_MSPINIT_CB_ID :
  694. hhcd->MspInitCallback = pCallback;
  695. break;
  696. case HAL_HCD_MSPDEINIT_CB_ID :
  697. hhcd->MspDeInitCallback = pCallback;
  698. break;
  699. default :
  700. /* Update the error code */
  701. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  702. /* Return error status */
  703. status = HAL_ERROR;
  704. break;
  705. }
  706. }
  707. else
  708. {
  709. /* Update the error code */
  710. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  711. /* Return error status */
  712. status = HAL_ERROR;
  713. }
  714. /* Release Lock */
  715. __HAL_UNLOCK(hhcd);
  716. return status;
  717. }
  718. /**
  719. * @brief Unregister an USB HCD Callback
  720. * USB HCD callback is redirected to the weak predefined callback
  721. * @param hhcd USB HCD handle
  722. * @param CallbackID ID of the callback to be unregistered
  723. * This parameter can be one of the following values:
  724. * @arg @ref HAL_HCD_SOF_CB_ID USB HCD SOF callback ID
  725. * @arg @ref HAL_HCD_CONNECT_CB_ID USB HCD Connect callback ID
  726. * @arg @ref HAL_HCD_DISCONNECT_CB_ID OTG HCD Disconnect callback ID
  727. * @arg @ref HAL_HCD_PORT_ENABLED_CB_ID USB HCD Port Enabled callback ID
  728. * @arg @ref HAL_HCD_PORT_DISABLED_CB_ID USB HCD Port Disabled callback ID
  729. * @arg @ref HAL_HCD_MSPINIT_CB_ID MspDeInit callback ID
  730. * @arg @ref HAL_HCD_MSPDEINIT_CB_ID MspDeInit callback ID
  731. * @retval HAL status
  732. */
  733. HAL_StatusTypeDef HAL_HCD_UnRegisterCallback(HCD_HandleTypeDef *hhcd, HAL_HCD_CallbackIDTypeDef CallbackID)
  734. {
  735. HAL_StatusTypeDef status = HAL_OK;
  736. /* Process locked */
  737. __HAL_LOCK(hhcd);
  738. /* Setup Legacy weak Callbacks */
  739. if (hhcd->State == HAL_HCD_STATE_READY)
  740. {
  741. switch (CallbackID)
  742. {
  743. case HAL_HCD_SOF_CB_ID :
  744. hhcd->SOFCallback = HAL_HCD_SOF_Callback;
  745. break;
  746. case HAL_HCD_CONNECT_CB_ID :
  747. hhcd->ConnectCallback = HAL_HCD_Connect_Callback;
  748. break;
  749. case HAL_HCD_DISCONNECT_CB_ID :
  750. hhcd->DisconnectCallback = HAL_HCD_Disconnect_Callback;
  751. break;
  752. case HAL_HCD_PORT_ENABLED_CB_ID :
  753. hhcd->PortEnabledCallback = HAL_HCD_PortEnabled_Callback;
  754. break;
  755. case HAL_HCD_PORT_DISABLED_CB_ID :
  756. hhcd->PortDisabledCallback = HAL_HCD_PortDisabled_Callback;
  757. break;
  758. case HAL_HCD_MSPINIT_CB_ID :
  759. hhcd->MspInitCallback = HAL_HCD_MspInit;
  760. break;
  761. case HAL_HCD_MSPDEINIT_CB_ID :
  762. hhcd->MspDeInitCallback = HAL_HCD_MspDeInit;
  763. break;
  764. default :
  765. /* Update the error code */
  766. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  767. /* Return error status */
  768. status = HAL_ERROR;
  769. break;
  770. }
  771. }
  772. else if (hhcd->State == HAL_HCD_STATE_RESET)
  773. {
  774. switch (CallbackID)
  775. {
  776. case HAL_HCD_MSPINIT_CB_ID :
  777. hhcd->MspInitCallback = HAL_HCD_MspInit;
  778. break;
  779. case HAL_HCD_MSPDEINIT_CB_ID :
  780. hhcd->MspDeInitCallback = HAL_HCD_MspDeInit;
  781. break;
  782. default :
  783. /* Update the error code */
  784. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  785. /* Return error status */
  786. status = HAL_ERROR;
  787. break;
  788. }
  789. }
  790. else
  791. {
  792. /* Update the error code */
  793. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  794. /* Return error status */
  795. status = HAL_ERROR;
  796. }
  797. /* Release Lock */
  798. __HAL_UNLOCK(hhcd);
  799. return status;
  800. }
  801. /**
  802. * @brief Register USB HCD Host Channel Notify URB Change Callback
  803. * To be used instead of the weak HAL_HCD_HC_NotifyURBChange_Callback() predefined callback
  804. * @param hhcd HCD handle
  805. * @param pCallback pointer to the USB HCD Host Channel Notify URB Change Callback function
  806. * @retval HAL status
  807. */
  808. HAL_StatusTypeDef HAL_HCD_RegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd,
  809. pHCD_HC_NotifyURBChangeCallbackTypeDef pCallback)
  810. {
  811. HAL_StatusTypeDef status = HAL_OK;
  812. if (pCallback == NULL)
  813. {
  814. /* Update the error code */
  815. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  816. return HAL_ERROR;
  817. }
  818. /* Process locked */
  819. __HAL_LOCK(hhcd);
  820. if (hhcd->State == HAL_HCD_STATE_READY)
  821. {
  822. hhcd->HC_NotifyURBChangeCallback = pCallback;
  823. }
  824. else
  825. {
  826. /* Update the error code */
  827. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  828. /* Return error status */
  829. status = HAL_ERROR;
  830. }
  831. /* Release Lock */
  832. __HAL_UNLOCK(hhcd);
  833. return status;
  834. }
  835. /**
  836. * @brief Unregister the USB HCD Host Channel Notify URB Change Callback
  837. * USB HCD Host Channel Notify URB Change Callback is redirected
  838. * to the weak HAL_HCD_HC_NotifyURBChange_Callback() predefined callback
  839. * @param hhcd HCD handle
  840. * @retval HAL status
  841. */
  842. HAL_StatusTypeDef HAL_HCD_UnRegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd)
  843. {
  844. HAL_StatusTypeDef status = HAL_OK;
  845. /* Process locked */
  846. __HAL_LOCK(hhcd);
  847. if (hhcd->State == HAL_HCD_STATE_READY)
  848. {
  849. hhcd->HC_NotifyURBChangeCallback = HAL_HCD_HC_NotifyURBChange_Callback; /* Legacy weak DataOutStageCallback */
  850. }
  851. else
  852. {
  853. /* Update the error code */
  854. hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
  855. /* Return error status */
  856. status = HAL_ERROR;
  857. }
  858. /* Release Lock */
  859. __HAL_UNLOCK(hhcd);
  860. return status;
  861. }
  862. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  863. /**
  864. * @}
  865. */
  866. /** @defgroup HCD_Exported_Functions_Group3 Peripheral Control functions
  867. * @brief Management functions
  868. *
  869. @verbatim
  870. ===============================================================================
  871. ##### Peripheral Control functions #####
  872. ===============================================================================
  873. [..]
  874. This subsection provides a set of functions allowing to control the HCD data
  875. transfers.
  876. @endverbatim
  877. * @{
  878. */
  879. /**
  880. * @brief Start the host driver.
  881. * @param hhcd HCD handle
  882. * @retval HAL status
  883. */
  884. HAL_StatusTypeDef HAL_HCD_Start(HCD_HandleTypeDef *hhcd)
  885. {
  886. __HAL_LOCK(hhcd);
  887. /* Enable port power */
  888. (void)USB_DriveVbus(hhcd->Instance, 1U);
  889. /* Enable global interrupt */
  890. __HAL_HCD_ENABLE(hhcd);
  891. __HAL_UNLOCK(hhcd);
  892. return HAL_OK;
  893. }
  894. /**
  895. * @brief Stop the host driver.
  896. * @param hhcd HCD handle
  897. * @retval HAL status
  898. */
  899. HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd)
  900. {
  901. __HAL_LOCK(hhcd);
  902. (void)USB_StopHost(hhcd->Instance);
  903. __HAL_UNLOCK(hhcd);
  904. return HAL_OK;
  905. }
  906. /**
  907. * @brief Reset the host port.
  908. * @param hhcd HCD handle
  909. * @retval HAL status
  910. */
  911. HAL_StatusTypeDef HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd)
  912. {
  913. return (USB_ResetPort(hhcd->Instance));
  914. }
  915. /**
  916. * @}
  917. */
  918. /** @defgroup HCD_Exported_Functions_Group4 Peripheral State functions
  919. * @brief Peripheral State functions
  920. *
  921. @verbatim
  922. ===============================================================================
  923. ##### Peripheral State functions #####
  924. ===============================================================================
  925. [..]
  926. This subsection permits to get in run-time the status of the peripheral
  927. and the data flow.
  928. @endverbatim
  929. * @{
  930. */
  931. /**
  932. * @brief Return the HCD handle state.
  933. * @param hhcd HCD handle
  934. * @retval HAL state
  935. */
  936. HCD_StateTypeDef HAL_HCD_GetState(HCD_HandleTypeDef const *hhcd)
  937. {
  938. return hhcd->State;
  939. }
  940. /**
  941. * @brief Return URB state for a channel.
  942. * @param hhcd HCD handle
  943. * @param chnum Channel number.
  944. * This parameter can be a value from 1 to 15
  945. * @retval URB state.
  946. * This parameter can be one of these values:
  947. * URB_IDLE/
  948. * URB_DONE/
  949. * URB_NOTREADY/
  950. * URB_NYET/
  951. * URB_ERROR/
  952. * URB_STALL
  953. */
  954. HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef const *hhcd, uint8_t chnum)
  955. {
  956. return hhcd->hc[chnum].urb_state;
  957. }
  958. /**
  959. * @brief Return the last host transfer size.
  960. * @param hhcd HCD handle
  961. * @param chnum Channel number.
  962. * This parameter can be a value from 1 to 15
  963. * @retval last transfer size in byte
  964. */
  965. uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef const *hhcd, uint8_t chnum)
  966. {
  967. return hhcd->hc[chnum].xfer_count;
  968. }
  969. /**
  970. * @brief Return the Host Channel state.
  971. * @param hhcd HCD handle
  972. * @param chnum Channel number.
  973. * This parameter can be a value from 1 to 15
  974. * @retval Host channel state
  975. * This parameter can be one of these values:
  976. * HC_IDLE/
  977. * HC_XFRC/
  978. * HC_HALTED/
  979. * HC_NYET/
  980. * HC_NAK/
  981. * HC_STALL/
  982. * HC_XACTERR/
  983. * HC_BBLERR/
  984. * HC_DATATGLERR
  985. */
  986. HCD_HCStateTypeDef HAL_HCD_HC_GetState(HCD_HandleTypeDef const *hhcd, uint8_t chnum)
  987. {
  988. return hhcd->hc[chnum].state;
  989. }
  990. /**
  991. * @brief Return the current Host frame number.
  992. * @param hhcd HCD handle
  993. * @retval Current Host frame number
  994. */
  995. uint32_t HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd)
  996. {
  997. return (USB_GetCurrentFrame(hhcd->Instance));
  998. }
  999. /**
  1000. * @brief Return the Host enumeration speed.
  1001. * @param hhcd HCD handle
  1002. * @retval Enumeration speed
  1003. */
  1004. uint32_t HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd)
  1005. {
  1006. return (USB_GetHostSpeed(hhcd->Instance));
  1007. }
  1008. /**
  1009. * @brief Set host channel Hub information.
  1010. * @param hhcd HCD handle
  1011. * @param ch_num Channel number.
  1012. * This parameter can be a value from 1 to 15
  1013. * @param addr Hub address
  1014. * @param PortNbr Hub port number
  1015. * @retval HAL status
  1016. */
  1017. HAL_StatusTypeDef HAL_HCD_HC_SetHubInfo(HCD_HandleTypeDef *hhcd, uint8_t ch_num,
  1018. uint8_t addr, uint8_t PortNbr)
  1019. {
  1020. hhcd->hc[ch_num].hub_addr = addr;
  1021. hhcd->hc[ch_num].hub_port_nbr = PortNbr;
  1022. return HAL_OK;
  1023. }
  1024. /**
  1025. * @brief Clear host channel hub information.
  1026. * @param hhcd HCD handle
  1027. * @param ch_num Channel number.
  1028. * This parameter can be a value from 1 to 15
  1029. * @retval HAL status
  1030. */
  1031. HAL_StatusTypeDef HAL_HCD_HC_ClearHubInfo(HCD_HandleTypeDef *hhcd, uint8_t ch_num)
  1032. {
  1033. hhcd->hc[ch_num].hub_addr = 0U;
  1034. hhcd->hc[ch_num].hub_port_nbr = 0U;
  1035. return HAL_OK;
  1036. }
  1037. /**
  1038. * @}
  1039. */
  1040. /**
  1041. * @}
  1042. */
  1043. /** @addtogroup HCD_Private_Functions
  1044. * @{
  1045. */
  1046. /**
  1047. * @brief Handle Host Channel IN interrupt requests.
  1048. * @param hhcd HCD handle
  1049. * @param chnum Channel number.
  1050. * This parameter can be a value from 1 to 15
  1051. * @retval none
  1052. */
  1053. static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
  1054. {
  1055. const USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
  1056. uint32_t USBx_BASE = (uint32_t)USBx;
  1057. uint32_t tmpreg;
  1058. if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_AHBERR))
  1059. {
  1060. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
  1061. hhcd->hc[chnum].state = HC_XACTERR;
  1062. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1063. }
  1064. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_BBERR))
  1065. {
  1066. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_BBERR);
  1067. hhcd->hc[chnum].state = HC_BBLERR;
  1068. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1069. }
  1070. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_STALL))
  1071. {
  1072. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
  1073. hhcd->hc[chnum].state = HC_STALL;
  1074. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1075. }
  1076. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_DTERR))
  1077. {
  1078. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
  1079. hhcd->hc[chnum].state = HC_DATATGLERR;
  1080. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1081. }
  1082. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_TXERR))
  1083. {
  1084. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
  1085. hhcd->hc[chnum].state = HC_XACTERR;
  1086. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1087. }
  1088. else
  1089. {
  1090. /* ... */
  1091. }
  1092. if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_FRMOR))
  1093. {
  1094. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1095. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
  1096. }
  1097. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_XFRC))
  1098. {
  1099. hhcd->hc[chnum].state = HC_XFRC;
  1100. hhcd->hc[chnum].ErrCnt = 0U;
  1101. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
  1102. if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
  1103. (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
  1104. {
  1105. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1106. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
  1107. }
  1108. else if ((hhcd->hc[chnum].ep_type == EP_TYPE_INTR) ||
  1109. (hhcd->hc[chnum].ep_type == EP_TYPE_ISOC))
  1110. {
  1111. USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM;
  1112. hhcd->hc[chnum].urb_state = URB_DONE;
  1113. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  1114. hhcd->HC_NotifyURBChangeCallback(hhcd, chnum, hhcd->hc[chnum].urb_state);
  1115. #else
  1116. HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
  1117. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  1118. }
  1119. else
  1120. {
  1121. /* ... */
  1122. }
  1123. if (hhcd->Init.dma_enable == 1U)
  1124. {
  1125. if ((((hhcd->hc[chnum].xfer_count + hhcd->hc[chnum].max_packet - 1U) / hhcd->hc[chnum].max_packet) & 1U) != 0U)
  1126. {
  1127. hhcd->hc[chnum].toggle_in ^= 1U;
  1128. }
  1129. }
  1130. else
  1131. {
  1132. hhcd->hc[chnum].toggle_in ^= 1U;
  1133. }
  1134. }
  1135. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_ACK))
  1136. {
  1137. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
  1138. }
  1139. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_CHH))
  1140. {
  1141. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
  1142. if (hhcd->hc[chnum].state == HC_XFRC)
  1143. {
  1144. hhcd->hc[chnum].state = HC_HALTED;
  1145. hhcd->hc[chnum].urb_state = URB_DONE;
  1146. }
  1147. else if (hhcd->hc[chnum].state == HC_STALL)
  1148. {
  1149. hhcd->hc[chnum].state = HC_HALTED;
  1150. hhcd->hc[chnum].urb_state = URB_STALL;
  1151. }
  1152. else if ((hhcd->hc[chnum].state == HC_XACTERR) ||
  1153. (hhcd->hc[chnum].state == HC_DATATGLERR))
  1154. {
  1155. hhcd->hc[chnum].state = HC_HALTED;
  1156. hhcd->hc[chnum].ErrCnt++;
  1157. if (hhcd->hc[chnum].ErrCnt > 2U)
  1158. {
  1159. hhcd->hc[chnum].ErrCnt = 0U;
  1160. hhcd->hc[chnum].urb_state = URB_ERROR;
  1161. }
  1162. else
  1163. {
  1164. hhcd->hc[chnum].urb_state = URB_NOTREADY;
  1165. if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
  1166. (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
  1167. {
  1168. /* re-activate the channel */
  1169. tmpreg = USBx_HC(chnum)->HCCHAR;
  1170. tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
  1171. tmpreg |= USB_OTG_HCCHAR_CHENA;
  1172. USBx_HC(chnum)->HCCHAR = tmpreg;
  1173. }
  1174. }
  1175. }
  1176. else if (hhcd->hc[chnum].state == HC_NYET)
  1177. {
  1178. hhcd->hc[chnum].state = HC_HALTED;
  1179. }
  1180. else if (hhcd->hc[chnum].state == HC_ACK)
  1181. {
  1182. hhcd->hc[chnum].state = HC_HALTED;
  1183. }
  1184. else if (hhcd->hc[chnum].state == HC_NAK)
  1185. {
  1186. hhcd->hc[chnum].state = HC_HALTED;
  1187. hhcd->hc[chnum].urb_state = URB_NOTREADY;
  1188. if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
  1189. (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
  1190. {
  1191. /* re-activate the channel */
  1192. tmpreg = USBx_HC(chnum)->HCCHAR;
  1193. tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
  1194. tmpreg |= USB_OTG_HCCHAR_CHENA;
  1195. USBx_HC(chnum)->HCCHAR = tmpreg;
  1196. }
  1197. }
  1198. else if (hhcd->hc[chnum].state == HC_BBLERR)
  1199. {
  1200. hhcd->hc[chnum].state = HC_HALTED;
  1201. hhcd->hc[chnum].ErrCnt++;
  1202. hhcd->hc[chnum].urb_state = URB_ERROR;
  1203. }
  1204. else
  1205. {
  1206. if (hhcd->hc[chnum].state == HC_HALTED)
  1207. {
  1208. return;
  1209. }
  1210. }
  1211. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  1212. hhcd->HC_NotifyURBChangeCallback(hhcd, chnum, hhcd->hc[chnum].urb_state);
  1213. #else
  1214. HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
  1215. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  1216. }
  1217. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NYET))
  1218. {
  1219. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET);
  1220. hhcd->hc[chnum].state = HC_NYET;
  1221. hhcd->hc[chnum].ErrCnt = 0U;
  1222. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1223. }
  1224. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NAK))
  1225. {
  1226. if (hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
  1227. {
  1228. hhcd->hc[chnum].ErrCnt = 0U;
  1229. hhcd->hc[chnum].state = HC_NAK;
  1230. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1231. }
  1232. else if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
  1233. (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
  1234. {
  1235. hhcd->hc[chnum].ErrCnt = 0U;
  1236. hhcd->hc[chnum].state = HC_NAK;
  1237. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1238. }
  1239. else
  1240. {
  1241. /* ... */
  1242. }
  1243. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
  1244. }
  1245. else
  1246. {
  1247. /* ... */
  1248. }
  1249. }
  1250. /**
  1251. * @brief Handle Host Channel OUT interrupt requests.
  1252. * @param hhcd HCD handle
  1253. * @param chnum Channel number.
  1254. * This parameter can be a value from 1 to 15
  1255. * @retval none
  1256. */
  1257. static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
  1258. {
  1259. const USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
  1260. uint32_t USBx_BASE = (uint32_t)USBx;
  1261. uint32_t tmpreg;
  1262. uint32_t num_packets;
  1263. if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_AHBERR))
  1264. {
  1265. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
  1266. hhcd->hc[chnum].state = HC_XACTERR;
  1267. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1268. }
  1269. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_ACK))
  1270. {
  1271. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
  1272. }
  1273. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_FRMOR))
  1274. {
  1275. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
  1276. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1277. }
  1278. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_XFRC))
  1279. {
  1280. hhcd->hc[chnum].ErrCnt = 0U;
  1281. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
  1282. hhcd->hc[chnum].state = HC_XFRC;
  1283. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1284. }
  1285. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_STALL))
  1286. {
  1287. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
  1288. hhcd->hc[chnum].state = HC_STALL;
  1289. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1290. }
  1291. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NAK))
  1292. {
  1293. hhcd->hc[chnum].ErrCnt = 0U;
  1294. hhcd->hc[chnum].state = HC_NAK;
  1295. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1296. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
  1297. }
  1298. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_TXERR))
  1299. {
  1300. hhcd->hc[chnum].state = HC_XACTERR;
  1301. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1302. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
  1303. }
  1304. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_DTERR))
  1305. {
  1306. hhcd->hc[chnum].state = HC_DATATGLERR;
  1307. (void)USB_HC_Halt(hhcd->Instance, chnum);
  1308. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
  1309. }
  1310. else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_CHH))
  1311. {
  1312. __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
  1313. if (hhcd->hc[chnum].state == HC_XFRC)
  1314. {
  1315. hhcd->hc[chnum].state = HC_HALTED;
  1316. hhcd->hc[chnum].urb_state = URB_DONE;
  1317. if ((hhcd->hc[chnum].ep_type == EP_TYPE_BULK) ||
  1318. (hhcd->hc[chnum].ep_type == EP_TYPE_INTR))
  1319. {
  1320. if (hhcd->Init.dma_enable == 0U)
  1321. {
  1322. hhcd->hc[chnum].toggle_out ^= 1U;
  1323. }
  1324. if ((hhcd->Init.dma_enable == 1U) && (hhcd->hc[chnum].xfer_len > 0U))
  1325. {
  1326. num_packets = (hhcd->hc[chnum].xfer_len + hhcd->hc[chnum].max_packet - 1U) / hhcd->hc[chnum].max_packet;
  1327. if ((num_packets & 1U) != 0U)
  1328. {
  1329. hhcd->hc[chnum].toggle_out ^= 1U;
  1330. }
  1331. }
  1332. }
  1333. }
  1334. else if (hhcd->hc[chnum].state == HC_ACK)
  1335. {
  1336. hhcd->hc[chnum].state = HC_HALTED;
  1337. }
  1338. else if (hhcd->hc[chnum].state == HC_NAK)
  1339. {
  1340. hhcd->hc[chnum].state = HC_HALTED;
  1341. hhcd->hc[chnum].urb_state = URB_NOTREADY;
  1342. }
  1343. else if (hhcd->hc[chnum].state == HC_STALL)
  1344. {
  1345. hhcd->hc[chnum].state = HC_HALTED;
  1346. hhcd->hc[chnum].urb_state = URB_STALL;
  1347. }
  1348. else if ((hhcd->hc[chnum].state == HC_XACTERR) ||
  1349. (hhcd->hc[chnum].state == HC_DATATGLERR))
  1350. {
  1351. hhcd->hc[chnum].state = HC_HALTED;
  1352. hhcd->hc[chnum].ErrCnt++;
  1353. if (hhcd->hc[chnum].ErrCnt > 2U)
  1354. {
  1355. hhcd->hc[chnum].ErrCnt = 0U;
  1356. hhcd->hc[chnum].urb_state = URB_ERROR;
  1357. }
  1358. else
  1359. {
  1360. hhcd->hc[chnum].urb_state = URB_NOTREADY;
  1361. /* re-activate the channel */
  1362. tmpreg = USBx_HC(chnum)->HCCHAR;
  1363. tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
  1364. tmpreg |= USB_OTG_HCCHAR_CHENA;
  1365. USBx_HC(chnum)->HCCHAR = tmpreg;
  1366. }
  1367. }
  1368. else
  1369. {
  1370. return;
  1371. }
  1372. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  1373. hhcd->HC_NotifyURBChangeCallback(hhcd, chnum, hhcd->hc[chnum].urb_state);
  1374. #else
  1375. HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
  1376. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  1377. }
  1378. else
  1379. {
  1380. return;
  1381. }
  1382. }
  1383. /**
  1384. * @brief Handle Rx Queue Level interrupt requests.
  1385. * @param hhcd HCD handle
  1386. * @retval none
  1387. */
  1388. static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd)
  1389. {
  1390. const USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
  1391. uint32_t USBx_BASE = (uint32_t)USBx;
  1392. uint32_t pktsts;
  1393. uint32_t pktcnt;
  1394. uint32_t GrxstspReg;
  1395. uint32_t xferSizePktCnt;
  1396. uint32_t tmpreg;
  1397. uint32_t chnum;
  1398. GrxstspReg = hhcd->Instance->GRXSTSP;
  1399. chnum = GrxstspReg & USB_OTG_GRXSTSP_EPNUM;
  1400. pktsts = (GrxstspReg & USB_OTG_GRXSTSP_PKTSTS) >> 17;
  1401. pktcnt = (GrxstspReg & USB_OTG_GRXSTSP_BCNT) >> 4;
  1402. switch (pktsts)
  1403. {
  1404. case GRXSTS_PKTSTS_IN:
  1405. /* Read the data into the host buffer. */
  1406. if ((pktcnt > 0U) && (hhcd->hc[chnum].xfer_buff != (void *)0))
  1407. {
  1408. if ((hhcd->hc[chnum].xfer_count + pktcnt) <= hhcd->hc[chnum].xfer_len)
  1409. {
  1410. (void)USB_ReadPacket(hhcd->Instance,
  1411. hhcd->hc[chnum].xfer_buff, (uint16_t)pktcnt);
  1412. /* manage multiple Xfer */
  1413. hhcd->hc[chnum].xfer_buff += pktcnt;
  1414. hhcd->hc[chnum].xfer_count += pktcnt;
  1415. /* get transfer size packet count */
  1416. xferSizePktCnt = (USBx_HC(chnum)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) >> 19;
  1417. if ((hhcd->hc[chnum].max_packet == pktcnt) && (xferSizePktCnt > 0U))
  1418. {
  1419. /* re-activate the channel when more packets are expected */
  1420. tmpreg = USBx_HC(chnum)->HCCHAR;
  1421. tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
  1422. tmpreg |= USB_OTG_HCCHAR_CHENA;
  1423. USBx_HC(chnum)->HCCHAR = tmpreg;
  1424. hhcd->hc[chnum].toggle_in ^= 1U;
  1425. }
  1426. }
  1427. else
  1428. {
  1429. hhcd->hc[chnum].urb_state = URB_ERROR;
  1430. }
  1431. }
  1432. break;
  1433. case GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  1434. break;
  1435. case GRXSTS_PKTSTS_IN_XFER_COMP:
  1436. case GRXSTS_PKTSTS_CH_HALTED:
  1437. default:
  1438. break;
  1439. }
  1440. }
  1441. /**
  1442. * @brief Handle Host Port interrupt requests.
  1443. * @param hhcd HCD handle
  1444. * @retval None
  1445. */
  1446. static void HCD_Port_IRQHandler(HCD_HandleTypeDef *hhcd)
  1447. {
  1448. const USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
  1449. uint32_t USBx_BASE = (uint32_t)USBx;
  1450. __IO uint32_t hprt0;
  1451. __IO uint32_t hprt0_dup;
  1452. /* Handle Host Port Interrupts */
  1453. hprt0 = USBx_HPRT0;
  1454. hprt0_dup = USBx_HPRT0;
  1455. hprt0_dup &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET | \
  1456. USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG);
  1457. /* Check whether Port Connect detected */
  1458. if ((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET)
  1459. {
  1460. if ((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS)
  1461. {
  1462. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  1463. hhcd->ConnectCallback(hhcd);
  1464. #else
  1465. HAL_HCD_Connect_Callback(hhcd);
  1466. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  1467. }
  1468. hprt0_dup |= USB_OTG_HPRT_PCDET;
  1469. }
  1470. /* Check whether Port Enable Changed */
  1471. if ((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG)
  1472. {
  1473. hprt0_dup |= USB_OTG_HPRT_PENCHNG;
  1474. if ((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA)
  1475. {
  1476. if (hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY)
  1477. {
  1478. if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17))
  1479. {
  1480. (void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_6_MHZ);
  1481. }
  1482. else
  1483. {
  1484. (void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_48_MHZ);
  1485. }
  1486. }
  1487. else
  1488. {
  1489. if (hhcd->Init.speed == HCD_SPEED_FULL)
  1490. {
  1491. USBx_HOST->HFIR = HFIR_60_MHZ;
  1492. }
  1493. }
  1494. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  1495. hhcd->PortEnabledCallback(hhcd);
  1496. #else
  1497. HAL_HCD_PortEnabled_Callback(hhcd);
  1498. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  1499. }
  1500. else
  1501. {
  1502. #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
  1503. hhcd->PortDisabledCallback(hhcd);
  1504. #else
  1505. HAL_HCD_PortDisabled_Callback(hhcd);
  1506. #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
  1507. }
  1508. }
  1509. /* Check for an overcurrent */
  1510. if ((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG)
  1511. {
  1512. hprt0_dup |= USB_OTG_HPRT_POCCHNG;
  1513. }
  1514. /* Clear Port Interrupts */
  1515. USBx_HPRT0 = hprt0_dup;
  1516. }
  1517. /**
  1518. * @}
  1519. */
  1520. /**
  1521. * @}
  1522. */
  1523. #endif /* defined (USB_OTG_FS) */
  1524. #endif /* HAL_HCD_MODULE_ENABLED */
  1525. /**
  1526. * @}
  1527. */
  1528. /**
  1529. * @}
  1530. */