Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 3 | ||
|---|---|---|---|
| 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 PCD Extended 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 |
8 | * + Extended features functions |
| 9 | * |
9 | * |
| 10 | ****************************************************************************** |
10 | ****************************************************************************** |
| 11 | * @attention |
11 | * @attention |
| 12 | * |
12 | * |
| 13 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
13 | * Copyright (c) 2016 STMicroelectronics. |
| 14 | * All rights reserved.</center></h2> |
14 | * All rights reserved. |
| 15 | * |
15 | * |
| 16 | * This software component is licensed by ST under BSD 3-Clause license, |
16 | * This software is licensed under terms that can be found in the LICENSE file |
| 17 | * the "License"; You may not use this file except in compliance with the |
17 | * in the root directory of this software component. |
| 18 | * License. You may obtain a copy of the License at: |
18 | * If no LICENSE file comes with this software, it is provided AS-IS. |
| 19 | * opensource.org/licenses/BSD-3-Clause |
19 | * |
| 20 | * |
20 | ****************************************************************************** |
| 21 | ****************************************************************************** |
21 | */ |
| 22 | */ |
22 | |
| 23 | 23 | /* Includes ------------------------------------------------------------------*/ |
|
| 24 | /* Includes ------------------------------------------------------------------*/ |
24 | #include "stm32f1xx_hal.h" |
| 25 | #include "stm32f1xx_hal.h" |
25 | |
| 26 | 26 | /** @addtogroup STM32F1xx_HAL_Driver |
|
| 27 | /** @addtogroup STM32F1xx_HAL_Driver |
27 | * @{ |
| 28 | * @{ |
28 | */ |
| 29 | */ |
29 | |
| 30 | 30 | /** @defgroup PCDEx PCDEx |
|
| 31 | /** @defgroup PCDEx PCDEx |
31 | * @brief PCD Extended HAL module driver |
| 32 | * @brief PCD Extended HAL module driver |
32 | * @{ |
| 33 | * @{ |
33 | */ |
| 34 | */ |
34 | |
| 35 | 35 | #ifdef HAL_PCD_MODULE_ENABLED |
|
| 36 | #ifdef HAL_PCD_MODULE_ENABLED |
36 | |
| 37 | 37 | #if defined (USB) || defined (USB_OTG_FS) |
|
| 38 | #if defined (USB) || defined (USB_OTG_FS) |
38 | /* Private types -------------------------------------------------------------*/ |
| 39 | /* Private types -------------------------------------------------------------*/ |
39 | /* Private variables ---------------------------------------------------------*/ |
| 40 | /* Private variables ---------------------------------------------------------*/ |
40 | /* Private constants ---------------------------------------------------------*/ |
| 41 | /* Private constants ---------------------------------------------------------*/ |
41 | /* Private macros ------------------------------------------------------------*/ |
| 42 | /* Private macros ------------------------------------------------------------*/ |
42 | /* Private functions ---------------------------------------------------------*/ |
| 43 | /* Private functions ---------------------------------------------------------*/ |
43 | /* Exported functions --------------------------------------------------------*/ |
| 44 | /* Exported functions --------------------------------------------------------*/ |
44 | |
| 45 | 45 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions |
|
| 46 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions |
46 | * @{ |
| 47 | * @{ |
47 | */ |
| 48 | */ |
48 | |
| 49 | 49 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions |
|
| 50 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions |
50 | * @brief PCDEx control functions |
| 51 | * @brief PCDEx control functions |
51 | * |
| 52 | * |
52 | @verbatim |
| 53 | @verbatim |
53 | =============================================================================== |
| 54 | =============================================================================== |
54 | ##### Extended features functions ##### |
| 55 | ##### Extended features functions ##### |
55 | =============================================================================== |
| 56 | =============================================================================== |
56 | [..] This section provides functions allowing to: |
| 57 | [..] This section provides functions allowing to: |
57 | (+) Update FIFO configuration |
| 58 | (+) Update FIFO configuration |
58 | |
| 59 | 59 | @endverbatim |
|
| 60 | @endverbatim |
60 | * @{ |
| 61 | * @{ |
61 | */ |
| 62 | */ |
62 | #if defined (USB_OTG_FS) |
| 63 | #if defined (USB_OTG_FS) |
63 | /** |
| 64 | /** |
64 | * @brief Set Tx FIFO |
| 65 | * @brief Set Tx FIFO |
65 | * @param hpcd PCD handle |
| 66 | * @param hpcd PCD handle |
66 | * @param fifo The number of Tx fifo |
| 67 | * @param fifo The number of Tx fifo |
67 | * @param size Fifo size |
| 68 | * @param size Fifo size |
68 | * @retval HAL status |
| 69 | * @retval HAL status |
69 | */ |
| 70 | */ |
70 | 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) |
71 | { |
| 72 | { |
72 | uint8_t i; |
| 73 | uint8_t i; |
73 | uint32_t Tx_Offset; |
| 74 | uint32_t Tx_Offset; |
74 | |
| 75 | 75 | /* TXn min size = 16 words. (n : Transmit FIFO index) |
|
| 76 | /* TXn min size = 16 words. (n : Transmit FIFO index) |
76 | 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: |
77 | 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) |
78 | --> Txm can use the space allocated for Txn. |
| 79 | --> Txm can use the space allocated for Txn. |
79 | 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) |
80 | --> Txn should be configured with the minimum space of 16 words |
| 81 | --> Txn should be configured with the minimum space of 16 words |
81 | 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 |
82 | 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. |
83 | 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 */ |
84 | |
| 85 | 85 | Tx_Offset = hpcd->Instance->GRXFSIZ; |
|
| 86 | Tx_Offset = hpcd->Instance->GRXFSIZ; |
86 | |
| 87 | 87 | if (fifo == 0U) |
|
| 88 | if (fifo == 0U) |
88 | { |
| 89 | { |
89 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset; |
| 90 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset; |
90 | } |
| 91 | } |
91 | else |
| 92 | else |
92 | { |
| 93 | { |
93 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16; |
| 94 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16; |
94 | for (i = 0U; i < (fifo - 1U); i++) |
| 95 | for (i = 0U; i < (fifo - 1U); i++) |
95 | { |
| 96 | { |
96 | Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16); |
| 97 | Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16); |
97 | } |
| 98 | } |
98 | |
| 99 | 99 | /* Multiply Tx_Size by 2 to get higher performance */ |
|
| 100 | /* Multiply Tx_Size by 2 to get higher performance */ |
100 | hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset; |
| 101 | hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset; |
101 | } |
| 102 | } |
102 | |
| 103 | 103 | return HAL_OK; |
|
| 104 | return HAL_OK; |
104 | } |
| 105 | } |
105 | |
| 106 | 106 | /** |
|
| 107 | /** |
107 | * @brief Set Rx FIFO |
| 108 | * @brief Set Rx FIFO |
108 | * @param hpcd PCD handle |
| 109 | * @param hpcd PCD handle |
109 | * @param size Size of Rx fifo |
| 110 | * @param size Size of Rx fifo |
110 | * @retval HAL status |
| 111 | * @retval HAL status |
111 | */ |
| 112 | */ |
112 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) |
| 113 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) |
113 | { |
| 114 | { |
114 | hpcd->Instance->GRXFSIZ = size; |
| 115 | hpcd->Instance->GRXFSIZ = size; |
115 | |
| 116 | 116 | return HAL_OK; |
|
| 117 | return HAL_OK; |
117 | } |
| 118 | } |
118 | #endif /* defined (USB_OTG_FS) */ |
| 119 | #endif /* defined (USB_OTG_FS) */ |
119 | #if defined (USB) |
| 120 | #if defined (USB) |
120 | /** |
| 121 | /** |
121 | * @brief Configure PMA for EP |
| 122 | * @brief Configure PMA for EP |
122 | * @param hpcd Device instance |
| 123 | * @param hpcd Device instance |
123 | * @param ep_addr endpoint address |
| 124 | * @param ep_addr endpoint address |
124 | * @param ep_kind endpoint Kind |
| 125 | * @param ep_kind endpoint Kind |
125 | * USB_SNG_BUF: Single Buffer used |
| 126 | * USB_SNG_BUF: Single Buffer used |
126 | * USB_DBL_BUF: Double Buffer used |
| 127 | * USB_DBL_BUF: Double Buffer used |
127 | * @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 |
128 | * this parameter is 16-bit value providing the address |
| 129 | * this parameter is 16-bit value providing the address |
129 | * in PMA allocated to endpoint. |
| 130 | * in PMA allocated to endpoint. |
130 | * In case of double buffer endpoint this parameter |
| 131 | * In case of double buffer endpoint this parameter |
131 | * is a 32-bit value providing the endpoint buffer 0 address |
| 132 | * is a 32-bit value providing the endpoint buffer 0 address |
132 | * 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 |
133 | * in the MSB part of 32-bit value. |
| 134 | * in the MSB part of 32-bit value. |
134 | * @retval HAL status |
| 135 | * @retval HAL status |
135 | */ |
| 136 | */ |
136 | |
| 137 | 137 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr, |
|
| 138 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr, |
138 | uint16_t ep_kind, uint32_t pmaadress) |
| 139 | uint16_t ep_kind, uint32_t pmaadress) |
139 | { |
| 140 | { |
140 | PCD_EPTypeDef *ep; |
| 141 | PCD_EPTypeDef *ep; |
141 | |
| 142 | 142 | /* initialize ep structure*/ |
|
| 143 | /* initialize ep structure*/ |
143 | if ((0x80U & ep_addr) == 0x80U) |
| 144 | if ((0x80U & ep_addr) == 0x80U) |
144 | { |
| 145 | { |
145 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
| 146 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
146 | } |
| 147 | } |
147 | else |
| 148 | else |
148 | { |
| 149 | { |
149 | ep = &hpcd->OUT_ep[ep_addr]; |
| 150 | ep = &hpcd->OUT_ep[ep_addr]; |
150 | } |
| 151 | } |
151 | |
| 152 | 152 | /* Here we check if the endpoint is single or double Buffer*/ |
|
| 153 | /* Here we check if the endpoint is single or double Buffer*/ |
153 | if (ep_kind == PCD_SNG_BUF) |
| 154 | if (ep_kind == PCD_SNG_BUF) |
154 | { |
| 155 | { |
155 | /* Single Buffer */ |
| 156 | /* Single Buffer */ |
156 | ep->doublebuffer = 0U; |
| 157 | ep->doublebuffer = 0U; |
157 | /* Configure the PMA */ |
| 158 | /* Configure the PMA */ |
158 | ep->pmaadress = (uint16_t)pmaadress; |
| 159 | ep->pmaadress = (uint16_t)pmaadress; |
159 | } |
| 160 | } |
160 | #if (USE_USB_DOUBLE_BUFFER == 1U) |
| 161 | else /* USB_DBL_BUF */ |
161 | else /* USB_DBL_BUF */ |
| 162 | { |
162 | { |
| 163 | /* Double Buffer Endpoint */ |
163 | /* Double Buffer Endpoint */ |
| 164 | ep->doublebuffer = 1U; |
164 | ep->doublebuffer = 1U; |
| 165 | /* Configure the PMA */ |
165 | /* Configure the PMA */ |
| 166 | ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU); |
166 | ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU); |
| 167 | ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16); |
167 | ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16); |
| 168 | } |
168 | } |
| 169 | 169 | #endif /* (USE_USB_DOUBLE_BUFFER == 1U) */ |
|
| 170 | return HAL_OK; |
170 | |
| 171 | } |
171 | return HAL_OK; |
| 172 | 172 | } |
|
| 173 | /** |
173 | |
| 174 | * @brief Software Device Connection, |
174 | /** |
| 175 | * this function is not required by USB OTG FS peripheral, it is used |
175 | * @brief Software Device Connection, |
| 176 | * only by USB Device FS peripheral. |
176 | * this function is not required by USB OTG FS peripheral, it is used |
| 177 | * @param hpcd PCD handle |
177 | * only by USB Device FS peripheral. |
| 178 | * @param state connection state (0 : disconnected / 1: connected) |
178 | * @param hpcd PCD handle |
| 179 | * @retval None |
179 | * @param state connection state (0 : disconnected / 1: connected) |
| 180 | */ |
180 | * @retval None |
| 181 | __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) |
181 | */ |
| 182 | { |
182 | __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) |
| 183 | /* Prevent unused argument(s) compilation warning */ |
183 | { |
| 184 | UNUSED(hpcd); |
184 | /* Prevent unused argument(s) compilation warning */ |
| 185 | UNUSED(state); |
185 | UNUSED(hpcd); |
| 186 | /* NOTE : This function Should not be modified, when the callback is needed, |
186 | UNUSED(state); |
| 187 | the HAL_PCDEx_SetConnectionState could be implemented in the user file |
187 | /* NOTE : This function Should not be modified, when the callback is needed, |
| 188 | */ |
188 | the HAL_PCDEx_SetConnectionState could be implemented in the user file |
| 189 | } |
189 | */ |
| 190 | #endif /* defined (USB) */ |
190 | } |
| 191 | 191 | #endif /* defined (USB) */ |
|
| 192 | /** |
192 | |
| 193 | * @brief Send LPM message to user layer callback. |
193 | /** |
| 194 | * @param hpcd PCD handle |
194 | * @brief Send LPM message to user layer callback. |
| 195 | * @param msg LPM message |
195 | * @param hpcd PCD handle |
| 196 | * @retval HAL status |
196 | * @param msg LPM message |
| 197 | */ |
197 | * @retval HAL status |
| 198 | __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) |
198 | */ |
| 199 | { |
199 | __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) |
| 200 | /* Prevent unused argument(s) compilation warning */ |
200 | { |
| 201 | UNUSED(hpcd); |
201 | /* Prevent unused argument(s) compilation warning */ |
| 202 | UNUSED(msg); |
202 | UNUSED(hpcd); |
| 203 | 203 | UNUSED(msg); |
|
| 204 | /* NOTE : This function should not be modified, when the callback is needed, |
204 | |
| 205 | the HAL_PCDEx_LPM_Callback could be implemented in the user file |
205 | /* NOTE : This function should not be modified, when the callback is needed, |
| 206 | */ |
206 | the HAL_PCDEx_LPM_Callback could be implemented in the user file |
| 207 | } |
207 | */ |
| 208 | 208 | } |
|
| 209 | /** |
209 | |
| 210 | * @brief Send BatteryCharging message to user layer callback. |
210 | /** |
| 211 | * @param hpcd PCD handle |
211 | * @brief Send BatteryCharging message to user layer callback. |
| 212 | * @param msg LPM message |
212 | * @param hpcd PCD handle |
| 213 | * @retval HAL status |
213 | * @param msg LPM message |
| 214 | */ |
214 | * @retval HAL status |
| 215 | __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg) |
215 | */ |
| 216 | { |
216 | __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg) |
| 217 | /* Prevent unused argument(s) compilation warning */ |
217 | { |
| 218 | UNUSED(hpcd); |
218 | /* Prevent unused argument(s) compilation warning */ |
| 219 | UNUSED(msg); |
219 | UNUSED(hpcd); |
| 220 | 220 | UNUSED(msg); |
|
| 221 | /* NOTE : This function should not be modified, when the callback is needed, |
221 | |
| 222 | the HAL_PCDEx_BCD_Callback could be implemented in the user file |
222 | /* NOTE : This function should not be modified, when the callback is needed, |
| 223 | */ |
223 | the HAL_PCDEx_BCD_Callback could be implemented in the user file |
| 224 | } |
224 | */ |
| 225 | 225 | } |
|
| 226 | /** |
226 | |
| 227 | * @} |
227 | /** |
| 228 | */ |
228 | * @} |
| 229 | 229 | */ |
|
| 230 | /** |
230 | |
| 231 | * @} |
231 | /** |
| 232 | */ |
232 | * @} |
| 233 | #endif /* defined (USB) || defined (USB_OTG_FS) */ |
233 | */ |
| 234 | #endif /* HAL_PCD_MODULE_ENABLED */ |
234 | #endif /* defined (USB) || defined (USB_OTG_FS) */ |
| 235 | 235 | #endif /* HAL_PCD_MODULE_ENABLED */ |
|
| 236 | /** |
236 | |
| 237 | * @} |
237 | /** |
| 238 | */ |
238 | * @} |
| 239 | 239 | */ |
|
| 240 | /** |
240 | |
| 241 | * @} |
241 | /** |
| 242 | */ |
242 | * @} |
| 243 | 243 | */ |
|
| 244 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
- | |