2 ******************************************************************************
3 * @file stm32f1xx_hal_pcd_ex.c
4 * @author MCD Application Team
6 * @date 15-December-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 * + Extended features functions: Update FIFO configuration,
11 * PMA configuration for EPs
13 ******************************************************************************
16 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
18 * Redistribution and use in source and binary forms, with or without modification,
19 * are permitted provided that the following conditions are met:
20 * 1. Redistributions of source code must retain the above copyright notice,
21 * this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright notice,
23 * this list of conditions and the following disclaimer in the documentation
24 * and/or other materials provided with the distribution.
25 * 3. Neither the name of STMicroelectronics nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ******************************************************************************
43 /* Includes ------------------------------------------------------------------*/
44 #include "stm32f1xx_hal.h"
46 /** @addtogroup STM32F1xx_HAL_Driver
50 #ifdef HAL_PCD_MODULE_ENABLED
52 #if defined(STM32F102x6) || defined(STM32F102xB) || \
53 defined(STM32F103x6) || defined(STM32F103xB) || \
54 defined(STM32F103xE) || defined(STM32F103xG) || \
55 defined(STM32F105xC) || defined(STM32F107xC)
58 /** @defgroup PCDEx PCDEx
59 * @brief PCD Extended HAL module driver
64 /* Private types -------------------------------------------------------------*/
65 /* Private variables ---------------------------------------------------------*/
66 /* Private constants ---------------------------------------------------------*/
67 /* Private macros ------------------------------------------------------------*/
68 /* Private functions ---------------------------------------------------------*/
69 /* Exported functions --------------------------------------------------------*/
70 /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
74 /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
75 * @brief PCDEx control functions
78 ===============================================================================
79 ##### Extended Peripheral Control functions #####
80 ===============================================================================
81 [..] This section provides functions allowing to:
82 (+) Update FIFO (USB_OTG_FS)
83 (+) Update PMA configuration (USB)
89 #if defined (USB_OTG_FS)
92 * @param hpcd: PCD handle
93 * @param fifo: The number of Tx fifo
94 * @param size: Fifo size
97 HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
100 uint32_t Tx_Offset = 0;
102 /* TXn min size = 16 words. (n : Transmit FIFO index)
103 When a TxFIFO is not used, the Configuration should be as follows:
104 case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
105 --> Txm can use the space allocated for Txn.
106 case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
107 --> Txn should be configured with the minimum space of 16 words
108 The FIFO is used optimally when used TxFIFOs are allocated in the top
109 of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
110 When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
112 Tx_Offset = hpcd->Instance->GRXFSIZ;
116 hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (size << 16) | Tx_Offset;
120 Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
121 for (index = 0; index < (fifo - 1); index++)
123 Tx_Offset += (hpcd->Instance->DIEPTXF[index] >> 16);
126 /* Multiply Tx_Size by 2 to get higher performance */
127 hpcd->Instance->DIEPTXF[fifo - 1] = (size << 16) | Tx_Offset;
136 * @param hpcd: PCD handle
137 * @param size: Size of Rx fifo
140 HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
142 hpcd->Instance->GRXFSIZ = size;
145 #endif /* USB_OTG_FS */
149 * @brief Configure PMA for EP
150 * @param hpcd : Device instance
151 * @param ep_addr: endpoint address
152 * @param ep_kind: endpoint Kind
153 * USB_SNG_BUF: Single Buffer used
154 * USB_DBL_BUF: Double Buffer used
155 * @param pmaadress: EP address in The PMA: In case of single buffer endpoint
156 * this parameter is 16-bit value providing the address
157 * in PMA allocated to endpoint.
158 * In case of double buffer endpoint this parameter
159 * is a 32-bit value providing the endpoint buffer 0 address
160 * in the LSB part of 32-bit value and endpoint buffer 1 address
161 * in the MSB part of 32-bit value.
165 HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd,
171 PCD_EPTypeDef *ep = NULL;
173 /* initialize ep structure*/
174 if ((0x80 & ep_addr) == 0x80)
176 ep = &hpcd->IN_ep[ep_addr & 0x7F];
180 ep = &hpcd->OUT_ep[ep_addr];
183 /* Here we check if the endpoint is single or double Buffer*/
184 if (ep_kind == PCD_SNG_BUF)
187 ep->doublebuffer = 0;
189 ep->pmaadress = (uint16_t)pmaadress;
193 /*Double Buffer Endpoint*/
194 ep->doublebuffer = 1;
195 /*Configure the PMA*/
196 ep->pmaaddr0 = pmaadress & 0xFFFF;
197 ep->pmaaddr1 = (pmaadress & 0xFFFF0000) >> 16;
207 /** @defgroup PCDEx_Exported_Functions_Group2 Peripheral State functions
208 * @brief Manage device connection state
212 * @brief Software Device Connection,
213 * this function is not required by USB OTG FS peripheral, it is used
214 * only by USB Device FS peripheral.
215 * @param hpcd: PCD handle
216 * @param state: connection state (0 : disconnected / 1: connected)
219 __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
221 /* NOTE : This function Should not be modified, when the callback is needed,
222 the HAL_PCDEx_SetConnectionState could be implemented in the user file
237 #endif /* STM32F102x6 || STM32F102xB || */
238 /* STM32F103x6 || STM32F103xB || */
239 /* STM32F103xE || STM32F103xG || */
240 /* STM32F105xC || STM32F107xC */
242 #endif /* HAL_PCD_MODULE_ENABLED */
249 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/