usbd_conf.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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_FS;
  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_FS) {
  315. /* Link The driver to the stack */
  316. hpcd_USB_OTG_FS.pData = pdev;
  317. pdev->pData = &hpcd_USB_OTG_FS;
  318. hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
  319. hpcd_USB_OTG_FS.Init.dev_endpoints = 7;
  320. hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
  321. hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
  322. hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;
  323. hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  324. hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
  325. hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
  326. hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE; // VBUS NOT CONNECTED ?? CHECK.
  327. hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  328. HAL_PCD_Init(&hpcd_USB_OTG_FS);
  329. // Sum of all FIFOs must be <= 320.
  330. HAL_PCD_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
  331. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
  332. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x40);
  333. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x40);
  334. HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
  335. HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
  336. } else if (pdev->id == DEVICE_HS) {
  337. /* Link The driver to the stack */
  338. /*
  339. hpcd_USB_OTG_HS.pData = pdev;
  340. pdev->pData = &hpcd_USB_OTG_HS;
  341. hpcd_USB_OTG_HS.Instance = USB_OTG_HS;
  342. hpcd_USB_OTG_HS.Init.dev_endpoints = 11;
  343. hpcd_USB_OTG_HS.Init.speed = PCD_SPEED_HIGH;
  344. hpcd_USB_OTG_HS.Init.dma_enable = ENABLE;
  345. hpcd_USB_OTG_HS.Init.ep0_mps = DEP0CTL_MPS_64;
  346. hpcd_USB_OTG_HS.Init.phy_itface = USB_OTG_ULPI_PHY;
  347. hpcd_USB_OTG_HS.Init.Sof_enable = DISABLE;
  348. hpcd_USB_OTG_HS.Init.low_power_enable = DISABLE;
  349. hpcd_USB_OTG_HS.Init.vbus_sensing_enable = DISABLE;
  350. hpcd_USB_OTG_HS.Init.use_dedicated_ep1 = DISABLE;
  351. hpcd_USB_OTG_HS.Init.use_external_vbus = DISABLE;
  352. HAL_PCD_Init(&hpcd_USB_OTG_HS);
  353. HAL_PCD_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200);
  354. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x40);
  355. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x40);
  356. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_HS, 2, 0x174);
  357. */
  358. }
  359. return USBD_OK;
  360. }
  361. /**
  362. * @brief De-Initializes the Low Level portion of the Device driver.
  363. * @param pdev: Device handle
  364. * @retval USBD Status
  365. */
  366. USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev)
  367. {
  368. HAL_PCD_DeInit(pdev->pData);
  369. return USBD_OK;
  370. }
  371. /**
  372. * @brief Starts the Low Level portion of the Device driver.
  373. * @param pdev: Device handle
  374. * @retval USBD Status
  375. */
  376. USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
  377. {
  378. HAL_PCD_Start(pdev->pData);
  379. return USBD_OK;
  380. }
  381. /**
  382. * @brief Stops the Low Level portion of the Device driver.
  383. * @param pdev: Device handle
  384. * @retval USBD Status
  385. */
  386. USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev)
  387. {
  388. HAL_PCD_Stop(pdev->pData);
  389. return USBD_OK;
  390. }
  391. /**
  392. * @brief Opens an endpoint of the Low Level Driver.
  393. * @param pdev: Device handle
  394. * @param ep_addr: Endpoint Number
  395. * @param ep_type: Endpoint Type
  396. * @param ep_mps: Endpoint Max Packet Size
  397. * @retval USBD Status
  398. */
  399. USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev,
  400. uint8_t ep_addr,
  401. uint8_t ep_type,
  402. uint16_t ep_mps)
  403. {
  404. HAL_PCD_EP_Open(pdev->pData,
  405. ep_addr,
  406. ep_mps,
  407. ep_type);
  408. return USBD_OK;
  409. }
  410. /**
  411. * @brief Closes an endpoint of the Low Level Driver.
  412. * @param pdev: Device handle
  413. * @param ep_addr: Endpoint Number
  414. * @retval USBD Status
  415. */
  416. USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  417. {
  418. HAL_PCD_EP_Close(pdev->pData, ep_addr);
  419. return USBD_OK;
  420. }
  421. /**
  422. * @brief Flushes an endpoint of the Low Level Driver.
  423. * @param pdev: Device handle
  424. * @param ep_addr: Endpoint Number
  425. * @retval USBD Status
  426. */
  427. USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  428. {
  429. HAL_PCD_EP_Flush(pdev->pData, ep_addr);
  430. return USBD_OK;
  431. }
  432. /**
  433. * @brief Sets a Stall condition on an endpoint of the Low Level Driver.
  434. * @param pdev: Device handle
  435. * @param ep_addr: Endpoint Number
  436. * @retval USBD Status
  437. */
  438. USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  439. {
  440. HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
  441. return USBD_OK;
  442. }
  443. /**
  444. * @brief Clears a Stall condition on an endpoint of the Low Level Driver.
  445. * @param pdev: Device handle
  446. * @param ep_addr: Endpoint Number
  447. * @retval USBD Status
  448. */
  449. USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  450. {
  451. HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
  452. return USBD_OK;
  453. }
  454. /**
  455. * @brief Returns Stall condition.
  456. * @param pdev: Device handle
  457. * @param ep_addr: Endpoint Number
  458. * @retval Stall (1: Yes, 0: No)
  459. */
  460. uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  461. {
  462. PCD_HandleTypeDef *hpcd = pdev->pData;
  463. if((ep_addr & 0x80) == 0x80)
  464. {
  465. return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
  466. }
  467. else
  468. {
  469. return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
  470. }
  471. }
  472. /**
  473. * @brief Assigns a USB address to the device.
  474. * @param pdev: Device handle
  475. * @param ep_addr: Endpoint Number
  476. * @retval USBD Status
  477. */
  478. USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr)
  479. {
  480. HAL_PCD_SetAddress(pdev->pData, dev_addr);
  481. return USBD_OK;
  482. }
  483. /**
  484. * @brief Transmits data over an endpoint.
  485. * @param pdev: Device handle
  486. * @param ep_addr: Endpoint Number
  487. * @param pbuf: Pointer to data to be sent
  488. * @param size: Data size
  489. * @retval USBD Status
  490. */
  491. USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev,
  492. uint8_t ep_addr,
  493. uint8_t *pbuf,
  494. uint16_t size)
  495. {
  496. HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
  497. return USBD_OK;
  498. }
  499. /**
  500. * @brief Prepares an endpoint for reception.
  501. * @param pdev: Device handle
  502. * @param ep_addr: Endpoint Number
  503. * @param pbuf: Pointer to data to be received
  504. * @param size: Data size
  505. * @retval USBD Status
  506. */
  507. USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
  508. uint8_t ep_addr,
  509. uint8_t *pbuf,
  510. uint16_t size)
  511. {
  512. HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
  513. return USBD_OK;
  514. }
  515. /**
  516. * @brief Returns the last transfered packet size.
  517. * @param pdev: Device handle
  518. * @param ep_addr: Endpoint Number
  519. * @retval Recived Data Size
  520. */
  521. uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  522. {
  523. return HAL_PCD_EP_GetRxCount(pdev->pData, ep_addr);
  524. }
  525. /**
  526. * @brief Delays routine for the USB Device Library.
  527. * @param Delay: Delay in ms
  528. * @retval None
  529. */
  530. void USBD_LL_Delay (uint32_t Delay)
  531. {
  532. HAL_Delay(Delay);
  533. }
  534. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/