stm32l4xx_hal_pcd.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_pcd.c
  4. * @author MCD Application Team
  5. * @brief PCD 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. @verbatim
  14. ==============================================================================
  15. ##### How to use this driver #####
  16. ==============================================================================
  17. [..]
  18. The PCD HAL driver can be used as follows:
  19. (#) Declare a PCD_HandleTypeDef handle structure, for example:
  20. PCD_HandleTypeDef hpcd;
  21. (#) Fill parameters of Init structure in HCD handle
  22. (#) Call HAL_PCD_Init() API to initialize the PCD peripheral (Core, Device core, ...)
  23. (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API:
  24. (##) Enable the PCD/USB Low Level interface clock using
  25. (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  26. (##) Initialize the related GPIO clocks
  27. (##) Configure PCD pin-out
  28. (##) Configure PCD NVIC interrupt
  29. (#)Associate the Upper USB device stack to the HAL PCD Driver:
  30. (##) hpcd.pData = pdev;
  31. (#)Enable PCD transmission and reception:
  32. (##) HAL_PCD_Start();
  33. @endverbatim
  34. ******************************************************************************
  35. * @attention
  36. *
  37. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  38. *
  39. * Redistribution and use in source and binary forms, with or without modification,
  40. * are permitted provided that the following conditions are met:
  41. * 1. Redistributions of source code must retain the above copyright notice,
  42. * this list of conditions and the following disclaimer.
  43. * 2. Redistributions in binary form must reproduce the above copyright notice,
  44. * this list of conditions and the following disclaimer in the documentation
  45. * and/or other materials provided with the distribution.
  46. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  47. * may be used to endorse or promote products derived from this software
  48. * without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  51. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  53. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  54. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  55. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  56. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  57. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  58. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  59. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60. *
  61. ******************************************************************************
  62. */
  63. /* Includes ------------------------------------------------------------------*/
  64. #include "stm32l4xx_hal.h"
  65. /** @addtogroup STM32L4xx_HAL_Driver
  66. * @{
  67. */
  68. /** @defgroup PCD PCD
  69. * @brief PCD HAL module driver
  70. * @{
  71. */
  72. #ifdef HAL_PCD_MODULE_ENABLED
  73. #if defined(STM32L432xx) || defined(STM32L433xx) || defined(STM32L442xx) || defined(STM32L443xx) || \
  74. defined(STM32L452xx) || defined(STM32L462xx) || \
  75. defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || \
  76. defined(STM32L496xx) || defined(STM32L4A6xx) || \
  77. defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  78. /* Private types -------------------------------------------------------------*/
  79. /* Private variables ---------------------------------------------------------*/
  80. /* Private constants ---------------------------------------------------------*/
  81. /**
  82. * USB_OTG_CORE VERSION ID
  83. */
  84. #define USB_OTG_CORE_ID_310A 0x4F54310A
  85. #define USB_OTG_CORE_ID_320A 0x4F54320A
  86. /* Private macros ------------------------------------------------------------*/
  87. /** @defgroup PCD_Private_Macros PCD Private Macros
  88. * @{
  89. */
  90. #define PCD_MIN(a, b) (((a) < (b)) ? (a) : (b))
  91. #define PCD_MAX(a, b) (((a) > (b)) ? (a) : (b))
  92. /**
  93. * @}
  94. */
  95. /* Private functions prototypes ----------------------------------------------*/
  96. /** @defgroup PCD_Private_Functions PCD Private Functions
  97. * @{
  98. */
  99. #if defined (USB_OTG_FS)
  100. static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum);
  101. #endif /* USB_OTG_FS */
  102. #if defined (USB)
  103. static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd);
  104. #endif /* USB */
  105. /**
  106. * @}
  107. */
  108. /* Exported functions --------------------------------------------------------*/
  109. /** @defgroup PCD_Exported_Functions PCD Exported Functions
  110. * @{
  111. */
  112. /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
  113. * @brief Initialization and Configuration functions
  114. *
  115. @verbatim
  116. ===============================================================================
  117. ##### Initialization and de-initialization functions #####
  118. ===============================================================================
  119. [..] This section provides functions allowing to:
  120. @endverbatim
  121. * @{
  122. */
  123. /**
  124. * @brief Initializes the PCD according to the specified
  125. * parameters in the PCD_InitTypeDef and initialize the associated handle.
  126. * @param hpcd: PCD handle
  127. * @retval HAL status
  128. */
  129. HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
  130. {
  131. uint32_t index = 0U;
  132. /* Check the PCD handle allocation */
  133. if(hpcd == NULL)
  134. {
  135. return HAL_ERROR;
  136. }
  137. /* Check the parameters */
  138. assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance));
  139. if(hpcd->State == HAL_PCD_STATE_RESET)
  140. {
  141. /* Allocate lock resource and initialize it */
  142. hpcd->Lock = HAL_UNLOCKED;
  143. // Added for MBED PR #3062
  144. for (index = 0; index < hpcd->Init.dev_endpoints ; index++)
  145. hpcd->EPLock[index].Lock = HAL_UNLOCKED;
  146. /* Init the low level hardware : GPIO, CLOCK, NVIC... */
  147. HAL_PCD_MspInit(hpcd);
  148. }
  149. hpcd->State = HAL_PCD_STATE_BUSY;
  150. /* Disable the Interrupts */
  151. __HAL_PCD_DISABLE(hpcd);
  152. /*Init the Core (common init.) */
  153. USB_CoreInit(hpcd->Instance, hpcd->Init);
  154. /* Force Device Mode*/
  155. USB_SetCurrentMode(hpcd->Instance , USB_DEVICE_MODE);
  156. /* Init endpoints structures */
  157. for (index = 0; index < hpcd->Init.dev_endpoints ; index++)
  158. {
  159. /* Init ep structure */
  160. hpcd->IN_ep[index].is_in = 1;
  161. hpcd->IN_ep[index].num = index;
  162. hpcd->IN_ep[index].tx_fifo_num = index;
  163. /* Control until ep is activated */
  164. hpcd->IN_ep[index].type = EP_TYPE_CTRL;
  165. hpcd->IN_ep[index].maxpacket = 0;
  166. hpcd->IN_ep[index].xfer_buff = 0;
  167. hpcd->IN_ep[index].xfer_len = 0;
  168. }
  169. for (index = 0; index < 15 ; index++)
  170. {
  171. hpcd->OUT_ep[index].is_in = 0;
  172. hpcd->OUT_ep[index].num = index;
  173. hpcd->IN_ep[index].tx_fifo_num = index;
  174. /* Control until ep is activated */
  175. hpcd->OUT_ep[index].type = EP_TYPE_CTRL;
  176. hpcd->OUT_ep[index].maxpacket = 0;
  177. hpcd->OUT_ep[index].xfer_buff = 0;
  178. hpcd->OUT_ep[index].xfer_len = 0;
  179. }
  180. /* Init Device */
  181. USB_DevInit(hpcd->Instance, hpcd->Init);
  182. hpcd->USB_Address = 0;
  183. hpcd->State= HAL_PCD_STATE_READY;
  184. /* Activate LPM */
  185. if (hpcd->Init.lpm_enable ==1)
  186. {
  187. HAL_PCDEx_ActivateLPM(hpcd);
  188. }
  189. /* Activate Battery charging */
  190. if (hpcd->Init.battery_charging_enable ==1)
  191. {
  192. HAL_PCDEx_ActivateBCD(hpcd);
  193. }
  194. USB_DevDisconnect (hpcd->Instance);
  195. return HAL_OK;
  196. }
  197. /**
  198. * @brief DeInitializes the PCD peripheral.
  199. * @param hpcd: PCD handle
  200. * @retval HAL status
  201. */
  202. HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd)
  203. {
  204. /* Check the PCD handle allocation */
  205. if(hpcd == NULL)
  206. {
  207. return HAL_ERROR;
  208. }
  209. hpcd->State = HAL_PCD_STATE_BUSY;
  210. /* Stop Device */
  211. HAL_PCD_Stop(hpcd);
  212. /* DeInit the low level hardware */
  213. HAL_PCD_MspDeInit(hpcd);
  214. hpcd->State = HAL_PCD_STATE_RESET;
  215. return HAL_OK;
  216. }
  217. /**
  218. * @brief Initializes the PCD MSP.
  219. * @param hpcd: PCD handle
  220. * @retval None
  221. */
  222. __weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
  223. {
  224. /* Prevent unused argument(s) compilation warning */
  225. UNUSED(hpcd);
  226. /* NOTE : This function should not be modified, when the callback is needed,
  227. the HAL_PCD_MspInit could be implemented in the user file
  228. */
  229. }
  230. /**
  231. * @brief DeInitializes PCD MSP.
  232. * @param hpcd: PCD handle
  233. * @retval None
  234. */
  235. __weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
  236. {
  237. /* Prevent unused argument(s) compilation warning */
  238. UNUSED(hpcd);
  239. /* NOTE : This function should not be modified, when the callback is needed,
  240. the HAL_PCD_MspDeInit could be implemented in the user file
  241. */
  242. }
  243. /**
  244. * @}
  245. */
  246. /** @defgroup PCD_Exported_Functions_Group2 Input and Output operation functions
  247. * @brief Data transfers functions
  248. *
  249. @verbatim
  250. ===============================================================================
  251. ##### IO operation functions #####
  252. ===============================================================================
  253. [..]
  254. This subsection provides a set of functions allowing to manage the PCD data
  255. transfers.
  256. @endverbatim
  257. * @{
  258. */
  259. /**
  260. * @brief Start The USB OTG Device.
  261. * @param hpcd: PCD handle
  262. * @retval HAL status
  263. */
  264. HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)
  265. {
  266. __HAL_LOCK(hpcd);
  267. USB_DevConnect (hpcd->Instance);
  268. __HAL_PCD_ENABLE(hpcd);
  269. __HAL_UNLOCK(hpcd);
  270. return HAL_OK;
  271. }
  272. /**
  273. * @brief Stop The USB OTG Device.
  274. * @param hpcd: PCD handle
  275. * @retval HAL status
  276. */
  277. HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd)
  278. {
  279. __HAL_LOCK(hpcd);
  280. __HAL_PCD_DISABLE(hpcd);
  281. USB_StopDevice(hpcd->Instance);
  282. USB_DevDisconnect (hpcd->Instance);
  283. __HAL_UNLOCK(hpcd);
  284. return HAL_OK;
  285. }
  286. #if defined (USB_OTG_FS)
  287. /**
  288. * @brief Handles PCD interrupt request.
  289. * @param hpcd: PCD handle
  290. * @retval HAL status
  291. */
  292. void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
  293. {
  294. USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
  295. uint32_t index = 0U, ep_intr = 0U, epint = 0U, epnum = 0U;
  296. uint32_t fifoemptymsk = 0U, temp = 0U;
  297. USB_OTG_EPTypeDef *ep = NULL;
  298. uint32_t hclk = 80000000;
  299. /* ensure that we are in device mode */
  300. if (USB_GetMode(hpcd->Instance) == USB_OTG_MODE_DEVICE)
  301. {
  302. /* avoid spurious interrupt */
  303. if(__HAL_PCD_IS_INVALID_INTERRUPT(hpcd))
  304. {
  305. return;
  306. }
  307. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_MMIS))
  308. {
  309. /* incorrect mode, acknowledge the interrupt */
  310. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_MMIS);
  311. }
  312. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OEPINT))
  313. {
  314. epnum = 0;
  315. /* Read in the device interrupt bits */
  316. ep_intr = USB_ReadDevAllOutEpInterrupt(hpcd->Instance);
  317. while (ep_intr)
  318. {
  319. if (ep_intr & 0x1)
  320. {
  321. epint = USB_ReadDevOutEPInterrupt(hpcd->Instance, epnum);
  322. if (( epint & USB_OTG_DOEPINT_XFRC) == USB_OTG_DOEPINT_XFRC)
  323. {
  324. CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_XFRC);
  325. /* setup/out transaction management for Core ID 310A */
  326. if (USBx->GSNPSID == USB_OTG_CORE_ID_310A)
  327. {
  328. if (!(USBx_OUTEP(0)->DOEPINT & (0x1 << 15)))
  329. {
  330. if (hpcd->Init.dma_enable == 1)
  331. {
  332. hpcd->OUT_ep[epnum].xfer_count =
  333. hpcd->OUT_ep[epnum].maxpacket -
  334. (USBx_OUTEP(epnum)->DOEPTSIZ & USB_OTG_DOEPTSIZ_XFRSIZ);
  335. hpcd->OUT_ep[epnum].xfer_buff +=
  336. hpcd->OUT_ep[epnum].maxpacket;
  337. }
  338. HAL_PCD_DataOutStageCallback(hpcd, epnum);
  339. if (hpcd->Init.dma_enable == 1)
  340. {
  341. if (!epnum && !hpcd->OUT_ep[epnum].xfer_len)
  342. {
  343. /* this is ZLP, so prepare EP0 for next setup */
  344. USB_EP0_OutStart(hpcd->Instance, 1, (uint8_t *)hpcd->Setup);
  345. }
  346. }
  347. }
  348. /* Clear the SetPktRcvd flag*/
  349. USBx_OUTEP(0)->DOEPINT |= (0x1 << 15) | (0x1 << 5);
  350. }
  351. else
  352. {
  353. if (hpcd->Init.dma_enable == 1)
  354. {
  355. hpcd->OUT_ep[epnum].xfer_count =
  356. hpcd->OUT_ep[epnum].maxpacket -
  357. (USBx_OUTEP(epnum)->DOEPTSIZ & USB_OTG_DOEPTSIZ_XFRSIZ);
  358. hpcd->OUT_ep[epnum].xfer_buff += hpcd->OUT_ep[epnum].maxpacket;
  359. }
  360. HAL_PCD_DataOutStageCallback(hpcd, epnum);
  361. if (hpcd->Init.dma_enable == 1)
  362. {
  363. if (!epnum && !hpcd->OUT_ep[epnum].xfer_len)
  364. {
  365. /* this is ZLP, so prepare EP0 for next setup */
  366. USB_EP0_OutStart(hpcd->Instance, 1, (uint8_t *)hpcd->Setup);
  367. }
  368. }
  369. }
  370. }
  371. if(( epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP)
  372. {
  373. /* Inform the upper layer that a setup packet is available */
  374. HAL_PCD_SetupStageCallback(hpcd);
  375. CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STUP);
  376. }
  377. if(( epint & USB_OTG_DOEPINT_OTEPDIS) == USB_OTG_DOEPINT_OTEPDIS)
  378. {
  379. CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPDIS);
  380. }
  381. #ifdef USB_OTG_DOEPINT_OTEPSPR
  382. /* Clear Status Phase Received interrupt */
  383. if(( epint & USB_OTG_DOEPINT_OTEPSPR) == USB_OTG_DOEPINT_OTEPSPR)
  384. {
  385. CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPSPR);
  386. }
  387. #endif /* USB_OTG_DOEPINT_OTEPSPR */
  388. }
  389. epnum++;
  390. ep_intr >>= 1;
  391. }
  392. }
  393. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IEPINT))
  394. {
  395. /* Read in the device interrupt bits */
  396. ep_intr = USB_ReadDevAllInEpInterrupt(hpcd->Instance);
  397. epnum = 0;
  398. while ( ep_intr )
  399. {
  400. if (ep_intr & 0x1) /* In ITR */
  401. {
  402. epint = USB_ReadDevInEPInterrupt(hpcd->Instance, epnum);
  403. if(( epint & USB_OTG_DIEPINT_XFRC) == USB_OTG_DIEPINT_XFRC)
  404. {
  405. fifoemptymsk = 0x1 << epnum;
  406. // Added for MBED PR #3062
  407. atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK, fifoemptymsk);
  408. CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_XFRC);
  409. if (hpcd->Init.dma_enable == 1)
  410. {
  411. hpcd->IN_ep[epnum].xfer_buff += hpcd->IN_ep[epnum].maxpacket;
  412. }
  413. HAL_PCD_DataInStageCallback(hpcd, epnum);
  414. if (hpcd->Init.dma_enable == 1)
  415. {
  416. /* this is ZLP, so prepare EP0 for next setup */
  417. if((epnum == 0) && (hpcd->IN_ep[epnum].xfer_len == 0))
  418. {
  419. /* prepare to rx more setup packets */
  420. USB_EP0_OutStart(hpcd->Instance, 1, (uint8_t *)hpcd->Setup);
  421. }
  422. }
  423. }
  424. if(( epint & USB_OTG_DIEPINT_TOC) == USB_OTG_DIEPINT_TOC)
  425. {
  426. CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_TOC);
  427. }
  428. if(( epint & USB_OTG_DIEPINT_ITTXFE) == USB_OTG_DIEPINT_ITTXFE)
  429. {
  430. CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_ITTXFE);
  431. }
  432. if(( epint & USB_OTG_DIEPINT_INEPNE) == USB_OTG_DIEPINT_INEPNE)
  433. {
  434. CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_INEPNE);
  435. }
  436. if(( epint & USB_OTG_DIEPINT_EPDISD) == USB_OTG_DIEPINT_EPDISD)
  437. {
  438. CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_EPDISD);
  439. }
  440. if(( epint & USB_OTG_DIEPINT_TXFE) == USB_OTG_DIEPINT_TXFE)
  441. {
  442. PCD_WriteEmptyTxFifo(hpcd , epnum);
  443. }
  444. }
  445. epnum++;
  446. ep_intr >>= 1;
  447. }
  448. }
  449. /* Handle Resume Interrupt */
  450. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT))
  451. {
  452. /* Clear the Remote Wake-up Signaling */
  453. USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG;
  454. if(hpcd->LPM_State == LPM_L1)
  455. {
  456. hpcd->LPM_State = LPM_L0;
  457. HAL_PCDEx_LPM_Callback(hpcd, PCD_LPM_L0_ACTIVE);
  458. }
  459. else
  460. {
  461. HAL_PCD_ResumeCallback(hpcd);
  462. }
  463. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT);
  464. }
  465. /* Handle Suspend Interrupt */
  466. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP))
  467. {
  468. if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS)
  469. {
  470. HAL_PCD_SuspendCallback(hpcd);
  471. }
  472. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP);
  473. }
  474. /* Handle LPM Interrupt */
  475. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_LPMINT))
  476. {
  477. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_LPMINT);
  478. if( hpcd->LPM_State == LPM_L0)
  479. {
  480. hpcd->LPM_State = LPM_L1;
  481. hpcd->BESL = (hpcd->Instance->GLPMCFG & USB_OTG_GLPMCFG_BESL) >>2 ;
  482. HAL_PCDEx_LPM_Callback(hpcd, PCD_LPM_L1_ACTIVE);
  483. }
  484. else
  485. {
  486. HAL_PCD_SuspendCallback(hpcd);
  487. }
  488. }
  489. /* Handle Reset Interrupt */
  490. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBRST))
  491. {
  492. USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG;
  493. USB_FlushTxFifo(hpcd->Instance , 0x10);
  494. for (index = 0; index < hpcd->Init.dev_endpoints ; index++)
  495. {
  496. USBx_INEP(index)->DIEPINT = 0xFF;
  497. USBx_OUTEP(index)->DOEPINT = 0xFF;
  498. }
  499. USBx_DEVICE->DAINT = 0xFFFFFFFF;
  500. USBx_DEVICE->DAINTMSK |= 0x10001;
  501. if(hpcd->Init.use_dedicated_ep1)
  502. {
  503. USBx_DEVICE->DOUTEP1MSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM);
  504. USBx_DEVICE->DINEP1MSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM);
  505. }
  506. else
  507. {
  508. #ifdef USB_OTG_DOEPINT_OTEPSPR
  509. USBx_DEVICE->DOEPMSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM | USB_OTG_DOEPMSK_OTEPSPRM);
  510. #else
  511. USBx_DEVICE->DOEPMSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM);
  512. #endif /* USB_OTG_DOEPINT_OTEPSPR */
  513. USBx_DEVICE->DIEPMSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM);
  514. }
  515. /* Set Default Address to 0 */
  516. USBx_DEVICE->DCFG &= ~USB_OTG_DCFG_DAD;
  517. /* setup EP0 to receive SETUP packets */
  518. USB_EP0_OutStart(hpcd->Instance, hpcd->Init.dma_enable, (uint8_t *)hpcd->Setup);
  519. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBRST);
  520. }
  521. /* Handle Enumeration done Interrupt */
  522. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE))
  523. {
  524. USB_ActivateSetup(hpcd->Instance);
  525. hpcd->Instance->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
  526. hpcd->Init.speed = USB_OTG_SPEED_FULL;
  527. hpcd->Init.ep0_mps = USB_OTG_FS_MAX_PACKET_SIZE ;
  528. /* The USBTRD is configured according to the tables below, depending on AHB frequency
  529. used by application. In the low AHB frequency range it is used to stretch enough the USB response
  530. time to IN tokens, the USB turnaround time, so to compensate for the longer AHB read access
  531. latency to the Data FIFO */
  532. /* Get hclk frequency value */
  533. hclk = HAL_RCC_GetHCLKFreq();
  534. if((hclk >= 14200000)&&(hclk < 15000000))
  535. {
  536. /* hclk Clock Range between 14.2-15 MHz */
  537. hpcd->Instance->GUSBCFG |= (uint32_t)((0xF << 10) & USB_OTG_GUSBCFG_TRDT);
  538. }
  539. else if((hclk >= 15000000)&&(hclk < 16000000))
  540. {
  541. /* hclk Clock Range between 15-16 MHz */
  542. hpcd->Instance->GUSBCFG |= (uint32_t)((0xE << 10) & USB_OTG_GUSBCFG_TRDT);
  543. }
  544. else if((hclk >= 16000000)&&(hclk < 17200000))
  545. {
  546. /* hclk Clock Range between 16-17.2 MHz */
  547. hpcd->Instance->GUSBCFG |= (uint32_t)((0xD << 10) & USB_OTG_GUSBCFG_TRDT);
  548. }
  549. else if((hclk >= 17200000)&&(hclk < 18500000))
  550. {
  551. /* hclk Clock Range between 17.2-18.5 MHz */
  552. hpcd->Instance->GUSBCFG |= (uint32_t)((0xC << 10) & USB_OTG_GUSBCFG_TRDT);
  553. }
  554. else if((hclk >= 18500000)&&(hclk < 20000000))
  555. {
  556. /* hclk Clock Range between 18.5-20 MHz */
  557. hpcd->Instance->GUSBCFG |= (uint32_t)((0xB << 10) & USB_OTG_GUSBCFG_TRDT);
  558. }
  559. else if((hclk >= 20000000)&&(hclk < 21800000))
  560. {
  561. /* hclk Clock Range between 20-21.8 MHz */
  562. hpcd->Instance->GUSBCFG |= (uint32_t)((0xA << 10) & USB_OTG_GUSBCFG_TRDT);
  563. }
  564. else if((hclk >= 21800000)&&(hclk < 24000000))
  565. {
  566. /* hclk Clock Range between 21.8-24 MHz */
  567. hpcd->Instance->GUSBCFG |= (uint32_t)((0x9 << 10) & USB_OTG_GUSBCFG_TRDT);
  568. }
  569. else if((hclk >= 24000000)&&(hclk < 27700000))
  570. {
  571. /* hclk Clock Range between 24-27.7 MHz */
  572. hpcd->Instance->GUSBCFG |= (uint32_t)((0x8 << 10) & USB_OTG_GUSBCFG_TRDT);
  573. }
  574. else if((hclk >= 27700000)&&(hclk < 32000000))
  575. {
  576. /* hclk Clock Range between 27.7-32 MHz */
  577. hpcd->Instance->GUSBCFG |= (uint32_t)((0x7 << 10) & USB_OTG_GUSBCFG_TRDT);
  578. }
  579. else /* if(hclk >= 32000000) */
  580. {
  581. /* hclk Clock Range between 32-80 MHz */
  582. hpcd->Instance->GUSBCFG |= (uint32_t)((0x6 << 10) & USB_OTG_GUSBCFG_TRDT);
  583. }
  584. HAL_PCD_ResetCallback(hpcd);
  585. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE);
  586. }
  587. /* Handle RxQLevel Interrupt */
  588. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_RXFLVL))
  589. {
  590. USB_MASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL);
  591. temp = USBx->GRXSTSP;
  592. ep = &hpcd->OUT_ep[temp & USB_OTG_GRXSTSP_EPNUM];
  593. if(((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_DATA_UPDT)
  594. {
  595. if((temp & USB_OTG_GRXSTSP_BCNT) != 0)
  596. {
  597. USB_ReadPacket(USBx, ep->xfer_buff, (temp & USB_OTG_GRXSTSP_BCNT) >> 4);
  598. ep->xfer_buff += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
  599. ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
  600. }
  601. }
  602. else if (((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_SETUP_UPDT)
  603. {
  604. USB_ReadPacket(USBx, (uint8_t *)hpcd->Setup, 8);
  605. ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
  606. }
  607. USB_UNMASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL);
  608. }
  609. /* Handle SOF Interrupt */
  610. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SOF))
  611. {
  612. HAL_PCD_SOFCallback(hpcd);
  613. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SOF);
  614. }
  615. /* Handle Incomplete ISO IN Interrupt */
  616. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR))
  617. {
  618. HAL_PCD_ISOINIncompleteCallback(hpcd, epnum);
  619. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR);
  620. }
  621. /* Handle Incomplete ISO OUT Interrupt */
  622. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
  623. {
  624. HAL_PCD_ISOOUTIncompleteCallback(hpcd, epnum);
  625. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
  626. }
  627. /* Handle Connection event Interrupt */
  628. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT))
  629. {
  630. HAL_PCD_ConnectCallback(hpcd);
  631. __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT);
  632. }
  633. /* Handle Disconnection event Interrupt */
  634. if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OTGINT))
  635. {
  636. temp = hpcd->Instance->GOTGINT;
  637. if((temp & USB_OTG_GOTGINT_SEDET) == USB_OTG_GOTGINT_SEDET)
  638. {
  639. HAL_PCD_DisconnectCallback(hpcd);
  640. }
  641. hpcd->Instance->GOTGINT |= temp;
  642. }
  643. }
  644. }
  645. #endif /* USB_OTG_FS */
  646. #if defined (USB)
  647. /**
  648. * @brief This function handles PCD interrupt request.
  649. * @param hpcd: PCD handle
  650. * @retval HAL status
  651. */
  652. void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
  653. {
  654. uint32_t wInterrupt_Mask = 0;
  655. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_CTR))
  656. {
  657. /* servicing of the endpoint correct transfer interrupt */
  658. /* clear of the CTR flag into the sub */
  659. PCD_EP_ISR_Handler(hpcd);
  660. }
  661. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_RESET))
  662. {
  663. __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET);
  664. HAL_PCD_ResetCallback(hpcd);
  665. HAL_PCD_SetAddress(hpcd, 0);
  666. }
  667. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_PMAOVR))
  668. {
  669. __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_PMAOVR);
  670. }
  671. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ERR))
  672. {
  673. __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ERR);
  674. }
  675. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP))
  676. {
  677. hpcd->Instance->CNTR &= ~(USB_CNTR_LPMODE);
  678. /*set wInterrupt_Mask global variable*/
  679. wInterrupt_Mask = USB_CNTR_CTRM | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM \
  680. | USB_CNTR_SOFM | USB_CNTR_ESOFM | USB_CNTR_RESETM;
  681. /*Set interrupt mask*/
  682. hpcd->Instance->CNTR = wInterrupt_Mask;
  683. /* enable L1REQ interrupt */
  684. if (hpcd->Init.lpm_enable ==1)
  685. {
  686. wInterrupt_Mask |= USB_CNTR_L1REQM;
  687. /* Enable LPM support and enable ACK answer to LPM request*/
  688. USB_TypeDef *USBx = hpcd->Instance;
  689. hpcd->lpm_active = ENABLE;
  690. hpcd->LPM_State = LPM_L0;
  691. USBx->LPMCSR |= (USB_LPMCSR_LMPEN);
  692. USBx->LPMCSR |= (USB_LPMCSR_LPMACK);
  693. }
  694. if(hpcd->LPM_State == LPM_L1)
  695. {
  696. hpcd->LPM_State = LPM_L0;
  697. HAL_PCDEx_LPM_Callback(hpcd, PCD_LPM_L0_ACTIVE);
  698. }
  699. HAL_PCD_ResumeCallback(hpcd);
  700. __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP);
  701. }
  702. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SUSP))
  703. {
  704. /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
  705. __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP);
  706. /* Force low-power mode in the macrocell */
  707. hpcd->Instance->CNTR |= USB_CNTR_FSUSP;
  708. hpcd->Instance->CNTR |= USB_CNTR_LPMODE;
  709. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP) == 0)
  710. {
  711. HAL_PCD_SuspendCallback(hpcd);
  712. }
  713. }
  714. /* Handle LPM Interrupt */
  715. if(__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_L1REQ))
  716. {
  717. __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_L1REQ);
  718. if( hpcd->LPM_State == LPM_L0)
  719. {
  720. /* Force suspend and low-power mode before going to L1 state*/
  721. hpcd->Instance->CNTR |= USB_CNTR_LPMODE;
  722. hpcd->Instance->CNTR |= USB_CNTR_FSUSP;
  723. hpcd->LPM_State = LPM_L1;
  724. hpcd->BESL = (hpcd->Instance->LPMCSR & USB_LPMCSR_BESL) >>2 ;
  725. HAL_PCDEx_LPM_Callback(hpcd, PCD_LPM_L1_ACTIVE);
  726. }
  727. else
  728. {
  729. HAL_PCD_SuspendCallback(hpcd);
  730. }
  731. }
  732. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SOF))
  733. {
  734. __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF);
  735. HAL_PCD_SOFCallback(hpcd);
  736. }
  737. if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ESOF))
  738. {
  739. /* clear ESOF flag in ISTR */
  740. __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ESOF);
  741. }
  742. }
  743. #endif /* USB */
  744. /**
  745. * @brief Data OUT stage callback.
  746. * @param hpcd: PCD handle
  747. * @param epnum: endpoint number
  748. * @retval None
  749. */
  750. __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  751. {
  752. /* Prevent unused argument(s) compilation warning */
  753. UNUSED(hpcd);
  754. UNUSED(epnum);
  755. /* NOTE : This function should not be modified, when the callback is needed,
  756. the HAL_PCD_DataOutStageCallback could be implemented in the user file
  757. */
  758. }
  759. /**
  760. * @brief Data IN stage callback.
  761. * @param hpcd: PCD handle
  762. * @param epnum: endpoint number
  763. * @retval None
  764. */
  765. __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  766. {
  767. /* Prevent unused argument(s) compilation warning */
  768. UNUSED(hpcd);
  769. UNUSED(epnum);
  770. /* NOTE : This function should not be modified, when the callback is needed,
  771. the HAL_PCD_DataInStageCallback could be implemented in the user file
  772. */
  773. }
  774. /**
  775. * @brief Setup stage callback.
  776. * @param hpcd: PCD handle
  777. * @retval None
  778. */
  779. __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
  780. {
  781. /* Prevent unused argument(s) compilation warning */
  782. UNUSED(hpcd);
  783. /* NOTE : This function should not be modified, when the callback is needed,
  784. the HAL_PCD_SetupStageCallback could be implemented in the user file
  785. */
  786. }
  787. /**
  788. * @brief USB Start Of Frame callback.
  789. * @param hpcd: PCD handle
  790. * @retval None
  791. */
  792. __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
  793. {
  794. /* Prevent unused argument(s) compilation warning */
  795. UNUSED(hpcd);
  796. /* NOTE : This function should not be modified, when the callback is needed,
  797. the HAL_PCD_SOFCallback could be implemented in the user file
  798. */
  799. }
  800. /**
  801. * @brief USB Reset callback.
  802. * @param hpcd: PCD handle
  803. * @retval None
  804. */
  805. __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
  806. {
  807. /* Prevent unused argument(s) compilation warning */
  808. UNUSED(hpcd);
  809. /* NOTE : This function should not be modified, when the callback is needed,
  810. the HAL_PCD_ResetCallback could be implemented in the user file
  811. */
  812. }
  813. /**
  814. * @brief Suspend event callback.
  815. * @param hpcd: PCD handle
  816. * @retval None
  817. */
  818. __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
  819. {
  820. /* Prevent unused argument(s) compilation warning */
  821. UNUSED(hpcd);
  822. /* NOTE : This function should not be modified, when the callback is needed,
  823. the HAL_PCD_SuspendCallback could be implemented in the user file
  824. */
  825. }
  826. /**
  827. * @brief Resume event callback.
  828. * @param hpcd: PCD handle
  829. * @retval None
  830. */
  831. __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
  832. {
  833. /* Prevent unused argument(s) compilation warning */
  834. UNUSED(hpcd);
  835. /* NOTE : This function should not be modified, when the callback is needed,
  836. the HAL_PCD_ResumeCallback could be implemented in the user file
  837. */
  838. }
  839. /**
  840. * @brief Incomplete ISO OUT callback.
  841. * @param hpcd: PCD handle
  842. * @param epnum: endpoint number
  843. * @retval None
  844. */
  845. __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  846. {
  847. /* Prevent unused argument(s) compilation warning */
  848. UNUSED(hpcd);
  849. UNUSED(epnum);
  850. /* NOTE : This function should not be modified, when the callback is needed,
  851. the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file
  852. */
  853. }
  854. /**
  855. * @brief Incomplete ISO IN callback.
  856. * @param hpcd: PCD handle
  857. * @param epnum: endpoint number
  858. * @retval None
  859. */
  860. __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  861. {
  862. /* Prevent unused argument(s) compilation warning */
  863. UNUSED(hpcd);
  864. UNUSED(epnum);
  865. /* NOTE : This function should not be modified, when the callback is needed,
  866. the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file
  867. */
  868. }
  869. /**
  870. * @brief Connection event callback.
  871. * @param hpcd: PCD handle
  872. * @retval None
  873. */
  874. __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
  875. {
  876. /* Prevent unused argument(s) compilation warning */
  877. UNUSED(hpcd);
  878. /* NOTE : This function should not be modified, when the callback is needed,
  879. the HAL_PCD_ConnectCallback could be implemented in the user file
  880. */
  881. }
  882. /**
  883. * @brief Disconnection event callback.
  884. * @param hpcd: PCD handle
  885. * @retval None
  886. */
  887. __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
  888. {
  889. /* Prevent unused argument(s) compilation warning */
  890. UNUSED(hpcd);
  891. /* NOTE : This function should not be modified, when the callback is needed,
  892. the HAL_PCD_DisconnectCallback could be implemented in the user file
  893. */
  894. }
  895. /**
  896. * @}
  897. */
  898. /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions
  899. * @brief management functions
  900. *
  901. @verbatim
  902. ===============================================================================
  903. ##### Peripheral Control functions #####
  904. ===============================================================================
  905. [..]
  906. This subsection provides a set of functions allowing to control the PCD data
  907. transfers.
  908. @endverbatim
  909. * @{
  910. */
  911. /**
  912. * @brief Connect the USB device.
  913. * @param hpcd: PCD handle
  914. * @retval HAL status
  915. */
  916. HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd)
  917. {
  918. __HAL_LOCK(hpcd);
  919. USB_DevConnect(hpcd->Instance);
  920. __HAL_UNLOCK(hpcd);
  921. return HAL_OK;
  922. }
  923. /**
  924. * @brief Disconnect the USB device.
  925. * @param hpcd: PCD handle
  926. * @retval HAL status
  927. */
  928. HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd)
  929. {
  930. __HAL_LOCK(hpcd);
  931. USB_DevDisconnect(hpcd->Instance);
  932. __HAL_UNLOCK(hpcd);
  933. return HAL_OK;
  934. }
  935. /**
  936. * @brief Set the USB Device address.
  937. * @param hpcd: PCD handle
  938. * @param address: new device address
  939. * @retval HAL status
  940. */
  941. HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address)
  942. {
  943. __HAL_LOCK(hpcd);
  944. hpcd->USB_Address = address;
  945. USB_SetDevAddress(hpcd->Instance, address);
  946. __HAL_UNLOCK(hpcd);
  947. return HAL_OK;
  948. }
  949. /**
  950. * @brief Open and configure an endpoint.
  951. * @param hpcd: PCD handle
  952. * @param ep_addr: endpoint address
  953. * @param ep_mps: endpoint max packet size
  954. * @param ep_type: endpoint type
  955. * @retval HAL status
  956. */
  957. HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
  958. {
  959. HAL_StatusTypeDef ret = HAL_OK;
  960. PCD_EPTypeDef *ep = NULL;
  961. if ((ep_addr & 0x80) == 0x80)
  962. {
  963. ep = &hpcd->IN_ep[ep_addr & 0x7F];
  964. }
  965. else
  966. {
  967. ep = &hpcd->OUT_ep[ep_addr & 0x7F];
  968. }
  969. ep->num = ep_addr & 0x7F;
  970. ep->is_in = (0x80 & ep_addr) != 0;
  971. ep->maxpacket = ep_mps;
  972. ep->type = ep_type;
  973. __HAL_LOCK(hpcd);
  974. USB_ActivateEndpoint(hpcd->Instance , ep);
  975. __HAL_UNLOCK(hpcd);
  976. return ret;
  977. }
  978. /**
  979. * @brief Deactivate an endpoint.
  980. * @param hpcd: PCD handle
  981. * @param ep_addr: endpoint address
  982. * @retval HAL status
  983. */
  984. HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
  985. {
  986. PCD_EPTypeDef *ep = NULL;
  987. if ((ep_addr & 0x80) == 0x80)
  988. {
  989. ep = &hpcd->IN_ep[ep_addr & 0x7F];
  990. }
  991. else
  992. {
  993. ep = &hpcd->OUT_ep[ep_addr & 0x7F];
  994. }
  995. ep->num = ep_addr & 0x7F;
  996. ep->is_in = (0x80 & ep_addr) != 0;
  997. __HAL_LOCK(hpcd);
  998. USB_DeactivateEndpoint(hpcd->Instance , ep);
  999. __HAL_UNLOCK(hpcd);
  1000. return HAL_OK;
  1001. }
  1002. /**
  1003. * @brief Receive an amount of data.
  1004. * @param hpcd: PCD handle
  1005. * @param ep_addr: endpoint address
  1006. * @param pBuf: pointer to the reception buffer
  1007. * @param len: amount of data to be received
  1008. * @retval HAL status
  1009. */
  1010. HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
  1011. {
  1012. PCD_EPTypeDef *ep = NULL;
  1013. ep = &hpcd->OUT_ep[ep_addr & 0x7F];
  1014. /*setup and start the Xfer */
  1015. ep->xfer_buff = pBuf;
  1016. ep->xfer_len = len;
  1017. ep->xfer_count = 0;
  1018. ep->is_in = 0;
  1019. ep->num = ep_addr & 0x7F;
  1020. // Added for MBED PR #3062
  1021. __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1022. if ((ep_addr & 0x7F) == 0 )
  1023. {
  1024. USB_EP0StartXfer(hpcd->Instance, ep, hpcd->Init.dma_enable);
  1025. }
  1026. else
  1027. {
  1028. USB_EPStartXfer(hpcd->Instance, ep, hpcd->Init.dma_enable);
  1029. }
  1030. // Added for MBED PR #3062
  1031. __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1032. return HAL_OK;
  1033. }
  1034. /**
  1035. * @brief Get Received Data Size.
  1036. * @param hpcd: PCD handle
  1037. * @param ep_addr: endpoint address
  1038. * @retval Data Size
  1039. */
  1040. uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
  1041. {
  1042. return hpcd->OUT_ep[ep_addr & 0x7F].xfer_count;
  1043. }
  1044. /**
  1045. * @brief Send an amount of data.
  1046. * @param hpcd: PCD handle
  1047. * @param ep_addr: endpoint address
  1048. * @param pBuf: pointer to the transmission buffer
  1049. * @param len: amount of data to be sent
  1050. * @retval HAL status
  1051. */
  1052. HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
  1053. {
  1054. PCD_EPTypeDef *ep = NULL;
  1055. ep = &hpcd->IN_ep[ep_addr & 0x7F];
  1056. /*setup and start the Xfer */
  1057. ep->xfer_buff = pBuf;
  1058. ep->xfer_len = len;
  1059. ep->xfer_count = 0;
  1060. ep->is_in = 1;
  1061. ep->num = ep_addr & 0x7F;
  1062. // Added for MBED PR #3062
  1063. __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1064. if ((ep_addr & 0x7F) == 0 )
  1065. {
  1066. USB_EP0StartXfer(hpcd->Instance,ep, hpcd->Init.dma_enable);
  1067. }
  1068. else
  1069. {
  1070. USB_EPStartXfer(hpcd->Instance, ep, hpcd->Init.dma_enable);
  1071. }
  1072. // Added for MBED PR #3062
  1073. __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1074. return HAL_OK;
  1075. }
  1076. /**
  1077. * @brief Set a STALL condition over an endpoint.
  1078. * @param hpcd: PCD handle
  1079. * @param ep_addr: endpoint address
  1080. * @retval HAL status
  1081. */
  1082. HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
  1083. {
  1084. PCD_EPTypeDef *ep = NULL;
  1085. if ((0x80 & ep_addr) == 0x80)
  1086. {
  1087. ep = &hpcd->IN_ep[ep_addr & 0x7F];
  1088. }
  1089. else
  1090. {
  1091. ep = &hpcd->OUT_ep[ep_addr];
  1092. }
  1093. ep->is_stall = 1;
  1094. ep->num = ep_addr & 0x7F;
  1095. ep->is_in = ((ep_addr & 0x80) == 0x80);
  1096. // Added for MBED PR #3062
  1097. __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1098. USB_EPSetStall(hpcd->Instance , ep);
  1099. if((ep_addr & 0x7F) == 0)
  1100. {
  1101. USB_EP0_OutStart(hpcd->Instance, hpcd->Init.dma_enable, (uint8_t *)hpcd->Setup);
  1102. }
  1103. // Added for MBED PR #3062
  1104. __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1105. return HAL_OK;
  1106. }
  1107. /**
  1108. * @brief Clear a STALL condition over in an endpoint.
  1109. * @param hpcd: PCD handle
  1110. * @param ep_addr: endpoint address
  1111. * @retval HAL status
  1112. */
  1113. HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
  1114. {
  1115. PCD_EPTypeDef *ep = NULL;
  1116. if ((0x80 & ep_addr) == 0x80)
  1117. {
  1118. ep = &hpcd->IN_ep[ep_addr & 0x7F];
  1119. }
  1120. else
  1121. {
  1122. ep = &hpcd->OUT_ep[ep_addr];
  1123. }
  1124. ep->is_stall = 0;
  1125. ep->num = ep_addr & 0x7F;
  1126. ep->is_in = ((ep_addr & 0x80) == 0x80);
  1127. // Added for MBED PR #3062
  1128. __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1129. USB_EPClearStall(hpcd->Instance , ep);
  1130. // Added for MBED PR #3062
  1131. __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1132. return HAL_OK;
  1133. }
  1134. /**
  1135. * @brief Flush an endpoint.
  1136. * @param hpcd: PCD handle
  1137. * @param ep_addr: endpoint address
  1138. * @retval HAL status
  1139. */
  1140. HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
  1141. {
  1142. // Added for MBED PR #3062
  1143. __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1144. if ((ep_addr & 0x80) == 0x80)
  1145. {
  1146. USB_FlushTxFifo(hpcd->Instance, ep_addr & 0x7F);
  1147. }
  1148. else
  1149. {
  1150. USB_FlushRxFifo(hpcd->Instance);
  1151. }
  1152. // Added for MBED PR #3062
  1153. __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7F]);
  1154. return HAL_OK;
  1155. }
  1156. /**
  1157. * @brief Activate remote wakeup signalling.
  1158. * @param hpcd: PCD handle
  1159. * @retval HAL status
  1160. */
  1161. HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
  1162. {
  1163. return(USB_ActivateRemoteWakeup(hpcd->Instance));
  1164. }
  1165. /**
  1166. * @brief De-activate remote wakeup signalling.
  1167. * @param hpcd: PCD handle
  1168. * @retval HAL status
  1169. */
  1170. HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
  1171. {
  1172. return(USB_DeActivateRemoteWakeup(hpcd->Instance));
  1173. }
  1174. /**
  1175. * @}
  1176. */
  1177. /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions
  1178. * @brief Peripheral State functions
  1179. *
  1180. @verbatim
  1181. ===============================================================================
  1182. ##### Peripheral State functions #####
  1183. ===============================================================================
  1184. [..]
  1185. This subsection permits to get in run-time the status of the peripheral
  1186. and the data flow.
  1187. @endverbatim
  1188. * @{
  1189. */
  1190. /**
  1191. * @brief Return the PCD handle state.
  1192. * @param hpcd: PCD handle
  1193. * @retval HAL state
  1194. */
  1195. PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd)
  1196. {
  1197. return hpcd->State;
  1198. }
  1199. /**
  1200. * @}
  1201. */
  1202. /**
  1203. * @}
  1204. */
  1205. /* Private functions ---------------------------------------------------------*/
  1206. /** @addtogroup PCD_Private_Functions
  1207. * @{
  1208. */
  1209. #if defined (USB_OTG_FS)
  1210. /**
  1211. * @brief Check FIFO for the next packet to be loaded.
  1212. * @param hpcd: PCD handle
  1213. * @param epnum: endpoint number
  1214. * @retval HAL status
  1215. */
  1216. static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum)
  1217. {
  1218. USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
  1219. USB_OTG_EPTypeDef *ep = NULL;
  1220. uint32_t len;
  1221. uint32_t len32b = 0;
  1222. uint32_t fifoemptymsk = 0;
  1223. ep = &hpcd->IN_ep[epnum];
  1224. len = ep->xfer_len - ep->xfer_count;
  1225. if (len > ep->maxpacket)
  1226. {
  1227. len = ep->maxpacket;
  1228. }
  1229. len32b = (len + 3) / 4;
  1230. while ( (USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b &&
  1231. ep->xfer_count < ep->xfer_len &&
  1232. ep->xfer_len != 0)
  1233. {
  1234. /* Write the FIFO */
  1235. len = ep->xfer_len - ep->xfer_count;
  1236. if (len > ep->maxpacket)
  1237. {
  1238. len = ep->maxpacket;
  1239. }
  1240. len32b = (len + 3) / 4;
  1241. USB_WritePacket(USBx, ep->xfer_buff, epnum, len, hpcd->Init.dma_enable);
  1242. ep->xfer_buff += len;
  1243. ep->xfer_count += len;
  1244. }
  1245. if (ep->xfer_count >= ep->xfer_len)
  1246. {
  1247. fifoemptymsk = 0x1 << epnum;
  1248. // Added for MBED PR #3062
  1249. atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK, fifoemptymsk);
  1250. }
  1251. return HAL_OK;
  1252. }
  1253. #endif /* USB_OTG_FS */
  1254. #if defined (USB)
  1255. /**
  1256. * @brief This function handles PCD Endpoint interrupt request.
  1257. * @param hpcd: PCD handle
  1258. * @retval HAL status
  1259. */
  1260. static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
  1261. {
  1262. PCD_EPTypeDef *ep = NULL;
  1263. uint16_t count = 0;
  1264. uint8_t epindex = 0;
  1265. __IO uint16_t wIstr = 0;
  1266. __IO uint16_t wEPVal = 0;
  1267. /* stay in loop while pending interrupts */
  1268. while (((wIstr = hpcd->Instance->ISTR) & USB_ISTR_CTR) != 0)
  1269. {
  1270. /* extract highest priority endpoint number */
  1271. epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID);
  1272. if (epindex == 0)
  1273. {
  1274. /* Decode and service control endpoint interrupt */
  1275. /* DIR bit = origin of the interrupt */
  1276. if ((wIstr & USB_ISTR_DIR) == 0)
  1277. {
  1278. /* DIR = 0 */
  1279. /* DIR = 0 => IN int */
  1280. /* DIR = 0 implies that (EP_CTR_TX = 1) always */
  1281. PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0);
  1282. ep = &hpcd->IN_ep[0];
  1283. ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
  1284. ep->xfer_buff += ep->xfer_count;
  1285. /* TX COMPLETE */
  1286. HAL_PCD_DataInStageCallback(hpcd, 0);
  1287. if((hpcd->USB_Address > 0)&& ( ep->xfer_len == 0))
  1288. {
  1289. hpcd->Instance->DADDR = (hpcd->USB_Address | USB_DADDR_EF);
  1290. hpcd->USB_Address = 0;
  1291. }
  1292. }
  1293. else
  1294. {
  1295. /* DIR = 1 */
  1296. /* DIR = 1 & CTR_RX => SETUP or OUT int */
  1297. /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
  1298. ep = &hpcd->OUT_ep[0];
  1299. wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0);
  1300. if ((wEPVal & USB_EP_SETUP) != 0)
  1301. {
  1302. /* Get SETUP Packet*/
  1303. ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
  1304. USB_ReadPMA(hpcd->Instance, (uint8_t*)hpcd->Setup ,ep->pmaadress , ep->xfer_count);
  1305. /* SETUP bit kept frozen while CTR_RX = 1*/
  1306. PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
  1307. /* Process SETUP Packet*/
  1308. HAL_PCD_SetupStageCallback(hpcd);
  1309. }
  1310. else if ((wEPVal & USB_EP_CTR_RX) != 0)
  1311. {
  1312. PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
  1313. /* Get Control Data OUT Packet*/
  1314. ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
  1315. if (ep->xfer_count != 0)
  1316. {
  1317. USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count);
  1318. ep->xfer_buff+=ep->xfer_count;
  1319. }
  1320. /* Process Control Data OUT Packet*/
  1321. HAL_PCD_DataOutStageCallback(hpcd, 0);
  1322. PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket);
  1323. PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID);
  1324. }
  1325. }
  1326. }
  1327. else
  1328. {
  1329. /* Decode and service non control endpoints interrupt */
  1330. /* process related endpoint register */
  1331. wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, epindex);
  1332. if ((wEPVal & USB_EP_CTR_RX) != 0)
  1333. {
  1334. /* clear int flag */
  1335. PCD_CLEAR_RX_EP_CTR(hpcd->Instance, epindex);
  1336. ep = &hpcd->OUT_ep[epindex];
  1337. /* OUT double Buffering*/
  1338. if (ep->doublebuffer == 0)
  1339. {
  1340. count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
  1341. if (count != 0)
  1342. {
  1343. USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count);
  1344. }
  1345. }
  1346. else
  1347. {
  1348. if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX)
  1349. {
  1350. /*read from endpoint BUF0Addr buffer*/
  1351. count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
  1352. if (count != 0)
  1353. {
  1354. USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count);
  1355. }
  1356. }
  1357. else
  1358. {
  1359. /*read from endpoint BUF1Addr buffer*/
  1360. count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
  1361. if (count != 0)
  1362. {
  1363. USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count);
  1364. }
  1365. }
  1366. PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_OUT);
  1367. }
  1368. /*multi-packet on the NON control OUT endpoint*/
  1369. ep->xfer_count+=count;
  1370. ep->xfer_buff+=count;
  1371. if ((ep->xfer_len == 0) || (count < ep->maxpacket))
  1372. {
  1373. /* RX COMPLETE */
  1374. HAL_PCD_DataOutStageCallback(hpcd, ep->num);
  1375. }
  1376. else
  1377. {
  1378. HAL_PCD_EP_Receive(hpcd, ep->num, ep->xfer_buff, ep->xfer_len);
  1379. }
  1380. } /* if((wEPVal & EP_CTR_RX) */
  1381. if ((wEPVal & USB_EP_CTR_TX) != 0)
  1382. {
  1383. ep = &hpcd->IN_ep[epindex];
  1384. /* clear int flag */
  1385. PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex);
  1386. /* IN double Buffering*/
  1387. if (ep->doublebuffer == 0)
  1388. {
  1389. ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
  1390. if (ep->xfer_count != 0)
  1391. {
  1392. USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count);
  1393. }
  1394. }
  1395. else
  1396. {
  1397. if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_TX)
  1398. {
  1399. /*read from endpoint BUF0Addr buffer*/
  1400. ep->xfer_count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
  1401. if (ep->xfer_count != 0)
  1402. {
  1403. USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, ep->xfer_count);
  1404. }
  1405. }
  1406. else
  1407. {
  1408. /*read from endpoint BUF1Addr buffer*/
  1409. ep->xfer_count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
  1410. if (ep->xfer_count != 0)
  1411. {
  1412. USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, ep->xfer_count);
  1413. }
  1414. }
  1415. PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_IN);
  1416. }
  1417. /*multi-packet on the NON control IN endpoint*/
  1418. ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
  1419. ep->xfer_buff+=ep->xfer_count;
  1420. /* Zero Length Packet? */
  1421. if (ep->xfer_len == 0)
  1422. {
  1423. /* TX COMPLETE */
  1424. HAL_PCD_DataInStageCallback(hpcd, ep->num);
  1425. }
  1426. else
  1427. {
  1428. HAL_PCD_EP_Transmit(hpcd, ep->num, ep->xfer_buff, ep->xfer_len);
  1429. }
  1430. }
  1431. }
  1432. }
  1433. return HAL_OK;
  1434. }
  1435. #endif /* USB */
  1436. /**
  1437. * @}
  1438. */
  1439. #endif /* STM32L432xx || STM32L433xx || STM32L442xx || STM32L443xx || */
  1440. /* STM32L452xx || STM32L462xx || */
  1441. /* STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || */
  1442. /* STM32L496xx || STM32L4A6xx || */
  1443. /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  1444. #endif /* HAL_PCD_MODULE_ENABLED */
  1445. /**
  1446. * @}
  1447. */
  1448. /**
  1449. * @}
  1450. */
  1451. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/