usbd_conf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /**
  2. ******************************************************************************
  3. * @file : usbd_conf.c
  4. * @version : v1.0_Cube
  5. * @brief : This file implements the board support package for the USB device library
  6. ******************************************************************************
  7. *
  8. * COPYRIGHT(c) 2019 STMicroelectronics
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f2xx.h"
  36. #include "stm32f2xx_hal.h"
  37. #include "usbd_def.h"
  38. #include "usbd_core.h"
  39. PCD_HandleTypeDef hpcd_USB_OTG_HS;
  40. /* External functions --------------------------------------------------------*/
  41. void SystemClock_Config(void);
  42. /* USER CODE BEGIN 0 */
  43. /* USER CODE END 0 */
  44. /* Private function prototypes -----------------------------------------------*/
  45. /* Private functions ---------------------------------------------------------*/
  46. /* USER CODE BEGIN 1 */
  47. /* USER CODE END 1 */
  48. /*******************************************************************************
  49. LL Driver Callbacks (PCD -> USB Device Library)
  50. *******************************************************************************/
  51. /* MSP Init */
  52. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  53. {
  54. GPIO_InitTypeDef GPIO_InitStruct;
  55. if(hpcd->Instance==USB_OTG_FS)
  56. {
  57. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  58. /* USER CODE END USB_OTG_FS_MspInit 0 */
  59. /**USB_OTG_FS GPIO Configuration
  60. PA10 ------> USB_OTG_FS_ID
  61. PA11 ------> USB_OTG_FS_DM
  62. PA12 ------> USB_OTG_FS_DP
  63. */
  64. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
  65. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  66. GPIO_InitStruct.Pull = GPIO_NOPULL;
  67. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  68. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  69. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  70. /* Peripheral clock enable */
  71. __USB_OTG_FS_CLK_ENABLE();
  72. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  73. /* USER CODE END USB_OTG_FS_MspInit 1 */
  74. }
  75. else if(hpcd->Instance==USB_OTG_HS)
  76. {
  77. /* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
  78. /* USER CODE END USB_OTG_HS_MspInit 0 */
  79. /**USB_OTG_HS GPIO Configuration
  80. PC0 ------> USB_OTG_HS_ULPI_STP
  81. PC2 ------> USB_OTG_HS_ULPI_DIR
  82. PC3 ------> USB_OTG_HS_ULPI_NXT
  83. PA3 ------> USB_OTG_HS_ULPI_D0
  84. PA5 ------> USB_OTG_HS_ULPI_CK
  85. PB0 ------> USB_OTG_HS_ULPI_D1
  86. PB1 ------> USB_OTG_HS_ULPI_D2
  87. PB10 ------> USB_OTG_HS_ULPI_D3
  88. PB11 ------> USB_OTG_HS_ULPI_D4
  89. PB12 ------> USB_OTG_HS_ULPI_D5
  90. PB13 ------> USB_OTG_HS_ULPI_D6
  91. PB5 ------> USB_OTG_HS_ULPI_D7
  92. */
  93. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_2|GPIO_PIN_3;
  94. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  95. GPIO_InitStruct.Pull = GPIO_NOPULL;
  96. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  97. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  98. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  99. GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_5;
  100. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  101. GPIO_InitStruct.Pull = GPIO_NOPULL;
  102. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  103. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  104. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  105. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_11
  106. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_5;
  107. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  108. GPIO_InitStruct.Pull = GPIO_NOPULL;
  109. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  110. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  111. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  112. /* Peripheral clock enable */
  113. __USB_OTG_HS_CLK_ENABLE();
  114. __USB_OTG_HS_ULPI_CLK_ENABLE();
  115. /* Peripheral interrupt init*/
  116. HAL_NVIC_SetPriority(OTG_HS_IRQn, 0, 0);
  117. HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
  118. /* USER CODE BEGIN USB_OTG_HS_MspInit 1 */
  119. /* USER CODE END USB_OTG_HS_MspInit 1 */
  120. }
  121. }
  122. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  123. {
  124. if(hpcd->Instance==USB_OTG_FS)
  125. {
  126. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  127. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  128. /* Peripheral clock disable */
  129. __USB_OTG_FS_CLK_DISABLE();
  130. /**USB_OTG_FS GPIO Configuration
  131. PA10 ------> USB_OTG_FS_ID
  132. PA11 ------> USB_OTG_FS_DM
  133. PA12 ------> USB_OTG_FS_DP
  134. */
  135. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);
  136. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  137. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  138. }
  139. else if(hpcd->Instance==USB_OTG_HS)
  140. {
  141. /* USER CODE BEGIN USB_OTG_HS_MspDeInit 0 */
  142. /* USER CODE END USB_OTG_HS_MspDeInit 0 */
  143. /* Disable Peripheral clock */
  144. __USB_OTG_HS_CLK_DISABLE();
  145. __USB_OTG_HS_ULPI_CLK_DISABLE();
  146. /**USB_OTG_HS GPIO Configuration
  147. PC0 ------> USB_OTG_HS_ULPI_STP
  148. PC2 ------> USB_OTG_HS_ULPI_DIR
  149. PC3 ------> USB_OTG_HS_ULPI_NXT
  150. PA3 ------> USB_OTG_HS_ULPI_D0
  151. PA5 ------> USB_OTG_HS_ULPI_CK
  152. PB0 ------> USB_OTG_HS_ULPI_D1
  153. PB1 ------> USB_OTG_HS_ULPI_D2
  154. PB10 ------> USB_OTG_HS_ULPI_D3
  155. PB11 ------> USB_OTG_HS_ULPI_D4
  156. PB12 ------> USB_OTG_HS_ULPI_D5
  157. PB13 ------> USB_OTG_HS_ULPI_D6
  158. PB5 ------> USB_OTG_HS_ULPI_D7
  159. */
  160. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_2|GPIO_PIN_3);
  161. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3|GPIO_PIN_5);
  162. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_11
  163. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_5);
  164. /* Peripheral interrupt Deinit*/
  165. HAL_NVIC_DisableIRQ(OTG_HS_IRQn);
  166. /* USER CODE BEGIN USB_OTG_HS_MspDeInit 1 */
  167. /* USER CODE END USB_OTG_HS_MspDeInit 1 */
  168. }
  169. }
  170. /**
  171. * @brief Setup stage callback
  172. * @param hpcd: PCD handle
  173. * @retval None
  174. */
  175. void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
  176. {
  177. USBD_LL_SetupStage(hpcd->pData, (uint8_t *)hpcd->Setup);
  178. }
  179. /**
  180. * @brief Data Out stage callback.
  181. * @param hpcd: PCD handle
  182. * @param epnum: Endpoint Number
  183. * @retval None
  184. */
  185. void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  186. {
  187. USBD_LL_DataOutStage(hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
  188. }
  189. /**
  190. * @brief Data In stage callback..
  191. * @param hpcd: PCD handle
  192. * @param epnum: Endpoint Number
  193. * @retval None
  194. */
  195. void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  196. {
  197. USBD_LL_DataInStage(hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
  198. }
  199. /**
  200. * @brief SOF callback.
  201. * @param hpcd: PCD handle
  202. * @retval None
  203. */
  204. void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
  205. {
  206. USBD_LL_SOF(hpcd->pData);
  207. }
  208. /**
  209. * @brief Reset callback.
  210. * @param hpcd: PCD handle
  211. * @retval None
  212. */
  213. void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
  214. {
  215. USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
  216. /*Set USB Current Speed*/
  217. switch (hpcd->Init.speed)
  218. {
  219. case PCD_SPEED_HIGH:
  220. speed = USBD_SPEED_HIGH;
  221. break;
  222. case PCD_SPEED_FULL:
  223. speed = USBD_SPEED_FULL;
  224. break;
  225. default:
  226. speed = USBD_SPEED_FULL;
  227. break;
  228. }
  229. USBD_LL_SetSpeed(hpcd->pData, speed);
  230. /*Reset Device*/
  231. USBD_LL_Reset(hpcd->pData);
  232. }
  233. /**
  234. * @brief Suspend callback.
  235. * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
  236. * @param hpcd: PCD handle
  237. * @retval None
  238. */
  239. void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
  240. {
  241. /* Inform USB library that core enters in suspend Mode */
  242. USBD_LL_Suspend(hpcd->pData);
  243. __HAL_PCD_GATE_PHYCLOCK(hpcd);
  244. /*Enter in STOP mode */
  245. /* USER CODE BEGIN 2 */
  246. if (hpcd->Init.low_power_enable)
  247. {
  248. /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */
  249. SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
  250. }
  251. /* USER CODE END 2 */
  252. }
  253. /**
  254. * @brief Resume callback.
  255. When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
  256. * @param hpcd: PCD handle
  257. * @retval None
  258. */
  259. void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
  260. {
  261. /* USER CODE BEGIN 3 */
  262. /* USER CODE END 3 */
  263. USBD_LL_Resume(hpcd->pData);
  264. }
  265. /**
  266. * @brief ISOC Out Incomplete callback.
  267. * @param hpcd: PCD handle
  268. * @param epnum: Endpoint Number
  269. * @retval None
  270. */
  271. void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  272. {
  273. USBD_LL_IsoOUTIncomplete(hpcd->pData, epnum);
  274. }
  275. /**
  276. * @brief ISOC In Incomplete callback.
  277. * @param hpcd: PCD handle
  278. * @param epnum: Endpoint Number
  279. * @retval None
  280. */
  281. void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  282. {
  283. USBD_LL_IsoINIncomplete(hpcd->pData, epnum);
  284. }
  285. /**
  286. * @brief Connect callback.
  287. * @param hpcd: PCD handle
  288. * @retval None
  289. */
  290. void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
  291. {
  292. USBD_LL_DevConnected(hpcd->pData);
  293. }
  294. /**
  295. * @brief Disconnect callback.
  296. * @param hpcd: PCD handle
  297. * @retval None
  298. */
  299. void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
  300. {
  301. USBD_LL_DevDisconnected(hpcd->pData);
  302. }
  303. /*******************************************************************************
  304. LL Driver Interface (USB Device Library --> PCD)
  305. *******************************************************************************/
  306. /**
  307. * @brief Initializes the Low Level portion of the Device driver.
  308. * @param pdev: Device handle
  309. * @retval USBD Status
  310. */
  311. USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
  312. {
  313. /* Init USB_IP */
  314. if (pdev->id == DEVICE_HS) {
  315. /* Link The driver to the stack */
  316. hpcd_USB_OTG_HS.pData = pdev;
  317. pdev->pData = &hpcd_USB_OTG_HS;
  318. hpcd_USB_OTG_HS.Instance = USB_OTG_HS;
  319. hpcd_USB_OTG_HS.Init.dev_endpoints = 11;
  320. hpcd_USB_OTG_HS.Init.speed = PCD_SPEED_HIGH;
  321. hpcd_USB_OTG_HS.Init.dma_enable = ENABLE;
  322. hpcd_USB_OTG_HS.Init.ep0_mps = DEP0CTL_MPS_64;
  323. hpcd_USB_OTG_HS.Init.phy_itface = USB_OTG_ULPI_PHY;
  324. hpcd_USB_OTG_HS.Init.Sof_enable = DISABLE;
  325. hpcd_USB_OTG_HS.Init.low_power_enable = DISABLE;
  326. hpcd_USB_OTG_HS.Init.vbus_sensing_enable = DISABLE;
  327. hpcd_USB_OTG_HS.Init.use_dedicated_ep1 = DISABLE;
  328. hpcd_USB_OTG_HS.Init.use_external_vbus = DISABLE;
  329. HAL_PCD_Init(&hpcd_USB_OTG_HS);
  330. HAL_PCD_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200);
  331. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x80);
  332. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x174);
  333. }
  334. return USBD_OK;
  335. }
  336. /**
  337. * @brief De-Initializes the Low Level portion of the Device driver.
  338. * @param pdev: Device handle
  339. * @retval USBD Status
  340. */
  341. USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev)
  342. {
  343. HAL_PCD_DeInit(pdev->pData);
  344. return USBD_OK;
  345. }
  346. /**
  347. * @brief Starts the Low Level portion of the Device driver.
  348. * @param pdev: Device handle
  349. * @retval USBD Status
  350. */
  351. USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
  352. {
  353. HAL_PCD_Start(pdev->pData);
  354. return USBD_OK;
  355. }
  356. /**
  357. * @brief Stops the Low Level portion of the Device driver.
  358. * @param pdev: Device handle
  359. * @retval USBD Status
  360. */
  361. USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev)
  362. {
  363. HAL_PCD_Stop(pdev->pData);
  364. return USBD_OK;
  365. }
  366. /**
  367. * @brief Opens an endpoint of the Low Level Driver.
  368. * @param pdev: Device handle
  369. * @param ep_addr: Endpoint Number
  370. * @param ep_type: Endpoint Type
  371. * @param ep_mps: Endpoint Max Packet Size
  372. * @retval USBD Status
  373. */
  374. USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev,
  375. uint8_t ep_addr,
  376. uint8_t ep_type,
  377. uint16_t ep_mps)
  378. {
  379. HAL_PCD_EP_Open(pdev->pData,
  380. ep_addr,
  381. ep_mps,
  382. ep_type);
  383. return USBD_OK;
  384. }
  385. /**
  386. * @brief Closes an endpoint of the Low Level Driver.
  387. * @param pdev: Device handle
  388. * @param ep_addr: Endpoint Number
  389. * @retval USBD Status
  390. */
  391. USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  392. {
  393. HAL_PCD_EP_Close(pdev->pData, ep_addr);
  394. return USBD_OK;
  395. }
  396. /**
  397. * @brief Flushes an endpoint of the Low Level Driver.
  398. * @param pdev: Device handle
  399. * @param ep_addr: Endpoint Number
  400. * @retval USBD Status
  401. */
  402. USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  403. {
  404. HAL_PCD_EP_Flush(pdev->pData, ep_addr);
  405. return USBD_OK;
  406. }
  407. /**
  408. * @brief Sets a Stall condition on an endpoint of the Low Level Driver.
  409. * @param pdev: Device handle
  410. * @param ep_addr: Endpoint Number
  411. * @retval USBD Status
  412. */
  413. USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  414. {
  415. HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
  416. return USBD_OK;
  417. }
  418. /**
  419. * @brief Clears a Stall condition on an endpoint of the Low Level Driver.
  420. * @param pdev: Device handle
  421. * @param ep_addr: Endpoint Number
  422. * @retval USBD Status
  423. */
  424. USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  425. {
  426. HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
  427. return USBD_OK;
  428. }
  429. /**
  430. * @brief Returns Stall condition.
  431. * @param pdev: Device handle
  432. * @param ep_addr: Endpoint Number
  433. * @retval Stall (1: Yes, 0: No)
  434. */
  435. uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  436. {
  437. PCD_HandleTypeDef *hpcd = pdev->pData;
  438. if((ep_addr & 0x80) == 0x80)
  439. {
  440. return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
  441. }
  442. else
  443. {
  444. return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
  445. }
  446. }
  447. /**
  448. * @brief Assigns a USB address to the device.
  449. * @param pdev: Device handle
  450. * @param ep_addr: Endpoint Number
  451. * @retval USBD Status
  452. */
  453. USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr)
  454. {
  455. HAL_PCD_SetAddress(pdev->pData, dev_addr);
  456. return USBD_OK;
  457. }
  458. /**
  459. * @brief Transmits data over an endpoint.
  460. * @param pdev: Device handle
  461. * @param ep_addr: Endpoint Number
  462. * @param pbuf: Pointer to data to be sent
  463. * @param size: Data size
  464. * @retval USBD Status
  465. */
  466. USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev,
  467. uint8_t ep_addr,
  468. uint8_t *pbuf,
  469. uint16_t size)
  470. {
  471. HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
  472. return USBD_OK;
  473. }
  474. /**
  475. * @brief Prepares an endpoint for reception.
  476. * @param pdev: Device handle
  477. * @param ep_addr: Endpoint Number
  478. * @param pbuf: Pointer to data to be received
  479. * @param size: Data size
  480. * @retval USBD Status
  481. */
  482. USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
  483. uint8_t ep_addr,
  484. uint8_t *pbuf,
  485. uint16_t size)
  486. {
  487. HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
  488. return USBD_OK;
  489. }
  490. /**
  491. * @brief Returns the last transfered packet size.
  492. * @param pdev: Device handle
  493. * @param ep_addr: Endpoint Number
  494. * @retval Recived Data Size
  495. */
  496. uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  497. {
  498. return HAL_PCD_EP_GetRxCount(pdev->pData, ep_addr);
  499. }
  500. /**
  501. * @brief Delays routine for the USB Device Library.
  502. * @param Delay: Delay in ms
  503. * @retval None
  504. */
  505. void USBD_LL_Delay (uint32_t Delay)
  506. {
  507. HAL_Delay(Delay);
  508. }
  509. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/