stm32f3xx_hal_pcd_ex.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_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) 2016 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 "stm32f3xx_hal.h"
  24. /** @addtogroup STM32F3xx_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)
  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. /**
  55. * @brief Configure PMA for EP
  56. * @param hpcd Device instance
  57. * @param ep_addr endpoint address
  58. * @param ep_kind endpoint Kind
  59. * USB_SNG_BUF: Single Buffer used
  60. * USB_DBL_BUF: Double Buffer used
  61. * @param pmaadress: EP address in The PMA: In case of single buffer endpoint
  62. * this parameter is 16-bit value providing the address
  63. * in PMA allocated to endpoint.
  64. * In case of double buffer endpoint this parameter
  65. * is a 32-bit value providing the endpoint buffer 0 address
  66. * in the LSB part of 32-bit value and endpoint buffer 1 address
  67. * in the MSB part of 32-bit value.
  68. * @retval HAL status
  69. */
  70. HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr,
  71. uint16_t ep_kind, uint32_t pmaadress)
  72. {
  73. PCD_EPTypeDef *ep;
  74. /* initialize ep structure*/
  75. if ((0x80U & ep_addr) == 0x80U)
  76. {
  77. ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
  78. }
  79. else
  80. {
  81. ep = &hpcd->OUT_ep[ep_addr];
  82. }
  83. /* Here we check if the endpoint is single or double Buffer*/
  84. if (ep_kind == PCD_SNG_BUF)
  85. {
  86. /* Single Buffer */
  87. ep->doublebuffer = 0U;
  88. /* Configure the PMA */
  89. ep->pmaadress = (uint16_t)pmaadress;
  90. }
  91. #if (USE_USB_DOUBLE_BUFFER == 1U)
  92. else /* USB_DBL_BUF */
  93. {
  94. /* Double Buffer Endpoint */
  95. ep->doublebuffer = 1U;
  96. /* Configure the PMA */
  97. ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU);
  98. ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16);
  99. }
  100. #endif /* (USE_USB_DOUBLE_BUFFER == 1U) */
  101. return HAL_OK;
  102. }
  103. /**
  104. * @brief Software Device Connection,
  105. * this function is not required by USB OTG FS peripheral, it is used
  106. * only by USB Device FS peripheral.
  107. * @param hpcd PCD handle
  108. * @param state connection state (0 : disconnected / 1: connected)
  109. * @retval None
  110. */
  111. __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
  112. {
  113. /* Prevent unused argument(s) compilation warning */
  114. UNUSED(hpcd);
  115. UNUSED(state);
  116. /* NOTE : This function Should not be modified, when the callback is needed,
  117. the HAL_PCDEx_SetConnectionState could be implemented in the user file
  118. */
  119. }
  120. /**
  121. * @brief Send LPM message to user layer callback.
  122. * @param hpcd PCD handle
  123. * @param msg LPM message
  124. * @retval HAL status
  125. */
  126. __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
  127. {
  128. /* Prevent unused argument(s) compilation warning */
  129. UNUSED(hpcd);
  130. UNUSED(msg);
  131. /* NOTE : This function should not be modified, when the callback is needed,
  132. the HAL_PCDEx_LPM_Callback could be implemented in the user file
  133. */
  134. }
  135. /**
  136. * @brief Send BatteryCharging message to user layer callback.
  137. * @param hpcd PCD handle
  138. * @param msg LPM message
  139. * @retval HAL status
  140. */
  141. __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
  142. {
  143. /* Prevent unused argument(s) compilation warning */
  144. UNUSED(hpcd);
  145. UNUSED(msg);
  146. /* NOTE : This function should not be modified, when the callback is needed,
  147. the HAL_PCDEx_BCD_Callback could be implemented in the user file
  148. */
  149. }
  150. /**
  151. * @}
  152. */
  153. /**
  154. * @}
  155. */
  156. #endif /* defined (USB) */
  157. #endif /* HAL_PCD_MODULE_ENABLED */
  158. /**
  159. * @}
  160. */
  161. /**
  162. * @}
  163. */