stm32f7xx_hal_pcd_ex.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. * Copyright (c) 2017 STMicroelectronics.
  14. * All rights reserved.
  15. *
  16. * This software is licensed under terms that can be found in the LICENSE file
  17. * in the root directory of this software component.
  18. * If no LICENSE file comes with this software, it is provided AS-IS.
  19. *
  20. ******************************************************************************
  21. */
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "stm32f7xx_hal.h"
  24. /** @addtogroup STM32F7xx_HAL_Driver
  25. * @{
  26. */
  27. /** @defgroup PCDEx PCDEx
  28. * @brief PCD Extended HAL module driver
  29. * @{
  30. */
  31. #ifdef HAL_PCD_MODULE_ENABLED
  32. #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /* Private macros ------------------------------------------------------------*/
  37. /* Private functions ---------------------------------------------------------*/
  38. /* Exported functions --------------------------------------------------------*/
  39. /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
  40. * @{
  41. */
  42. /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
  43. * @brief PCDEx control functions
  44. *
  45. @verbatim
  46. ===============================================================================
  47. ##### Extended features functions #####
  48. ===============================================================================
  49. [..] This section provides functions allowing to:
  50. (+) Update FIFO configuration
  51. @endverbatim
  52. * @{
  53. */
  54. #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
  55. /**
  56. * @brief Set Tx FIFO
  57. * @param hpcd PCD handle
  58. * @param fifo The number of Tx fifo
  59. * @param size Fifo size
  60. * @retval HAL status
  61. */
  62. HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
  63. {
  64. uint8_t i;
  65. uint32_t Tx_Offset;
  66. /* TXn min size = 16 words. (n : Transmit FIFO index)
  67. When a TxFIFO is not used, the Configuration should be as follows:
  68. case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
  69. --> Txm can use the space allocated for Txn.
  70. case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
  71. --> Txn should be configured with the minimum space of 16 words
  72. The FIFO is used optimally when used TxFIFOs are allocated in the top
  73. of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
  74. When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
  75. Tx_Offset = hpcd->Instance->GRXFSIZ;
  76. if (fifo == 0U)
  77. {
  78. hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset;
  79. }
  80. else
  81. {
  82. Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
  83. for (i = 0U; i < (fifo - 1U); i++)
  84. {
  85. Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
  86. }
  87. /* Multiply Tx_Size by 2 to get higher performance */
  88. hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset;
  89. }
  90. return HAL_OK;
  91. }
  92. /**
  93. * @brief Set Rx FIFO
  94. * @param hpcd PCD handle
  95. * @param size Size of Rx fifo
  96. * @retval HAL status
  97. */
  98. HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
  99. {
  100. hpcd->Instance->GRXFSIZ = size;
  101. return HAL_OK;
  102. }
  103. /**
  104. * @brief Activate LPM feature.
  105. * @param hpcd PCD handle
  106. * @retval HAL status
  107. */
  108. HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd)
  109. {
  110. USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
  111. hpcd->lpm_active = 1U;
  112. hpcd->LPM_State = LPM_L0;
  113. USBx->GINTMSK |= USB_OTG_GINTMSK_LPMINTM;
  114. USBx->GLPMCFG |= (USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
  115. return HAL_OK;
  116. }
  117. /**
  118. * @brief Deactivate LPM feature.
  119. * @param hpcd PCD handle
  120. * @retval HAL status
  121. */
  122. HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd)
  123. {
  124. USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
  125. hpcd->lpm_active = 0U;
  126. USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM;
  127. USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
  128. return HAL_OK;
  129. }
  130. #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
  131. /**
  132. * @brief Send LPM message to user layer callback.
  133. * @param hpcd PCD handle
  134. * @param msg LPM message
  135. * @retval HAL status
  136. */
  137. __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
  138. {
  139. /* Prevent unused argument(s) compilation warning */
  140. UNUSED(hpcd);
  141. UNUSED(msg);
  142. /* NOTE : This function should not be modified, when the callback is needed,
  143. the HAL_PCDEx_LPM_Callback could be implemented in the user file
  144. */
  145. }
  146. /**
  147. * @brief Send BatteryCharging message to user layer callback.
  148. * @param hpcd PCD handle
  149. * @param msg LPM message
  150. * @retval HAL status
  151. */
  152. __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
  153. {
  154. /* Prevent unused argument(s) compilation warning */
  155. UNUSED(hpcd);
  156. UNUSED(msg);
  157. /* NOTE : This function should not be modified, when the callback is needed,
  158. the HAL_PCDEx_BCD_Callback could be implemented in the user file
  159. */
  160. }
  161. /**
  162. * @}
  163. */
  164. /**
  165. * @}
  166. */
  167. #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
  168. #endif /* HAL_PCD_MODULE_ENABLED */
  169. /**
  170. * @}
  171. */
  172. /**
  173. * @}
  174. */