stm32l1xx_hal_pcd_ex.c 5.0 KB

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