stm32f1xx_hal_hcd.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  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. */