Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

631 lines
18 KiB

  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : Target/usbd_conf.c
  5. * @version : v2.0_Cube
  6. * @brief : This file implements the board support package for the USB device library
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under Ultimate Liberty license
  14. * SLA0044, the "License"; You may not use this file except in compliance with
  15. * the License. You may obtain a copy of the License at:
  16. * www.st.com/SLA0044
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "usb_common_inc.h"
  23. #include "usbd_def.h"
  24. #include "usbd_core.h"
  25. #include "usbd_cdc.h"
  26. /* USER CODE BEGIN Includes */
  27. /* USER CODE END Includes */
  28. /* Private typedef -----------------------------------------------------------*/
  29. /* Private define ------------------------------------------------------------*/
  30. /* Private macro -------------------------------------------------------------*/
  31. /* USER CODE BEGIN PV */
  32. /* Private variables ---------------------------------------------------------*/
  33. /* USER CODE END PV */
  34. PCD_HandleTypeDef hpcd_USB_FS;
  35. void Error_Handler(void);
  36. /* USER CODE BEGIN 0 */
  37. /* USER CODE END 0 */
  38. /* USER CODE BEGIN PFP */
  39. /* Private function prototypes -----------------------------------------------*/
  40. /* USER CODE END PFP */
  41. /* Private functions ---------------------------------------------------------*/
  42. static USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status);
  43. /* USER CODE BEGIN 1 */
  44. /* USER CODE END 1 */
  45. /*******************************************************************************
  46. LL Driver Callbacks (PCD -> USB Device Library)
  47. *******************************************************************************/
  48. /* MSP Init */
  49. void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
  50. {
  51. if(pcdHandle->Instance==USB)
  52. {
  53. /* USER CODE BEGIN USB_MspInit 0 */
  54. /* USER CODE END USB_MspInit 0 */
  55. /* Peripheral clock enable */
  56. __HAL_RCC_USB_CLK_ENABLE();
  57. /* Peripheral interrupt init */
  58. HAL_NVIC_SetPriority(USB_LP_IRQn, 0, 0);
  59. HAL_NVIC_EnableIRQ(USB_LP_IRQn);
  60. /* USER CODE BEGIN USB_MspInit 1 */
  61. /* USER CODE END USB_MspInit 1 */
  62. }
  63. }
  64. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
  65. {
  66. if(pcdHandle->Instance==USB)
  67. {
  68. /* USER CODE BEGIN USB_MspDeInit 0 */
  69. /* USER CODE END USB_MspDeInit 0 */
  70. /* Peripheral clock disable */
  71. __HAL_RCC_USB_CLK_DISABLE();
  72. /* Peripheral interrupt Deinit*/
  73. HAL_NVIC_DisableIRQ(USB_LP_IRQn);
  74. /* USER CODE BEGIN USB_MspDeInit 1 */
  75. /* USER CODE END USB_MspDeInit 1 */
  76. }
  77. }
  78. /**
  79. * @brief Setup stage callback
  80. * @param hpcd: PCD handle
  81. * @retval None
  82. */
  83. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  84. static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
  85. #else
  86. void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
  87. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  88. {
  89. USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup);
  90. }
  91. /**
  92. * @brief Data Out stage callback.
  93. * @param hpcd: PCD handle
  94. * @param epnum: Endpoint number
  95. * @retval None
  96. */
  97. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  98. static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  99. #else
  100. void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  101. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  102. {
  103. USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
  104. }
  105. /**
  106. * @brief Data In stage callback.
  107. * @param hpcd: PCD handle
  108. * @param epnum: Endpoint number
  109. * @retval None
  110. */
  111. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  112. static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  113. #else
  114. void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  115. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  116. {
  117. USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
  118. }
  119. /**
  120. * @brief SOF callback.
  121. * @param hpcd: PCD handle
  122. * @retval None
  123. */
  124. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  125. static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
  126. #else
  127. void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
  128. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  129. {
  130. USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData);
  131. }
  132. /**
  133. * @brief Reset callback.
  134. * @param hpcd: PCD handle
  135. * @retval None
  136. */
  137. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  138. static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
  139. #else
  140. void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
  141. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  142. {
  143. USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
  144. if ( hpcd->Init.speed != PCD_SPEED_FULL)
  145. {
  146. Error_Handler();
  147. }
  148. /* Set Speed. */
  149. USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed);
  150. /* Reset Device. */
  151. USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData);
  152. }
  153. /**
  154. * @brief Suspend callback.
  155. * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
  156. * @param hpcd: PCD handle
  157. * @retval None
  158. */
  159. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  160. static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
  161. #else
  162. void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
  163. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  164. {
  165. /* Inform USB library that core enters in suspend Mode. */
  166. USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData);
  167. /* Enter in STOP mode. */
  168. /* USER CODE BEGIN 2 */
  169. if (hpcd->Init.low_power_enable)
  170. {
  171. /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
  172. SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
  173. }
  174. /* USER CODE END 2 */
  175. }
  176. /**
  177. * @brief Resume callback.
  178. * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
  179. * @param hpcd: PCD handle
  180. * @retval None
  181. */
  182. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  183. static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
  184. #else
  185. void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
  186. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  187. {
  188. /* USER CODE BEGIN 3 */
  189. /* USER CODE END 3 */
  190. USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData);
  191. }
  192. /**
  193. * @brief ISOOUTIncomplete callback.
  194. * @param hpcd: PCD handle
  195. * @param epnum: Endpoint number
  196. * @retval None
  197. */
  198. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  199. static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  200. #else
  201. void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  202. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  203. {
  204. USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
  205. }
  206. /**
  207. * @brief ISOINIncomplete callback.
  208. * @param hpcd: PCD handle
  209. * @param epnum: Endpoint number
  210. * @retval None
  211. */
  212. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  213. static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  214. #else
  215. void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
  216. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  217. {
  218. USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
  219. }
  220. /**
  221. * @brief Connect callback.
  222. * @param hpcd: PCD handle
  223. * @retval None
  224. */
  225. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  226. static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
  227. #else
  228. void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
  229. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  230. {
  231. USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData);
  232. }
  233. /**
  234. * @brief Disconnect callback.
  235. * @param hpcd: PCD handle
  236. * @retval None
  237. */
  238. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  239. static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
  240. #else
  241. void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
  242. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  243. {
  244. USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData);
  245. }
  246. /*******************************************************************************
  247. LL Driver Interface (USB Device Library --> PCD)
  248. *******************************************************************************/
  249. /**
  250. * @brief Initializes the low level portion of the device driver.
  251. * @param pdev: Device handle
  252. * @retval USBD status
  253. */
  254. USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
  255. {
  256. /* Init USB Ip. */
  257. /* Link the driver to the stack. */
  258. hpcd_USB_FS.pData = pdev;
  259. pdev->pData = &hpcd_USB_FS;
  260. hpcd_USB_FS.Instance = USB;
  261. hpcd_USB_FS.Init.dev_endpoints = 8;
  262. hpcd_USB_FS.Init.speed = PCD_SPEED_FULL;
  263. hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  264. hpcd_USB_FS.Init.low_power_enable = DISABLE;
  265. hpcd_USB_FS.Init.battery_charging_enable = DISABLE;
  266. if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK)
  267. {
  268. Error_Handler( );
  269. }
  270. #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  271. /* Register USB PCD CallBacks */
  272. HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback);
  273. HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback);
  274. HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback);
  275. HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback);
  276. HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback);
  277. HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback);
  278. HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback);
  279. HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_FS, PCD_DataOutStageCallback);
  280. HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_FS, PCD_DataInStageCallback);
  281. HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_FS, PCD_ISOOUTIncompleteCallback);
  282. HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_FS, PCD_ISOINIncompleteCallback);
  283. #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
  284. /* USER CODE BEGIN EndPoint_Configuration */
  285. HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18);
  286. HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58);
  287. /* USER CODE END EndPoint_Configuration */
  288. /* USER CODE BEGIN EndPoint_Configuration_CDC */
  289. HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0);
  290. HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110);
  291. HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100);
  292. /* USER CODE END EndPoint_Configuration_CDC */
  293. return USBD_OK;
  294. }
  295. /**
  296. * @brief De-Initializes the low level portion of the device driver.
  297. * @param pdev: Device handle
  298. * @retval USBD status
  299. */
  300. USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
  301. {
  302. HAL_StatusTypeDef hal_status = HAL_OK;
  303. USBD_StatusTypeDef usb_status = USBD_OK;
  304. hal_status = HAL_PCD_DeInit(pdev->pData);
  305. usb_status = USBD_Get_USB_Status(hal_status);
  306. return usb_status;
  307. }
  308. /**
  309. * @brief Starts the low level portion of the device driver.
  310. * @param pdev: Device handle
  311. * @retval USBD status
  312. */
  313. USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
  314. {
  315. HAL_StatusTypeDef hal_status = HAL_OK;
  316. USBD_StatusTypeDef usb_status = USBD_OK;
  317. hal_status = HAL_PCD_Start(pdev->pData);
  318. usb_status = USBD_Get_USB_Status(hal_status);
  319. return usb_status;
  320. }
  321. /**
  322. * @brief Stops the low level portion of the device driver.
  323. * @param pdev: Device handle
  324. * @retval USBD status
  325. */
  326. USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
  327. {
  328. HAL_StatusTypeDef hal_status = HAL_OK;
  329. USBD_StatusTypeDef usb_status = USBD_OK;
  330. hal_status = HAL_PCD_Stop(pdev->pData);
  331. usb_status = USBD_Get_USB_Status(hal_status);
  332. return usb_status;
  333. }
  334. /**
  335. * @brief Opens an endpoint of the low level driver.
  336. * @param pdev: Device handle
  337. * @param ep_addr: Endpoint number
  338. * @param ep_type: Endpoint type
  339. * @param ep_mps: Endpoint max packet size
  340. * @retval USBD status
  341. */
  342. USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
  343. {
  344. HAL_StatusTypeDef hal_status = HAL_OK;
  345. USBD_StatusTypeDef usb_status = USBD_OK;
  346. hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type);
  347. usb_status = USBD_Get_USB_Status(hal_status);
  348. return usb_status;
  349. }
  350. /**
  351. * @brief Closes an endpoint of the low level driver.
  352. * @param pdev: Device handle
  353. * @param ep_addr: Endpoint number
  354. * @retval USBD status
  355. */
  356. USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  357. {
  358. HAL_StatusTypeDef hal_status = HAL_OK;
  359. USBD_StatusTypeDef usb_status = USBD_OK;
  360. hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr);
  361. usb_status = USBD_Get_USB_Status(hal_status);
  362. return usb_status;
  363. }
  364. /**
  365. * @brief Flushes an endpoint of the Low Level Driver.
  366. * @param pdev: Device handle
  367. * @param ep_addr: Endpoint number
  368. * @retval USBD status
  369. */
  370. USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  371. {
  372. HAL_StatusTypeDef hal_status = HAL_OK;
  373. USBD_StatusTypeDef usb_status = USBD_OK;
  374. hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr);
  375. usb_status = USBD_Get_USB_Status(hal_status);
  376. return usb_status;
  377. }
  378. /**
  379. * @brief Sets a Stall condition on an endpoint of the Low Level Driver.
  380. * @param pdev: Device handle
  381. * @param ep_addr: Endpoint number
  382. * @retval USBD status
  383. */
  384. USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  385. {
  386. HAL_StatusTypeDef hal_status = HAL_OK;
  387. USBD_StatusTypeDef usb_status = USBD_OK;
  388. hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
  389. usb_status = USBD_Get_USB_Status(hal_status);
  390. return usb_status;
  391. }
  392. /**
  393. * @brief Clears a Stall condition on an endpoint of the Low Level Driver.
  394. * @param pdev: Device handle
  395. * @param ep_addr: Endpoint number
  396. * @retval USBD status
  397. */
  398. USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  399. {
  400. HAL_StatusTypeDef hal_status = HAL_OK;
  401. USBD_StatusTypeDef usb_status = USBD_OK;
  402. hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
  403. usb_status = USBD_Get_USB_Status(hal_status);
  404. return usb_status;
  405. }
  406. /**
  407. * @brief Returns Stall condition.
  408. * @param pdev: Device handle
  409. * @param ep_addr: Endpoint number
  410. * @retval Stall (1: Yes, 0: No)
  411. */
  412. uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  413. {
  414. PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData;
  415. if((ep_addr & 0x80) == 0x80)
  416. {
  417. return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
  418. }
  419. else
  420. {
  421. return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
  422. }
  423. }
  424. /**
  425. * @brief Assigns a USB address to the device.
  426. * @param pdev: Device handle
  427. * @param dev_addr: Device address
  428. * @retval USBD status
  429. */
  430. USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
  431. {
  432. HAL_StatusTypeDef hal_status = HAL_OK;
  433. USBD_StatusTypeDef usb_status = USBD_OK;
  434. hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr);
  435. usb_status = USBD_Get_USB_Status(hal_status);
  436. return usb_status;
  437. }
  438. /**
  439. * @brief Transmits data over an endpoint.
  440. * @param pdev: Device handle
  441. * @param ep_addr: Endpoint number
  442. * @param pbuf: Pointer to data to be sent
  443. * @param size: Data size
  444. * @retval USBD status
  445. */
  446. USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
  447. {
  448. HAL_StatusTypeDef hal_status = HAL_OK;
  449. USBD_StatusTypeDef usb_status = USBD_OK;
  450. hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
  451. usb_status = USBD_Get_USB_Status(hal_status);
  452. return usb_status;
  453. }
  454. /**
  455. * @brief Prepares an endpoint for reception.
  456. * @param pdev: Device handle
  457. * @param ep_addr: Endpoint number
  458. * @param pbuf: Pointer to data to be received
  459. * @param size: Data size
  460. * @retval USBD status
  461. */
  462. USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
  463. {
  464. HAL_StatusTypeDef hal_status = HAL_OK;
  465. USBD_StatusTypeDef usb_status = USBD_OK;
  466. hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
  467. usb_status = USBD_Get_USB_Status(hal_status);
  468. return usb_status;
  469. }
  470. /**
  471. * @brief Returns the last transfered packet size.
  472. * @param pdev: Device handle
  473. * @param ep_addr: Endpoint number
  474. * @retval Recived Data Size
  475. */
  476. uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  477. {
  478. return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr);
  479. }
  480. /**
  481. * @brief Delays routine for the USB device library.
  482. * @param Delay: Delay in ms
  483. * @retval None
  484. */
  485. void USBD_LL_Delay(uint32_t Delay)
  486. {
  487. HAL_Delay(Delay);
  488. }
  489. /**
  490. * @brief Static single allocation.
  491. * @param size: Size of allocated memory
  492. * @retval None
  493. */
  494. void *USBD_static_malloc(uint32_t size)
  495. {
  496. static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */
  497. return mem;
  498. }
  499. /**
  500. * @brief Dummy memory free
  501. * @param p: Pointer to allocated memory address
  502. * @retval None
  503. */
  504. void USBD_static_free(void *p)
  505. {
  506. }
  507. /**
  508. * @brief Retuns the USB status depending on the HAL status:
  509. * @param hal_status: HAL status
  510. * @retval USB status
  511. */
  512. USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status)
  513. {
  514. USBD_StatusTypeDef usb_status = USBD_OK;
  515. switch (hal_status)
  516. {
  517. case HAL_OK :
  518. usb_status = USBD_OK;
  519. break;
  520. case HAL_ERROR :
  521. usb_status = USBD_FAIL;
  522. break;
  523. case HAL_BUSY :
  524. usb_status = USBD_BUSY;
  525. break;
  526. case HAL_TIMEOUT :
  527. usb_status = USBD_FAIL;
  528. break;
  529. default :
  530. usb_status = USBD_FAIL;
  531. break;
  532. }
  533. return usb_status;
  534. }
  535. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/