You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

155 lines
5.4 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_pcd_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended PCD HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the USB Peripheral Controller:
  8. * + Configuration of the PMA for EP
  9. *
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; COPYRIGHT(c) 2016 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 "stm32f0xx_hal.h"
  41. #ifdef HAL_PCD_MODULE_ENABLED
  42. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)|| defined(STM32F070x6)
  43. /** @addtogroup STM32F0xx_HAL_Driver
  44. * @{
  45. */
  46. /** @defgroup PCDEx PCDEx
  47. * @brief PCD Extended HAL module driver
  48. * @{
  49. */
  50. /* Private typedef -----------------------------------------------------------*/
  51. /* Private define ------------------------------------------------------------*/
  52. /* Private macro -------------------------------------------------------------*/
  53. /* Private variables ---------------------------------------------------------*/
  54. /* Private function prototypes -----------------------------------------------*/
  55. /* Exported functions ---------------------------------------------------------*/
  56. /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
  57. * @{
  58. */
  59. /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
  60. * @brief PCDEx control functions
  61. *
  62. @verbatim
  63. ===============================================================================
  64. ##### Extended Peripheral Control functions #####
  65. ===============================================================================
  66. [..] This section provides functions allowing to:
  67. (+) Update PMA configuration
  68. @endverbatim
  69. * @{
  70. */
  71. /**
  72. * @brief Configure PMA for EP
  73. * @param hpcd PCD handle
  74. * @param ep_addr endpoint address
  75. * @param ep_kind endpoint Kind
  76. * @arg USB_SNG_BUF: Single Buffer used
  77. * @arg USB_DBL_BUF: Double Buffer used
  78. * @param pmaadress EP address in The PMA: In case of single buffer endpoint
  79. * this parameter is 16-bit value providing the address
  80. * in PMA allocated to endpoint.
  81. * In case of double buffer endpoint this parameter
  82. * is a 32-bit value providing the endpoint buffer 0 address
  83. * in the LSB part of 32-bit value and endpoint buffer 1 address
  84. * in the MSB part of 32-bit value.
  85. * @retval : status
  86. */
  87. HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd,
  88. uint16_t ep_addr,
  89. uint16_t ep_kind,
  90. uint32_t pmaadress)
  91. {
  92. PCD_EPTypeDef *ep;
  93. /* initialize ep structure*/
  94. if ((0x80U & ep_addr) == 0x80U)
  95. {
  96. ep = &hpcd->IN_ep[ep_addr & 0x7FU];
  97. }
  98. else
  99. {
  100. ep = &hpcd->OUT_ep[ep_addr];
  101. }
  102. /* Here we check if the endpoint is single or double Buffer*/
  103. if (ep_kind == PCD_SNG_BUF)
  104. {
  105. /*Single Buffer*/
  106. ep->doublebuffer = 0U;
  107. /*Configure the PMA*/
  108. ep->pmaadress = (uint16_t)pmaadress;
  109. }
  110. else /*USB_DBL_BUF*/
  111. {
  112. /*Double Buffer Endpoint*/
  113. ep->doublebuffer = 1U;
  114. /*Configure the PMA*/
  115. ep->pmaaddr0 = pmaadress & 0xFFFFU;
  116. ep->pmaaddr1 = (pmaadress & 0xFFFF0000U) >> 16U;
  117. }
  118. return HAL_OK;
  119. }
  120. /**
  121. * @}
  122. */
  123. /**
  124. * @}
  125. */
  126. /**
  127. * @}
  128. */
  129. /**
  130. * @}
  131. */
  132. #endif /* STM32F042x6 || STM32F072xB || STM32F078xx || STM32F070xB || STM32F070x6 */
  133. #endif /* HAL_PCD_MODULE_ENABLED */
  134. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/