stm32f4xx_hal_pcd_ex.c 6.4 KB

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