stm32f1xx_hal_pcd_ex.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_pcd_ex.c
  4. * @author MCD Application Team
  5. * @brief PCD Extended HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the USB Peripheral Controller:
  8. * + Extended features functions
  9. *
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  14. * All rights reserved.</center></h2>
  15. *
  16. * This software component is licensed by ST under BSD 3-Clause license,
  17. * the "License"; You may not use this file except in compliance with the
  18. * License. You may obtain a copy of the License at:
  19. * opensource.org/licenses/BSD-3-Clause
  20. *
  21. ******************************************************************************
  22. */
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32f1xx_hal.h"
  25. /** @addtogroup STM32F1xx_HAL_Driver
  26. * @{
  27. */
  28. /** @defgroup PCDEx PCDEx
  29. * @brief PCD Extended HAL module driver
  30. * @{
  31. */
  32. #ifdef HAL_PCD_MODULE_ENABLED
  33. #if defined (USB) || defined (USB_OTG_FS)
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /* Private functions ---------------------------------------------------------*/
  39. /* Exported functions --------------------------------------------------------*/
  40. /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
  41. * @{
  42. */
  43. /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
  44. * @brief PCDEx control functions
  45. *
  46. @verbatim
  47. ===============================================================================
  48. ##### Extended features functions #####
  49. ===============================================================================
  50. [..] This section provides functions allowing to:
  51. (+) Update FIFO configuration
  52. @endverbatim
  53. * @{
  54. */
  55. #if defined (USB_OTG_FS)
  56. /**
  57. * @brief Set Tx FIFO
  58. * @param hpcd PCD handle
  59. * @param fifo The number of Tx fifo
  60. * @param size Fifo size
  61. * @retval HAL status
  62. */
  63. HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
  64. {
  65. uint8_t i;
  66. uint32_t Tx_Offset;
  67. /* TXn min size = 16 words. (n : Transmit FIFO index)
  68. When a TxFIFO is not used, the Configuration should be as follows:
  69. case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
  70. --> Txm can use the space allocated for Txn.
  71. case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
  72. --> Txn should be configured with the minimum space of 16 words
  73. The FIFO is used optimally when used TxFIFOs are allocated in the top
  74. of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
  75. When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
  76. Tx_Offset = hpcd->Instance->GRXFSIZ;
  77. if (fifo == 0U)
  78. {
  79. hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset;
  80. }
  81. else
  82. {
  83. Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
  84. for (i = 0U; i < (fifo - 1U); i++)
  85. {
  86. Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
  87. }
  88. /* Multiply Tx_Size by 2 to get higher performance */
  89. hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset;
  90. }
  91. return HAL_OK;
  92. }
  93. /**
  94. * @brief Set Rx FIFO
  95. * @param hpcd PCD handle
  96. * @param size Size of Rx fifo
  97. * @retval HAL status
  98. */
  99. HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
  100. {
  101. hpcd->Instance->GRXFSIZ = size;
  102. return HAL_OK;
  103. }
  104. #endif /* defined (USB_OTG_FS) */
  105. #if defined (USB)
  106. /**
  107. * @brief Configure PMA for EP
  108. * @param hpcd Device instance
  109. * @param ep_addr endpoint address
  110. * @param ep_kind endpoint Kind
  111. * USB_SNG_BUF: Single Buffer used
  112. * USB_DBL_BUF: Double Buffer used
  113. * @param pmaadress: EP address in The PMA: In case of single buffer endpoint
  114. * this parameter is 16-bit value providing the address
  115. * in PMA allocated to endpoint.
  116. * In case of double buffer endpoint this parameter
  117. * is a 32-bit value providing the endpoint buffer 0 address
  118. * in the LSB part of 32-bit value and endpoint buffer 1 address
  119. * in the MSB part of 32-bit value.
  120. * @retval HAL status
  121. */
  122. HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd,
  123. uint16_t ep_addr,
  124. uint16_t ep_kind,
  125. uint32_t pmaadress)
  126. {
  127. PCD_EPTypeDef *ep;
  128. /* initialize ep structure*/
  129. if ((0x80U & ep_addr) == 0x80U)
  130. {
  131. ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
  132. }
  133. else
  134. {
  135. ep = &hpcd->OUT_ep[ep_addr];
  136. }
  137. /* Here we check if the endpoint is single or double Buffer*/
  138. if (ep_kind == PCD_SNG_BUF)
  139. {
  140. /* Single Buffer */
  141. ep->doublebuffer = 0U;
  142. /* Configure the PMA */
  143. ep->pmaadress = (uint16_t)pmaadress;
  144. }
  145. else /* USB_DBL_BUF */
  146. {
  147. /* Double Buffer Endpoint */
  148. ep->doublebuffer = 1U;
  149. /* Configure the PMA */
  150. ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU);
  151. ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16);
  152. }
  153. return HAL_OK;
  154. }
  155. /**
  156. * @brief Software Device Connection,
  157. * this function is not required by USB OTG FS peripheral, it is used
  158. * only by USB Device FS peripheral.
  159. * @param hpcd: PCD handle
  160. * @param state: connection state (0 : disconnected / 1: connected)
  161. * @retval None
  162. */
  163. __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
  164. {
  165. /* Prevent unused argument(s) compilation warning */
  166. UNUSED(hpcd);
  167. UNUSED(state);
  168. /* NOTE : This function Should not be modified, when the callback is needed,
  169. the HAL_PCDEx_SetConnectionState could be implemented in the user file
  170. */
  171. }
  172. #endif /* defined (USB) */
  173. /**
  174. * @brief Send LPM message to user layer callback.
  175. * @param hpcd PCD handle
  176. * @param msg LPM message
  177. * @retval HAL status
  178. */
  179. __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
  180. {
  181. /* Prevent unused argument(s) compilation warning */
  182. UNUSED(hpcd);
  183. UNUSED(msg);
  184. /* NOTE : This function should not be modified, when the callback is needed,
  185. the HAL_PCDEx_LPM_Callback could be implemented in the user file
  186. */
  187. }
  188. /**
  189. * @brief Send BatteryCharging message to user layer callback.
  190. * @param hpcd PCD handle
  191. * @param msg LPM message
  192. * @retval HAL status
  193. */
  194. __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
  195. {
  196. /* Prevent unused argument(s) compilation warning */
  197. UNUSED(hpcd);
  198. UNUSED(msg);
  199. /* NOTE : This function should not be modified, when the callback is needed,
  200. the HAL_PCDEx_BCD_Callback could be implemented in the user file
  201. */
  202. }
  203. /**
  204. * @}
  205. */
  206. /**
  207. * @}
  208. */
  209. #endif /* defined (USB) || defined (USB_OTG_FS) */
  210. #endif /* HAL_PCD_MODULE_ENABLED */
  211. /**
  212. * @}
  213. */
  214. /**
  215. * @}
  216. */
  217. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/