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.
 
 
 
 
 
 

887 lines
24 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_ll_usb.c
  4. * @author MCD Application Team
  5. * @brief USB Low Layer HAL module driver.
  6. *
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the USB Peripheral Controller:
  9. * + Initialization/de-initialization functions
  10. * + I/O operation functions
  11. * + Peripheral Control functions
  12. * + Peripheral State functions
  13. *
  14. @verbatim
  15. ==============================================================================
  16. ##### How to use this driver #####
  17. ==============================================================================
  18. [..]
  19. (#) Fill parameters of Init structure in USB_OTG_CfgTypeDef structure.
  20. (#) Call USB_CoreInit() API to initialize the USB Core peripheral.
  21. (#) The upper HAL HCD/PCD driver will call the right routines for its internal processes.
  22. @endverbatim
  23. ******************************************************************************
  24. * @attention
  25. *
  26. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  27. * All rights reserved.</center></h2>
  28. *
  29. * This software component is licensed by ST under BSD 3-Clause license,
  30. * the "License"; You may not use this file except in compliance with the
  31. * License. You may obtain a copy of the License at:
  32. * opensource.org/licenses/BSD-3-Clause
  33. *
  34. ******************************************************************************
  35. */
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32l1xx_hal.h"
  38. /** @addtogroup STM32L1xx_LL_USB_DRIVER
  39. * @{
  40. */
  41. #if defined (HAL_PCD_MODULE_ENABLED) || defined (HAL_HCD_MODULE_ENABLED)
  42. #if defined (USB)
  43. /* Private typedef -----------------------------------------------------------*/
  44. /* Private define ------------------------------------------------------------*/
  45. /* Private macro -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private function prototypes -----------------------------------------------*/
  48. /* Private functions ---------------------------------------------------------*/
  49. /**
  50. * @brief Initializes the USB Core
  51. * @param USBx: USB Instance
  52. * @param cfg : pointer to a USB_CfgTypeDef structure that contains
  53. * the configuration information for the specified USBx peripheral.
  54. * @retval HAL status
  55. */
  56. HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg)
  57. {
  58. /* Prevent unused argument(s) compilation warning */
  59. UNUSED(USBx);
  60. UNUSED(cfg);
  61. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  62. only by USB OTG FS peripheral.
  63. - This function is added to ensure compatibility across platforms.
  64. */
  65. return HAL_OK;
  66. }
  67. /**
  68. * @brief USB_EnableGlobalInt
  69. * Enables the controller's Global Int in the AHB Config reg
  70. * @param USBx : Selected device
  71. * @retval HAL status
  72. */
  73. HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx)
  74. {
  75. uint16_t winterruptmask;
  76. /* Set winterruptmask variable */
  77. winterruptmask = USB_CNTR_CTRM | USB_CNTR_WKUPM |
  78. USB_CNTR_SUSPM | USB_CNTR_ERRM |
  79. USB_CNTR_SOFM | USB_CNTR_ESOFM |
  80. USB_CNTR_RESETM;
  81. /* Set interrupt mask */
  82. USBx->CNTR |= winterruptmask;
  83. return HAL_OK;
  84. }
  85. /**
  86. * @brief USB_DisableGlobalInt
  87. * Disable the controller's Global Int in the AHB Config reg
  88. * @param USBx : Selected device
  89. * @retval HAL status
  90. */
  91. HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx)
  92. {
  93. uint16_t winterruptmask;
  94. /* Set winterruptmask variable */
  95. winterruptmask = USB_CNTR_CTRM | USB_CNTR_WKUPM |
  96. USB_CNTR_SUSPM | USB_CNTR_ERRM |
  97. USB_CNTR_SOFM | USB_CNTR_ESOFM |
  98. USB_CNTR_RESETM;
  99. /* Clear interrupt mask */
  100. USBx->CNTR &= ~winterruptmask;
  101. return HAL_OK;
  102. }
  103. /**
  104. * @brief USB_SetCurrentMode : Set functional mode
  105. * @param USBx : Selected device
  106. * @param mode : current core mode
  107. * This parameter can be one of the these values:
  108. * @arg USB_DEVICE_MODE: Peripheral mode mode
  109. * @retval HAL status
  110. */
  111. HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode)
  112. {
  113. /* Prevent unused argument(s) compilation warning */
  114. UNUSED(USBx);
  115. UNUSED(mode);
  116. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  117. only by USB OTG FS peripheral.
  118. - This function is added to ensure compatibility across platforms.
  119. */
  120. return HAL_OK;
  121. }
  122. /**
  123. * @brief USB_DevInit : Initializes the USB controller registers
  124. * for device mode
  125. * @param USBx : Selected device
  126. * @param cfg : pointer to a USB_CfgTypeDef structure that contains
  127. * the configuration information for the specified USBx peripheral.
  128. * @retval HAL status
  129. */
  130. HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg)
  131. {
  132. /* Prevent unused argument(s) compilation warning */
  133. UNUSED(cfg);
  134. /* Init Device */
  135. /*CNTR_FRES = 1*/
  136. USBx->CNTR = USB_CNTR_FRES;
  137. /*CNTR_FRES = 0*/
  138. USBx->CNTR = 0;
  139. /*Clear pending interrupts*/
  140. USBx->ISTR = 0;
  141. /*Set Btable Address*/
  142. USBx->BTABLE = BTABLE_ADDRESS;
  143. /* Enable USB Device Interrupt mask */
  144. (void)USB_EnableGlobalInt(USBx);
  145. return HAL_OK;
  146. }
  147. /**
  148. * @brief USB_SetDevSpeed :Initializes the device speed
  149. * depending on the PHY type and the enumeration speed of the device.
  150. * @param USBx Selected device
  151. * @param speed device speed
  152. * @retval Hal status
  153. */
  154. HAL_StatusTypeDef USB_SetDevSpeed(USB_TypeDef *USBx, uint8_t speed)
  155. {
  156. /* Prevent unused argument(s) compilation warning */
  157. UNUSED(USBx);
  158. UNUSED(speed);
  159. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  160. only by USB OTG FS peripheral.
  161. - This function is added to ensure compatibility across platforms.
  162. */
  163. return HAL_OK;
  164. }
  165. /**
  166. * @brief USB_FlushTxFifo : Flush a Tx FIFO
  167. * @param USBx : Selected device
  168. * @param num : FIFO number
  169. * This parameter can be a value from 1 to 15
  170. 15 means Flush all Tx FIFOs
  171. * @retval HAL status
  172. */
  173. HAL_StatusTypeDef USB_FlushTxFifo(USB_TypeDef *USBx, uint32_t num)
  174. {
  175. /* Prevent unused argument(s) compilation warning */
  176. UNUSED(USBx);
  177. UNUSED(num);
  178. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  179. only by USB OTG FS peripheral.
  180. - This function is added to ensure compatibility across platforms.
  181. */
  182. return HAL_OK;
  183. }
  184. /**
  185. * @brief USB_FlushRxFifo : Flush Rx FIFO
  186. * @param USBx : Selected device
  187. * @retval HAL status
  188. */
  189. HAL_StatusTypeDef USB_FlushRxFifo(USB_TypeDef *USBx)
  190. {
  191. /* Prevent unused argument(s) compilation warning */
  192. UNUSED(USBx);
  193. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  194. only by USB OTG FS peripheral.
  195. - This function is added to ensure compatibility across platforms.
  196. */
  197. return HAL_OK;
  198. }
  199. /**
  200. * @brief Activate and configure an endpoint
  201. * @param USBx : Selected device
  202. * @param ep: pointer to endpoint structure
  203. * @retval HAL status
  204. */
  205. HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
  206. {
  207. HAL_StatusTypeDef ret = HAL_OK;
  208. uint16_t wEpRegVal;
  209. wEpRegVal = PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_T_MASK;
  210. /* initialize Endpoint */
  211. switch (ep->type)
  212. {
  213. case EP_TYPE_CTRL:
  214. wEpRegVal |= USB_EP_CONTROL;
  215. break;
  216. case EP_TYPE_BULK:
  217. wEpRegVal |= USB_EP_BULK;
  218. break;
  219. case EP_TYPE_INTR:
  220. wEpRegVal |= USB_EP_INTERRUPT;
  221. break;
  222. case EP_TYPE_ISOC:
  223. wEpRegVal |= USB_EP_ISOCHRONOUS;
  224. break;
  225. default:
  226. ret = HAL_ERROR;
  227. break;
  228. }
  229. PCD_SET_ENDPOINT(USBx, ep->num, wEpRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX);
  230. PCD_SET_EP_ADDRESS(USBx, ep->num, ep->num);
  231. if (ep->doublebuffer == 0U)
  232. {
  233. if (ep->is_in != 0U)
  234. {
  235. /*Set the endpoint Transmit buffer address */
  236. PCD_SET_EP_TX_ADDRESS(USBx, ep->num, ep->pmaadress);
  237. PCD_CLEAR_TX_DTOG(USBx, ep->num);
  238. if (ep->type != EP_TYPE_ISOC)
  239. {
  240. /* Configure NAK status for the Endpoint */
  241. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
  242. }
  243. else
  244. {
  245. /* Configure TX Endpoint to disabled state */
  246. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
  247. }
  248. }
  249. else
  250. {
  251. /*Set the endpoint Receive buffer address */
  252. PCD_SET_EP_RX_ADDRESS(USBx, ep->num, ep->pmaadress);
  253. /*Set the endpoint Receive buffer counter*/
  254. PCD_SET_EP_RX_CNT(USBx, ep->num, ep->maxpacket);
  255. PCD_CLEAR_RX_DTOG(USBx, ep->num);
  256. /* Configure VALID status for the Endpoint*/
  257. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
  258. }
  259. }
  260. /*Double Buffer*/
  261. else
  262. {
  263. /* Set the endpoint as double buffered */
  264. PCD_SET_EP_DBUF(USBx, ep->num);
  265. /* Set buffer address for double buffered mode */
  266. PCD_SET_EP_DBUF_ADDR(USBx, ep->num, ep->pmaaddr0, ep->pmaaddr1);
  267. if (ep->is_in == 0U)
  268. {
  269. /* Clear the data toggle bits for the endpoint IN/OUT */
  270. PCD_CLEAR_RX_DTOG(USBx, ep->num);
  271. PCD_CLEAR_TX_DTOG(USBx, ep->num);
  272. /* Reset value of the data toggle bits for the endpoint out */
  273. PCD_TX_DTOG(USBx, ep->num);
  274. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
  275. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
  276. }
  277. else
  278. {
  279. /* Clear the data toggle bits for the endpoint IN/OUT */
  280. PCD_CLEAR_RX_DTOG(USBx, ep->num);
  281. PCD_CLEAR_TX_DTOG(USBx, ep->num);
  282. PCD_RX_DTOG(USBx, ep->num);
  283. if (ep->type != EP_TYPE_ISOC)
  284. {
  285. /* Configure NAK status for the Endpoint */
  286. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
  287. }
  288. else
  289. {
  290. /* Configure TX Endpoint to disabled state */
  291. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
  292. }
  293. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
  294. }
  295. }
  296. return ret;
  297. }
  298. /**
  299. * @brief De-activate and de-initialize an endpoint
  300. * @param USBx : Selected device
  301. * @param ep: pointer to endpoint structure
  302. * @retval HAL status
  303. */
  304. HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
  305. {
  306. if (ep->doublebuffer == 0U)
  307. {
  308. if (ep->is_in != 0U)
  309. {
  310. PCD_CLEAR_TX_DTOG(USBx, ep->num);
  311. /* Configure DISABLE status for the Endpoint*/
  312. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
  313. }
  314. else
  315. {
  316. PCD_CLEAR_RX_DTOG(USBx, ep->num);
  317. /* Configure DISABLE status for the Endpoint*/
  318. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
  319. }
  320. }
  321. /*Double Buffer*/
  322. else
  323. {
  324. if (ep->is_in == 0U)
  325. {
  326. /* Clear the data toggle bits for the endpoint IN/OUT*/
  327. PCD_CLEAR_RX_DTOG(USBx, ep->num);
  328. PCD_CLEAR_TX_DTOG(USBx, ep->num);
  329. /* Reset value of the data toggle bits for the endpoint out*/
  330. PCD_TX_DTOG(USBx, ep->num);
  331. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
  332. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
  333. }
  334. else
  335. {
  336. /* Clear the data toggle bits for the endpoint IN/OUT*/
  337. PCD_CLEAR_RX_DTOG(USBx, ep->num);
  338. PCD_CLEAR_TX_DTOG(USBx, ep->num);
  339. PCD_RX_DTOG(USBx, ep->num);
  340. /* Configure DISABLE status for the Endpoint*/
  341. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
  342. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
  343. }
  344. }
  345. return HAL_OK;
  346. }
  347. /**
  348. * @brief USB_EPStartXfer : setup and starts a transfer over an EP
  349. * @param USBx : Selected device
  350. * @param ep: pointer to endpoint structure
  351. * @retval HAL status
  352. */
  353. HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep)
  354. {
  355. uint16_t pmabuffer;
  356. uint32_t len;
  357. /* IN endpoint */
  358. if (ep->is_in == 1U)
  359. {
  360. /*Multi packet transfer*/
  361. if (ep->xfer_len > ep->maxpacket)
  362. {
  363. len = ep->maxpacket;
  364. ep->xfer_len -= len;
  365. }
  366. else
  367. {
  368. len = ep->xfer_len;
  369. ep->xfer_len = 0U;
  370. }
  371. /* configure and validate Tx endpoint */
  372. if (ep->doublebuffer == 0U)
  373. {
  374. USB_WritePMA(USBx, ep->xfer_buff, ep->pmaadress, (uint16_t)len);
  375. PCD_SET_EP_TX_CNT(USBx, ep->num, len);
  376. }
  377. else
  378. {
  379. /* Write the data to the USB endpoint */
  380. if ((PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_DTOG_TX) != 0U)
  381. {
  382. /* Set the Double buffer counter for pmabuffer1 */
  383. PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len);
  384. pmabuffer = ep->pmaaddr1;
  385. }
  386. else
  387. {
  388. /* Set the Double buffer counter for pmabuffer0 */
  389. PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
  390. pmabuffer = ep->pmaaddr0;
  391. }
  392. USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
  393. PCD_FreeUserBuffer(USBx, ep->num, ep->is_in);
  394. }
  395. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_VALID);
  396. }
  397. else /* OUT endpoint */
  398. {
  399. /* Multi packet transfer*/
  400. if (ep->xfer_len > ep->maxpacket)
  401. {
  402. len = ep->maxpacket;
  403. ep->xfer_len -= len;
  404. }
  405. else
  406. {
  407. len = ep->xfer_len;
  408. ep->xfer_len = 0U;
  409. }
  410. /* configure and validate Rx endpoint */
  411. if (ep->doublebuffer == 0U)
  412. {
  413. /*Set RX buffer count*/
  414. PCD_SET_EP_RX_CNT(USBx, ep->num, len);
  415. }
  416. else
  417. {
  418. /*Set the Double buffer counter*/
  419. PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, len);
  420. }
  421. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
  422. }
  423. return HAL_OK;
  424. }
  425. /**
  426. * @brief USB_WritePacket : Writes a packet into the Tx FIFO associated
  427. * with the EP/channel
  428. * @param USBx : Selected device
  429. * @param src : pointer to source buffer
  430. * @param ch_ep_num : endpoint or host channel number
  431. * @param len : Number of bytes to write
  432. * @retval HAL status
  433. */
  434. HAL_StatusTypeDef USB_WritePacket(USB_TypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len)
  435. {
  436. /* Prevent unused argument(s) compilation warning */
  437. UNUSED(USBx);
  438. UNUSED(src);
  439. UNUSED(ch_ep_num);
  440. UNUSED(len);
  441. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  442. only by USB OTG FS peripheral.
  443. - This function is added to ensure compatibility across platforms.
  444. */
  445. return HAL_OK;
  446. }
  447. /**
  448. * @brief USB_ReadPacket : read a packet from the Tx FIFO associated
  449. * with the EP/channel
  450. * @param USBx : Selected device
  451. * @param dest : destination pointer
  452. * @param len : Number of bytes to read
  453. * @retval pointer to destination buffer
  454. */
  455. void *USB_ReadPacket(USB_TypeDef *USBx, uint8_t *dest, uint16_t len)
  456. {
  457. /* Prevent unused argument(s) compilation warning */
  458. UNUSED(USBx);
  459. UNUSED(dest);
  460. UNUSED(len);
  461. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  462. only by USB OTG FS peripheral.
  463. - This function is added to ensure compatibility across platforms.
  464. */
  465. return ((void *)NULL);
  466. }
  467. /**
  468. * @brief USB_EPSetStall : set a stall condition over an EP
  469. * @param USBx : Selected device
  470. * @param ep: pointer to endpoint structure
  471. * @retval HAL status
  472. */
  473. HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep)
  474. {
  475. if (ep->is_in != 0U)
  476. {
  477. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_STALL);
  478. }
  479. else
  480. {
  481. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_STALL);
  482. }
  483. return HAL_OK;
  484. }
  485. /**
  486. * @brief USB_EPClearStall : Clear a stall condition over an EP
  487. * @param USBx : Selected device
  488. * @param ep: pointer to endpoint structure
  489. * @retval HAL status
  490. */
  491. HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep)
  492. {
  493. if (ep->doublebuffer == 0U)
  494. {
  495. if (ep->is_in != 0U)
  496. {
  497. PCD_CLEAR_TX_DTOG(USBx, ep->num);
  498. if (ep->type != EP_TYPE_ISOC)
  499. {
  500. /* Configure NAK status for the Endpoint */
  501. PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
  502. }
  503. }
  504. else
  505. {
  506. PCD_CLEAR_RX_DTOG(USBx, ep->num);
  507. /* Configure VALID status for the Endpoint*/
  508. PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
  509. }
  510. }
  511. return HAL_OK;
  512. }
  513. /**
  514. * @brief USB_StopDevice : Stop the usb device mode
  515. * @param USBx : Selected device
  516. * @retval HAL status
  517. */
  518. HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx)
  519. {
  520. /* disable all interrupts and force USB reset */
  521. USBx->CNTR = USB_CNTR_FRES;
  522. /* clear interrupt status register */
  523. USBx->ISTR = 0;
  524. /* switch-off device */
  525. USBx->CNTR = (USB_CNTR_FRES | USB_CNTR_PDWN);
  526. return HAL_OK;
  527. }
  528. /**
  529. * @brief USB_SetDevAddress : Stop the usb device mode
  530. * @param USBx : Selected device
  531. * @param address : new device address to be assigned
  532. * This parameter can be a value from 0 to 255
  533. * @retval HAL status
  534. */
  535. HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address)
  536. {
  537. if (address == 0U)
  538. {
  539. /* set device address and enable function */
  540. USBx->DADDR = USB_DADDR_EF;
  541. }
  542. return HAL_OK;
  543. }
  544. /**
  545. * @brief USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down
  546. * @param USBx : Selected device
  547. * @retval HAL status
  548. */
  549. HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx)
  550. {
  551. /* Prevent unused argument(s) compilation warning */
  552. UNUSED(USBx);
  553. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  554. only by USB OTG FS peripheral.
  555. - This function is added to ensure compatibility across platforms.
  556. */
  557. return HAL_OK;
  558. }
  559. /**
  560. * @brief USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down
  561. * @param USBx : Selected device
  562. * @retval HAL status
  563. */
  564. HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx)
  565. {
  566. /* Prevent unused argument(s) compilation warning */
  567. UNUSED(USBx);
  568. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  569. only by USB OTG FS peripheral.
  570. - This function is added to ensure compatibility across platforms.
  571. */
  572. return HAL_OK;
  573. }
  574. /**
  575. * @brief USB_ReadInterrupts: return the global USB interrupt status
  576. * @param USBx : Selected device
  577. * @retval HAL status
  578. */
  579. uint32_t USB_ReadInterrupts(USB_TypeDef *USBx)
  580. {
  581. uint32_t tmpreg;
  582. tmpreg = USBx->ISTR;
  583. return tmpreg;
  584. }
  585. /**
  586. * @brief USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status
  587. * @param USBx : Selected device
  588. * @retval HAL status
  589. */
  590. uint32_t USB_ReadDevAllOutEpInterrupt(USB_TypeDef *USBx)
  591. {
  592. /* Prevent unused argument(s) compilation warning */
  593. UNUSED(USBx);
  594. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  595. only by USB OTG FS peripheral.
  596. - This function is added to ensure compatibility across platforms.
  597. */
  598. return (0);
  599. }
  600. /**
  601. * @brief USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status
  602. * @param USBx : Selected device
  603. * @retval HAL status
  604. */
  605. uint32_t USB_ReadDevAllInEpInterrupt(USB_TypeDef *USBx)
  606. {
  607. /* Prevent unused argument(s) compilation warning */
  608. UNUSED(USBx);
  609. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  610. only by USB OTG FS peripheral.
  611. - This function is added to ensure compatibility across platforms.
  612. */
  613. return (0);
  614. }
  615. /**
  616. * @brief Returns Device OUT EP Interrupt register
  617. * @param USBx : Selected device
  618. * @param epnum : endpoint number
  619. * This parameter can be a value from 0 to 15
  620. * @retval Device OUT EP Interrupt register
  621. */
  622. uint32_t USB_ReadDevOutEPInterrupt(USB_TypeDef *USBx, uint8_t epnum)
  623. {
  624. /* Prevent unused argument(s) compilation warning */
  625. UNUSED(USBx);
  626. UNUSED(epnum);
  627. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  628. only by USB OTG FS peripheral.
  629. - This function is added to ensure compatibility across platforms.
  630. */
  631. return (0);
  632. }
  633. /**
  634. * @brief Returns Device IN EP Interrupt register
  635. * @param USBx : Selected device
  636. * @param epnum : endpoint number
  637. * This parameter can be a value from 0 to 15
  638. * @retval Device IN EP Interrupt register
  639. */
  640. uint32_t USB_ReadDevInEPInterrupt(USB_TypeDef *USBx, uint8_t epnum)
  641. {
  642. /* Prevent unused argument(s) compilation warning */
  643. UNUSED(USBx);
  644. UNUSED(epnum);
  645. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  646. only by USB OTG FS peripheral.
  647. - This function is added to ensure compatibility across platforms.
  648. */
  649. return (0);
  650. }
  651. /**
  652. * @brief USB_ClearInterrupts: clear a USB interrupt
  653. * @param USBx Selected device
  654. * @param interrupt interrupt flag
  655. * @retval None
  656. */
  657. void USB_ClearInterrupts(USB_TypeDef *USBx, uint32_t interrupt)
  658. {
  659. /* Prevent unused argument(s) compilation warning */
  660. UNUSED(USBx);
  661. UNUSED(interrupt);
  662. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  663. only by USB OTG FS peripheral.
  664. - This function is added to ensure compatibility across platforms.
  665. */
  666. }
  667. /**
  668. * @brief Prepare the EP0 to start the first control setup
  669. * @param USBx Selected device
  670. * @param psetup pointer to setup packet
  671. * @retval HAL status
  672. */
  673. HAL_StatusTypeDef USB_EP0_OutStart(USB_TypeDef *USBx, uint8_t *psetup)
  674. {
  675. /* Prevent unused argument(s) compilation warning */
  676. UNUSED(USBx);
  677. UNUSED(psetup);
  678. /* NOTE : - This function is not required by USB Device FS peripheral, it is used
  679. only by USB OTG FS peripheral.
  680. - This function is added to ensure compatibility across platforms.
  681. */
  682. return HAL_OK;
  683. }
  684. /**
  685. * @brief USB_ActivateRemoteWakeup : active remote wakeup signalling
  686. * @param USBx Selected device
  687. * @retval HAL status
  688. */
  689. HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx)
  690. {
  691. USBx->CNTR |= USB_CNTR_RESUME;
  692. return HAL_OK;
  693. }
  694. /**
  695. * @brief USB_DeActivateRemoteWakeup : de-active remote wakeup signalling
  696. * @param USBx Selected device
  697. * @retval HAL status
  698. */
  699. HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx)
  700. {
  701. USBx->CNTR &= ~(USB_CNTR_RESUME);
  702. return HAL_OK;
  703. }
  704. /**
  705. * @brief Copy a buffer from user memory area to packet memory area (PMA)
  706. * @param USBx USB peripheral instance register address.
  707. * @param pbUsrBuf pointer to user memory area.
  708. * @param wPMABufAddr address into PMA.
  709. * @param wNBytes: no. of bytes to be copied.
  710. * @retval None
  711. */
  712. void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
  713. {
  714. uint32_t n = ((uint32_t)wNBytes + 1U) >> 1;
  715. uint32_t BaseAddr = (uint32_t)USBx;
  716. uint32_t i, temp1, temp2;
  717. uint16_t *pdwVal;
  718. uint8_t *pBuf = pbUsrBuf;
  719. pdwVal = (uint16_t *)(BaseAddr + 0x400U + ((uint32_t)wPMABufAddr * PMA_ACCESS));
  720. for (i = n; i != 0U; i--)
  721. {
  722. temp1 = (uint16_t) * pBuf;
  723. pBuf++;
  724. temp2 = temp1 | ((uint16_t)((uint16_t) * pBuf << 8));
  725. *pdwVal = (uint16_t)temp2;
  726. pdwVal++;
  727. #if PMA_ACCESS > 1U
  728. pdwVal++;
  729. #endif
  730. pBuf++;
  731. }
  732. }
  733. /**
  734. * @brief Copy a buffer from user memory area to packet memory area (PMA)
  735. * @param USBx: USB peripheral instance register address.
  736. * @param pbUsrBuf pointer to user memory area.
  737. * @param wPMABufAddr address into PMA.
  738. * @param wNBytes: no. of bytes to be copied.
  739. * @retval None
  740. */
  741. void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
  742. {
  743. uint32_t n = (uint32_t)wNBytes >> 1;
  744. uint32_t BaseAddr = (uint32_t)USBx;
  745. uint32_t i, temp;
  746. uint16_t *pdwVal;
  747. uint8_t *pBuf = pbUsrBuf;
  748. pdwVal = (uint16_t *)(BaseAddr + 0x400U + ((uint32_t)wPMABufAddr * PMA_ACCESS));
  749. for (i = n; i != 0U; i--)
  750. {
  751. temp = *pdwVal;
  752. pdwVal++;
  753. *pBuf = (uint8_t)((temp >> 0) & 0xFFU);
  754. pBuf++;
  755. *pBuf = (uint8_t)((temp >> 8) & 0xFFU);
  756. pBuf++;
  757. #if PMA_ACCESS > 1U
  758. pdwVal++;
  759. #endif
  760. }
  761. if ((wNBytes % 2U) != 0U)
  762. {
  763. temp = *pdwVal;
  764. *pBuf = (uint8_t)((temp >> 0) & 0xFFU);
  765. }
  766. }
  767. /**
  768. * @}
  769. */
  770. /**
  771. * @}
  772. */
  773. #endif /* defined (USB) */
  774. #endif /* defined (HAL_PCD_MODULE_ENABLED) || defined (HAL_HCD_MODULE_ENABLED) */
  775. /**
  776. * @}
  777. */
  778. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/