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.
 
 
 
 
 
 

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