stm32f7xx_hal_pcd_ex.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_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) 2017 STMicroelectronics</center></h2>
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "stm32f7xx_hal.h"
  41. /** @addtogroup STM32F7xx_HAL_Driver
  42. * @{
  43. */
  44. /** @defgroup PCDEx PCDEx
  45. * @brief PCD Extended HAL module driver
  46. * @{
  47. */
  48. #ifdef HAL_PCD_MODULE_ENABLED
  49. /* Private types -------------------------------------------------------------*/
  50. /* Private variables ---------------------------------------------------------*/
  51. /* Private constants ---------------------------------------------------------*/
  52. /* Private macros ------------------------------------------------------------*/
  53. /* Private functions ---------------------------------------------------------*/
  54. /* Exported functions --------------------------------------------------------*/
  55. /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
  56. * @{
  57. */
  58. /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
  59. * @brief PCDEx control functions
  60. *
  61. @verbatim
  62. ===============================================================================
  63. ##### Extended features functions #####
  64. ===============================================================================
  65. [..] This section provides functions allowing to:
  66. (+) Update FIFO configuration
  67. @endverbatim
  68. * @{
  69. */
  70. #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
  71. /**
  72. * @brief Set Tx FIFO
  73. * @param hpcd PCD handle
  74. * @param fifo The number of Tx fifo
  75. * @param size Fifo size
  76. * @retval HAL status
  77. */
  78. HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
  79. {
  80. uint8_t i;
  81. uint32_t Tx_Offset;
  82. /* TXn min size = 16 words. (n : Transmit FIFO index)
  83. When a TxFIFO is not used, the Configuration should be as follows:
  84. case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
  85. --> Txm can use the space allocated for Txn.
  86. case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
  87. --> Txn should be configured with the minimum space of 16 words
  88. The FIFO is used optimally when used TxFIFOs are allocated in the top
  89. of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
  90. When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
  91. Tx_Offset = hpcd->Instance->GRXFSIZ;
  92. if(fifo == 0U)
  93. {
  94. hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset;
  95. }
  96. else
  97. {
  98. Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
  99. for (i = 0U; i < (fifo - 1U); i++)
  100. {
  101. Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
  102. }
  103. /* Multiply Tx_Size by 2 to get higher performance */
  104. hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset;
  105. }
  106. return HAL_OK;
  107. }
  108. /**
  109. * @brief Set Rx FIFO
  110. * @param hpcd PCD handle
  111. * @param size Size of Rx fifo
  112. * @retval HAL status
  113. */
  114. HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
  115. {
  116. hpcd->Instance->GRXFSIZ = size;
  117. return HAL_OK;
  118. }
  119. /**
  120. * @brief Activate LPM feature.
  121. * @param hpcd PCD handle
  122. * @retval HAL status
  123. */
  124. HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd)
  125. {
  126. USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
  127. hpcd->lpm_active = 1U;
  128. hpcd->LPM_State = LPM_L0;
  129. USBx->GINTMSK |= USB_OTG_GINTMSK_LPMINTM;
  130. USBx->GLPMCFG |= (USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
  131. return HAL_OK;
  132. }
  133. /**
  134. * @brief Deactivate LPM feature.
  135. * @param hpcd PCD handle
  136. * @retval HAL status
  137. */
  138. HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd)
  139. {
  140. USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
  141. hpcd->lpm_active = 0U;
  142. USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM;
  143. USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
  144. return HAL_OK;
  145. }
  146. #endif /* USB_OTG_FS || USB_OTG_HS */
  147. /**
  148. * @brief Send LPM message to user layer callback.
  149. * @param hpcd PCD handle
  150. * @param msg LPM message
  151. * @retval HAL status
  152. */
  153. __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
  154. {
  155. /* Prevent unused argument(s) compilation warning */
  156. UNUSED(hpcd);
  157. UNUSED(msg);
  158. /* NOTE : This function should not be modified, when the callback is needed,
  159. the HAL_PCDEx_LPM_Callback could be implemented in the user file
  160. */
  161. }
  162. /**
  163. * @brief Send BatteryCharging message to user layer callback.
  164. * @param hpcd PCD handle
  165. * @param msg LPM message
  166. * @retval HAL status
  167. */
  168. __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
  169. {
  170. /* Prevent unused argument(s) compilation warning */
  171. UNUSED(hpcd);
  172. UNUSED(msg);
  173. /* NOTE : This function should not be modified, when the callback is needed,
  174. the HAL_PCDEx_BCD_Callback could be implemented in the user file
  175. */
  176. }
  177. /**
  178. * @}
  179. */
  180. /**
  181. * @}
  182. */
  183. #endif /* HAL_PCD_MODULE_ENABLED */
  184. /**
  185. * @}
  186. */
  187. /**
  188. * @}
  189. */
  190. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/