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