stm32l4xx_hal_hcd.c 46 KB

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