stm32f1xx_hal_hcd.c 47 KB

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