Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 9 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | ****************************************************************************** |
2 | ****************************************************************************** |
| 3 | * @file stm32f1xx_hal_pcd_ex.c |
3 | * @file stm32f1xx_hal_pcd_ex.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @brief Extended PCD HAL module driver. |
5 | * @brief PCD Extended HAL module driver. |
| 6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
| 7 | * functionalities of the USB Peripheral Controller: |
7 | * functionalities of the USB Peripheral Controller: |
| 8 | * + Extended features functions: Update FIFO configuration, |
8 | * + Extended features functions |
| 9 | * PMA configuration for EPs |
- | |
| 10 | * |
9 | * |
| 11 | ****************************************************************************** |
10 | ****************************************************************************** |
| 12 | * @attention |
11 | * @attention |
| 13 | * |
12 | * |
| 14 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
13 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
| - | 14 | * All rights reserved.</center></h2> |
|
| 15 | * |
15 | * |
| 16 | * Redistribution and use in source and binary forms, with or without modification, |
16 | * This software component is licensed by ST under BSD 3-Clause license, |
| 17 | * are permitted provided that the following conditions are met: |
17 | * the "License"; You may not use this file except in compliance with the |
| 18 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
| 19 | * this list of conditions and the following disclaimer. |
- | |
| 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
| 21 | * this list of conditions and the following disclaimer in the documentation |
- | |
| 22 | * and/or other materials provided with the distribution. |
18 | * License. You may obtain a copy of the License at: |
| 23 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
| 24 | * may be used to endorse or promote products derived from this software |
19 | * opensource.org/licenses/BSD-3-Clause |
| 25 | * without specific prior written permission. |
- | |
| 26 | * |
- | |
| 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
- | |
| 28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
| 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
| 30 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
| 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
| 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
- | |
| 33 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
- | |
| 34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
| 35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
| 36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- | |
| 37 | * |
20 | * |
| 38 | ****************************************************************************** |
21 | ****************************************************************************** |
| 39 | */ |
22 | */ |
| 40 | 23 | ||
| 41 | /* Includes ------------------------------------------------------------------*/ |
24 | /* Includes ------------------------------------------------------------------*/ |
| Line 43... | Line 26... | ||
| 43 | 26 | ||
| 44 | /** @addtogroup STM32F1xx_HAL_Driver |
27 | /** @addtogroup STM32F1xx_HAL_Driver |
| 45 | * @{ |
28 | * @{ |
| 46 | */ |
29 | */ |
| 47 | 30 | ||
| 48 | #ifdef HAL_PCD_MODULE_ENABLED |
- | |
| 49 | - | ||
| 50 | #if defined(STM32F102x6) || defined(STM32F102xB) || \ |
- | |
| 51 | defined(STM32F103x6) || defined(STM32F103xB) || \ |
- | |
| 52 | defined(STM32F103xE) || defined(STM32F103xG) || \ |
- | |
| 53 | defined(STM32F105xC) || defined(STM32F107xC) |
- | |
| 54 | - | ||
| 55 | - | ||
| 56 | /** @defgroup PCDEx PCDEx |
31 | /** @defgroup PCDEx PCDEx |
| 57 | * @brief PCD Extended HAL module driver |
32 | * @brief PCD Extended HAL module driver |
| 58 | * @{ |
33 | * @{ |
| 59 | */ |
34 | */ |
| 60 | 35 | ||
| - | 36 | #ifdef HAL_PCD_MODULE_ENABLED |
|
| 61 | 37 | ||
| - | 38 | #if defined (USB) || defined (USB_OTG_FS) |
|
| 62 | /* Private types -------------------------------------------------------------*/ |
39 | /* Private types -------------------------------------------------------------*/ |
| 63 | /* Private variables ---------------------------------------------------------*/ |
40 | /* Private variables ---------------------------------------------------------*/ |
| 64 | /* Private constants ---------------------------------------------------------*/ |
41 | /* Private constants ---------------------------------------------------------*/ |
| 65 | /* Private macros ------------------------------------------------------------*/ |
42 | /* Private macros ------------------------------------------------------------*/ |
| 66 | /* Private functions ---------------------------------------------------------*/ |
43 | /* Private functions ---------------------------------------------------------*/ |
| 67 | /* Exported functions --------------------------------------------------------*/ |
44 | /* Exported functions --------------------------------------------------------*/ |
| - | 45 | ||
| 68 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions |
46 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions |
| 69 | * @{ |
47 | * @{ |
| 70 | */ |
48 | */ |
| 71 | 49 | ||
| 72 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions |
50 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions |
| 73 | * @brief PCDEx control functions |
51 | * @brief PCDEx control functions |
| 74 | * |
52 | * |
| 75 | @verbatim |
53 | @verbatim |
| 76 | =============================================================================== |
54 | =============================================================================== |
| 77 | ##### Extended Peripheral Control functions ##### |
55 | ##### Extended features functions ##### |
| 78 | =============================================================================== |
56 | =============================================================================== |
| 79 | [..] This section provides functions allowing to: |
57 | [..] This section provides functions allowing to: |
| 80 | (+) Update FIFO (USB_OTG_FS) |
- | |
| 81 | (+) Update PMA configuration (USB) |
58 | (+) Update FIFO configuration |
| 82 | 59 | ||
| 83 | @endverbatim |
60 | @endverbatim |
| 84 | * @{ |
61 | * @{ |
| 85 | */ |
62 | */ |
| 86 | - | ||
| 87 | #if defined (USB_OTG_FS) |
63 | #if defined (USB_OTG_FS) |
| 88 | /** |
64 | /** |
| 89 | * @brief Set Tx FIFO |
65 | * @brief Set Tx FIFO |
| 90 | * @param hpcd: PCD handle |
66 | * @param hpcd PCD handle |
| 91 | * @param fifo: The number of Tx fifo |
67 | * @param fifo The number of Tx fifo |
| 92 | * @param size: Fifo size |
68 | * @param size Fifo size |
| 93 | * @retval HAL status |
69 | * @retval HAL status |
| 94 | */ |
70 | */ |
| 95 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) |
71 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) |
| 96 | { |
72 | { |
| 97 | uint8_t index = 0; |
73 | uint8_t i; |
| 98 | uint32_t Tx_Offset = 0U; |
74 | uint32_t Tx_Offset; |
| 99 | 75 | ||
| 100 | /* TXn min size = 16 words. (n : Transmit FIFO index) |
76 | /* TXn min size = 16 words. (n : Transmit FIFO index) |
| 101 | When a TxFIFO is not used, the Configuration should be as follows: |
77 | When a TxFIFO is not used, the Configuration should be as follows: |
| 102 | case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) |
78 | case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) |
| 103 | --> Txm can use the space allocated for Txn. |
79 | --> Txm can use the space allocated for Txn. |
| 104 | case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) |
80 | case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) |
| 105 | --> Txn should be configured with the minimum space of 16 words |
81 | --> Txn should be configured with the minimum space of 16 words |
| 106 | The FIFO is used optimally when used TxFIFOs are allocated in the top |
82 | The FIFO is used optimally when used TxFIFOs are allocated in the top |
| 107 | of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. |
83 | of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. |
| 108 | When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */ |
84 | When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */ |
| 109 | 85 | ||
| 110 | Tx_Offset = hpcd->Instance->GRXFSIZ; |
86 | Tx_Offset = hpcd->Instance->GRXFSIZ; |
| 111 | 87 | ||
| 112 | if(fifo == 0U) |
88 | if (fifo == 0U) |
| 113 | { |
89 | { |
| 114 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (size << 16U) | Tx_Offset; |
90 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset; |
| 115 | } |
91 | } |
| 116 | else |
92 | else |
| 117 | { |
93 | { |
| 118 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16U; |
94 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16; |
| 119 | for(index = 0; index < (fifo - 1); index++) |
95 | for (i = 0U; i < (fifo - 1U); i++) |
| 120 | { |
96 | { |
| 121 | Tx_Offset += (hpcd->Instance->DIEPTXF[index] >> 16U); |
97 | Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16); |
| 122 | } |
98 | } |
| 123 | 99 | ||
| 124 | /* Multiply Tx_Size by 2 to get higher performance */ |
100 | /* Multiply Tx_Size by 2 to get higher performance */ |
| 125 | hpcd->Instance->DIEPTXF[fifo - 1U] = (size << 16U) | Tx_Offset; |
101 | hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset; |
| 126 | - | ||
| 127 | } |
102 | } |
| 128 | 103 | ||
| 129 | return HAL_OK; |
104 | return HAL_OK; |
| 130 | } |
105 | } |
| 131 | 106 | ||
| 132 | /** |
107 | /** |
| 133 | * @brief Set Rx FIFO |
108 | * @brief Set Rx FIFO |
| 134 | * @param hpcd: PCD handle |
109 | * @param hpcd PCD handle |
| 135 | * @param size: Size of Rx fifo |
110 | * @param size Size of Rx fifo |
| 136 | * @retval HAL status |
111 | * @retval HAL status |
| 137 | */ |
112 | */ |
| 138 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) |
113 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) |
| 139 | { |
114 | { |
| 140 | hpcd->Instance->GRXFSIZ = size; |
115 | hpcd->Instance->GRXFSIZ = size; |
| - | 116 | ||
| 141 | return HAL_OK; |
117 | return HAL_OK; |
| 142 | } |
118 | } |
| 143 | #endif /* USB_OTG_FS */ |
119 | #endif /* defined (USB_OTG_FS) */ |
| 144 | - | ||
| 145 | #if defined (USB) |
120 | #if defined (USB) |
| 146 | /** |
121 | /** |
| 147 | * @brief Configure PMA for EP |
122 | * @brief Configure PMA for EP |
| 148 | * @param hpcd : Device instance |
123 | * @param hpcd Device instance |
| 149 | * @param ep_addr: endpoint address |
124 | * @param ep_addr endpoint address |
| 150 | * @param ep_kind: endpoint Kind |
125 | * @param ep_kind endpoint Kind |
| 151 | * USB_SNG_BUF: Single Buffer used |
126 | * USB_SNG_BUF: Single Buffer used |
| 152 | * USB_DBL_BUF: Double Buffer used |
127 | * USB_DBL_BUF: Double Buffer used |
| 153 | * @param pmaadress: EP address in The PMA: In case of single buffer endpoint |
128 | * @param pmaadress: EP address in The PMA: In case of single buffer endpoint |
| 154 | * this parameter is 16-bit value providing the address |
129 | * this parameter is 16-bit value providing the address |
| 155 | * in PMA allocated to endpoint. |
130 | * in PMA allocated to endpoint. |
| Line 158... | Line 133... | ||
| 158 | * in the LSB part of 32-bit value and endpoint buffer 1 address |
133 | * in the LSB part of 32-bit value and endpoint buffer 1 address |
| 159 | * in the MSB part of 32-bit value. |
134 | * in the MSB part of 32-bit value. |
| 160 | * @retval HAL status |
135 | * @retval HAL status |
| 161 | */ |
136 | */ |
| 162 | 137 | ||
| 163 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, |
138 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr, |
| 164 | uint16_t ep_addr, |
- | |
| 165 | uint16_t ep_kind, |
- | |
| 166 | uint32_t pmaadress) |
139 | uint16_t ep_kind, uint32_t pmaadress) |
| 167 | - | ||
| 168 | { |
140 | { |
| 169 | PCD_EPTypeDef *ep = NULL; |
141 | PCD_EPTypeDef *ep; |
| 170 | 142 | ||
| 171 | /* initialize ep structure*/ |
143 | /* initialize ep structure*/ |
| 172 | if ((ep_addr & 0x80U) == 0x80U) |
144 | if ((0x80U & ep_addr) == 0x80U) |
| 173 | { |
145 | { |
| 174 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
146 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
| 175 | } |
147 | } |
| 176 | else |
148 | else |
| 177 | { |
149 | { |
| 178 | ep = &hpcd->OUT_ep[ep_addr]; |
150 | ep = &hpcd->OUT_ep[ep_addr]; |
| 179 | } |
151 | } |
| 180 | 152 | ||
| 181 | /* Here we check if the endpoint is single or double Buffer*/ |
153 | /* Here we check if the endpoint is single or double Buffer*/ |
| 182 | if (ep_kind == PCD_SNG_BUF) |
154 | if (ep_kind == PCD_SNG_BUF) |
| 183 | { |
155 | { |
| 184 | /*Single Buffer*/ |
156 | /* Single Buffer */ |
| 185 | ep->doublebuffer = 0U; |
157 | ep->doublebuffer = 0U; |
| 186 | /*Configure te PMA*/ |
158 | /* Configure the PMA */ |
| 187 | ep->pmaadress = (uint16_t)pmaadress; |
159 | ep->pmaadress = (uint16_t)pmaadress; |
| 188 | } |
160 | } |
| 189 | else /*USB_DBL_BUF*/ |
161 | else /* USB_DBL_BUF */ |
| 190 | { |
162 | { |
| 191 | /*Double Buffer Endpoint*/ |
163 | /* Double Buffer Endpoint */ |
| 192 | ep->doublebuffer = 1U; |
164 | ep->doublebuffer = 1U; |
| 193 | /*Configure the PMA*/ |
165 | /* Configure the PMA */ |
| 194 | ep->pmaaddr0 = pmaadress & 0x0000FFFFU; |
166 | ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU); |
| 195 | ep->pmaaddr1 = (pmaadress & 0xFFFF0000U) >> 16U; |
167 | ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16); |
| 196 | } |
168 | } |
| 197 | 169 | ||
| 198 | return HAL_OK; |
170 | return HAL_OK; |
| 199 | } |
171 | } |
| 200 | #endif /* USB */ |
- | |
| 201 | /** |
- | |
| 202 | * @} |
- | |
| 203 | */ |
- | |
| 204 | 172 | ||
| 205 | /** @defgroup PCDEx_Exported_Functions_Group2 Peripheral State functions |
- | |
| 206 | * @brief Manage device connection state |
- | |
| 207 | * @{ |
- | |
| 208 | */ |
- | |
| 209 | /** |
173 | /** |
| 210 | * @brief Software Device Connection, |
174 | * @brief Software Device Connection, |
| 211 | * this function is not required by USB OTG FS peripheral, it is used |
175 | * this function is not required by USB OTG FS peripheral, it is used |
| 212 | * only by USB Device FS peripheral. |
176 | * only by USB Device FS peripheral. |
| 213 | * @param hpcd: PCD handle |
177 | * @param hpcd PCD handle |
| 214 | * @param state: connection state (0 : disconnected / 1: connected) |
178 | * @param state connection state (0 : disconnected / 1: connected) |
| 215 | * @retval None |
179 | * @retval None |
| 216 | */ |
180 | */ |
| 217 | __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) |
181 | __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) |
| 218 | { |
182 | { |
| 219 | /* Prevent unused argument(s) compilation warning */ |
183 | /* Prevent unused argument(s) compilation warning */ |
| 220 | UNUSED(hpcd); |
184 | UNUSED(hpcd); |
| 221 | UNUSED(state); |
185 | UNUSED(state); |
| 222 | /* NOTE : This function Should not be modified, when the callback is needed, |
186 | /* NOTE : This function Should not be modified, when the callback is needed, |
| 223 | the HAL_PCDEx_SetConnectionState could be implemented in the user file |
187 | the HAL_PCDEx_SetConnectionState could be implemented in the user file |
| 224 | */ |
188 | */ |
| 225 | } |
189 | } |
| - | 190 | #endif /* defined (USB) */ |
|
| - | 191 | ||
| 226 | /** |
192 | /** |
| - | 193 | * @brief Send LPM message to user layer callback. |
|
| - | 194 | * @param hpcd PCD handle |
|
| - | 195 | * @param msg LPM message |
|
| 227 | * @} |
196 | * @retval HAL status |
| 228 | */ |
197 | */ |
| - | 198 | __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) |
|
| - | 199 | { |
|
| - | 200 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 201 | UNUSED(hpcd); |
|
| - | 202 | UNUSED(msg); |
|
| - | 203 | ||
| - | 204 | /* NOTE : This function should not be modified, when the callback is needed, |
|
| - | 205 | the HAL_PCDEx_LPM_Callback could be implemented in the user file |
|
| - | 206 | */ |
|
| - | 207 | } |
|
| 229 | 208 | ||
| 230 | /** |
209 | /** |
| - | 210 | * @brief Send BatteryCharging message to user layer callback. |
|
| - | 211 | * @param hpcd PCD handle |
|
| - | 212 | * @param msg LPM message |
|
| 231 | * @} |
213 | * @retval HAL status |
| 232 | */ |
214 | */ |
| - | 215 | __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg) |
|
| - | 216 | { |
|
| - | 217 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 218 | UNUSED(hpcd); |
|
| - | 219 | UNUSED(msg); |
|
| - | 220 | ||
| - | 221 | /* NOTE : This function should not be modified, when the callback is needed, |
|
| - | 222 | the HAL_PCDEx_BCD_Callback could be implemented in the user file |
|
| - | 223 | */ |
|
| - | 224 | } |
|
| 233 | 225 | ||
| 234 | /** |
226 | /** |
| 235 | * @} |
227 | * @} |
| 236 | */ |
228 | */ |
| 237 | 229 | ||
| 238 | #endif /* STM32F102x6 || STM32F102xB || */ |
230 | /** |
| 239 | /* STM32F103x6 || STM32F103xB || */ |
231 | * @} |
| 240 | /* STM32F103xE || STM32F103xG || */ |
232 | */ |
| 241 | /* STM32F105xC || STM32F107xC */ |
233 | #endif /* defined (USB) || defined (USB_OTG_FS) */ |
| 242 | - | ||
| 243 | #endif /* HAL_PCD_MODULE_ENABLED */ |
234 | #endif /* HAL_PCD_MODULE_ENABLED */ |
| 244 | 235 | ||
| - | 236 | /** |
|
| - | 237 | * @} |
|
| - | 238 | */ |
|
| 245 | 239 | ||
| 246 | /** |
240 | /** |
| 247 | * @} |
241 | * @} |
| 248 | */ |
242 | */ |
| 249 | 243 | ||