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 usbd_cdc.c |
3 | * @file usbd_cdc.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @version V2.4.2 |
- | |
6 | * @date 11-December-2015 |
- | |
7 | * @brief This file provides the high layer firmware functions to manage the |
5 | * @brief This file provides the high layer firmware functions to manage the |
8 | * following functionalities of the USB CDC Class: |
6 | * following functionalities of the USB CDC Class: |
9 | * - Initialization and Configuration of high and low layer |
7 | * - Initialization and Configuration of high and low layer |
10 | * - Enumeration as CDC Device (and enumeration for each implemented memory interface) |
8 | * - Enumeration as CDC Device (and enumeration for each implemented memory interface) |
11 | * - OUT/IN data transfer |
9 | * - OUT/IN data transfer |
12 | * - Command IN transfer (class requests management) |
10 | * - Command IN transfer (class requests management) |
13 | * - Error management |
11 | * - Error management |
14 | * |
12 | * |
15 | * @verbatim |
13 | * @verbatim |
16 | * |
14 | * |
17 | * =================================================================== |
15 | * =================================================================== |
18 | * CDC Class Driver Description |
16 | * CDC Class Driver Description |
19 | * =================================================================== |
17 | * =================================================================== |
20 | * This driver manages the "Universal Serial Bus Class Definitions for Communications Devices |
18 | * This driver manages the "Universal Serial Bus Class Definitions for Communications Devices |
21 | * Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus |
19 | * Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus |
22 | * Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007" |
20 | * Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007" |
23 | * This driver implements the following aspects of the specification: |
21 | * This driver implements the following aspects of the specification: |
24 | * - Device descriptor management |
22 | * - Device descriptor management |
25 | * - Configuration descriptor management |
23 | * - Configuration descriptor management |
26 | * - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN) |
24 | * - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN) |
27 | * - Requests management (as described in section 6.2 in specification) |
25 | * - Requests management (as described in section 6.2 in specification) |
28 | * - Abstract Control Model compliant |
26 | * - Abstract Control Model compliant |
29 | * - Union Functional collection (using 1 IN endpoint for control) |
27 | * - Union Functional collection (using 1 IN endpoint for control) |
30 | * - Data interface class |
28 | * - Data interface class |
31 | * |
29 | * |
32 | * These aspects may be enriched or modified for a specific user application. |
30 | * These aspects may be enriched or modified for a specific user application. |
33 | * |
31 | * |
34 | * This driver doesn't implement the following aspects of the specification |
32 | * This driver doesn't implement the following aspects of the specification |
35 | * (but it is possible to manage these features with some modifications on this driver): |
33 | * (but it is possible to manage these features with some modifications on this driver): |
36 | * - Any class-specific aspect relative to communication classes should be managed by user application. |
34 | * - Any class-specific aspect relative to communication classes should be managed by user application. |
37 | * - All communication classes other than PSTN are not managed |
35 | * - All communication classes other than PSTN are not managed |
38 | * |
36 | * |
39 | * @endverbatim |
37 | * @endverbatim |
40 | * |
38 | * |
41 | ****************************************************************************** |
39 | ****************************************************************************** |
42 | * @attention |
40 | * @attention |
43 | * |
41 | * |
44 | * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> |
42 | * <h2><center>© Copyright (c) 2015 STMicroelectronics. |
45 | * |
- | |
46 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
- | |
47 | * You may not use this file except in compliance with the License. |
- | |
48 | * You may obtain a copy of the License at: |
43 | * All rights reserved.</center></h2> |
49 | * |
44 | * |
50 | * http://www.st.com/software_license_agreement_liberty_v2 |
- | |
51 | * |
- | |
52 | * Unless required by applicable law or agreed to in writing, software |
45 | * This software component is licensed by ST under Ultimate Liberty license |
53 | * distributed under the License is distributed on an "AS IS" BASIS, |
46 | * SLA0044, the "License"; You may not use this file except in compliance with |
54 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
- | |
55 | * See the License for the specific language governing permissions and |
47 | * the License. You may obtain a copy of the License at: |
56 | * limitations under the License. |
48 | * www.st.com/SLA0044 |
57 | * |
49 | * |
58 | ****************************************************************************** |
50 | ****************************************************************************** |
59 | */ |
51 | */ |
- | 52 | ||
- | 53 | /* BSPDependencies |
|
- | 54 | - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" |
|
- | 55 | - "stm32xxxxx_{eval}{discovery}_io.c" |
|
- | 56 | EndBSPDependencies */ |
|
60 | 57 | ||
61 | /* Includes ------------------------------------------------------------------*/ |
58 | /* Includes ------------------------------------------------------------------*/ |
62 | #include "usbd_cdc.h" |
59 | #include "usbd_cdc.h" |
63 | #include "usbd_desc.h" |
- | |
64 | #include "usbd_ctlreq.h" |
60 | #include "usbd_ctlreq.h" |
65 | 61 | ||
66 | 62 | ||
67 | /** @addtogroup STM32_USB_DEVICE_LIBRARY |
63 | /** @addtogroup STM32_USB_DEVICE_LIBRARY |
68 | * @{ |
64 | * @{ |
69 | */ |
65 | */ |
70 | 66 | ||
71 | 67 | ||
72 | /** @defgroup USBD_CDC |
68 | /** @defgroup USBD_CDC |
73 | * @brief usbd core module |
69 | * @brief usbd core module |
74 | * @{ |
70 | * @{ |
75 | */ |
71 | */ |
76 | 72 | ||
77 | /** @defgroup USBD_CDC_Private_TypesDefinitions |
73 | /** @defgroup USBD_CDC_Private_TypesDefinitions |
78 | * @{ |
74 | * @{ |
79 | */ |
75 | */ |
80 | /** |
76 | /** |
81 | * @} |
77 | * @} |
82 | */ |
78 | */ |
83 | 79 | ||
84 | 80 | ||
85 | /** @defgroup USBD_CDC_Private_Defines |
81 | /** @defgroup USBD_CDC_Private_Defines |
86 | * @{ |
82 | * @{ |
87 | */ |
83 | */ |
88 | /** |
84 | /** |
89 | * @} |
85 | * @} |
90 | */ |
86 | */ |
91 | 87 | ||
92 | 88 | ||
93 | /** @defgroup USBD_CDC_Private_Macros |
89 | /** @defgroup USBD_CDC_Private_Macros |
94 | * @{ |
90 | * @{ |
95 | */ |
91 | */ |
96 | 92 | ||
97 | /** |
93 | /** |
98 | * @} |
94 | * @} |
99 | */ |
95 | */ |
100 | 96 | ||
101 | 97 | ||
102 | /** @defgroup USBD_CDC_Private_FunctionPrototypes |
98 | /** @defgroup USBD_CDC_Private_FunctionPrototypes |
103 | * @{ |
99 | * @{ |
104 | */ |
100 | */ |
105 | 101 | ||
106 | 102 | ||
107 | static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, |
103 | static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, |
108 | uint8_t cfgidx); |
104 | uint8_t cfgidx); |
109 | 105 | ||
110 | static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, |
106 | static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, |
111 | uint8_t cfgidx); |
107 | uint8_t cfgidx); |
112 | 108 | ||
113 | static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, |
109 | static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, |
114 | USBD_SetupReqTypedef *req); |
110 | USBD_SetupReqTypedef *req); |
115 | 111 | ||
116 | static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, |
112 | static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, |
117 | uint8_t epnum); |
113 | uint8_t epnum); |
118 | 114 | ||
119 | static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, |
115 | static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, |
120 | uint8_t epnum); |
116 | uint8_t epnum); |
121 | 117 | ||
122 | static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev); |
118 | static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev); |
123 | 119 | ||
124 | static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length); |
120 | static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length); |
125 | 121 | ||
126 | static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length); |
122 | static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length); |
127 | 123 | ||
128 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); |
124 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length); |
129 | 125 | ||
130 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); |
126 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length); |
131 | 127 | ||
132 | uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length); |
128 | uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length); |
133 | 129 | ||
134 | /* USB Standard Device Descriptor */ |
130 | /* USB Standard Device Descriptor */ |
135 | __ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = |
131 | __ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = |
136 | { |
132 | { |
137 | USB_LEN_DEV_QUALIFIER_DESC, |
133 | USB_LEN_DEV_QUALIFIER_DESC, |
Line 146... | Line 142... | ||
146 | 0x00, |
142 | 0x00, |
147 | }; |
143 | }; |
148 | 144 | ||
149 | /** |
145 | /** |
150 | * @} |
146 | * @} |
151 | */ |
147 | */ |
152 | 148 | ||
153 | /** @defgroup USBD_CDC_Private_Variables |
149 | /** @defgroup USBD_CDC_Private_Variables |
154 | * @{ |
150 | * @{ |
155 | */ |
151 | */ |
156 | 152 | ||
157 | 153 | ||
158 | /* CDC interface class callbacks structure */ |
154 | /* CDC interface class callbacks structure */ |
159 | USBD_ClassTypeDef USBD_CDC = |
155 | USBD_ClassTypeDef USBD_CDC = |
160 | { |
156 | { |
161 | USBD_CDC_Init, |
157 | USBD_CDC_Init, |
162 | USBD_CDC_DeInit, |
158 | USBD_CDC_DeInit, |
163 | USBD_CDC_Setup, |
159 | USBD_CDC_Setup, |
164 | NULL, /* EP0_TxSent, */ |
160 | NULL, /* EP0_TxSent, */ |
165 | USBD_CDC_EP0_RxReady, |
161 | USBD_CDC_EP0_RxReady, |
166 | USBD_CDC_DataIn, |
162 | USBD_CDC_DataIn, |
167 | USBD_CDC_DataOut, |
163 | USBD_CDC_DataOut, |
168 | NULL, |
164 | NULL, |
169 | NULL, |
165 | NULL, |
170 | NULL, |
166 | NULL, |
171 | USBD_CDC_GetHSCfgDesc, |
167 | USBD_CDC_GetHSCfgDesc, |
172 | USBD_CDC_GetFSCfgDesc, |
168 | USBD_CDC_GetFSCfgDesc, |
173 | USBD_CDC_GetOtherSpeedCfgDesc, |
169 | USBD_CDC_GetOtherSpeedCfgDesc, |
174 | USBD_CDC_GetDeviceQualifierDescriptor, |
170 | USBD_CDC_GetDeviceQualifierDescriptor, |
175 | }; |
171 | }; |
176 | 172 | ||
177 | /* USB CDC device Configuration Descriptor */ |
173 | /* USB CDC device Configuration Descriptor */ |
178 | __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = |
174 | __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = |
Line 185... | Line 181... | ||
185 | 0x02, /* bNumInterfaces: 2 interface */ |
181 | 0x02, /* bNumInterfaces: 2 interface */ |
186 | 0x01, /* bConfigurationValue: Configuration value */ |
182 | 0x01, /* bConfigurationValue: Configuration value */ |
187 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ |
183 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ |
188 | 0xC0, /* bmAttributes: self powered */ |
184 | 0xC0, /* bmAttributes: self powered */ |
189 | 0x32, /* MaxPower 0 mA */ |
185 | 0x32, /* MaxPower 0 mA */ |
190 | 186 | ||
191 | /*---------------------------------------------------------------------------*/ |
187 | /*---------------------------------------------------------------------------*/ |
192 | 188 | ||
193 | /*Interface Descriptor */ |
189 | /*Interface Descriptor */ |
194 | 0x09, /* bLength: Interface Descriptor size */ |
190 | 0x09, /* bLength: Interface Descriptor size */ |
195 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
191 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
196 | /* Interface descriptor type */ |
192 | /* Interface descriptor type */ |
197 | 0x00, /* bInterfaceNumber: Number of Interface */ |
193 | 0x00, /* bInterfaceNumber: Number of Interface */ |
Line 199... | Line 195... | ||
199 | 0x01, /* bNumEndpoints: One endpoints used */ |
195 | 0x01, /* bNumEndpoints: One endpoints used */ |
200 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
196 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
201 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
197 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
202 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
198 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
203 | 0x00, /* iInterface: */ |
199 | 0x00, /* iInterface: */ |
204 | 200 | ||
205 | /*Header Functional Descriptor*/ |
201 | /*Header Functional Descriptor*/ |
206 | 0x05, /* bLength: Endpoint Descriptor size */ |
202 | 0x05, /* bLength: Endpoint Descriptor size */ |
207 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
203 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
208 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
204 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
209 | 0x10, /* bcdCDC: spec release number */ |
205 | 0x10, /* bcdCDC: spec release number */ |
210 | 0x01, |
206 | 0x01, |
211 | 207 | ||
212 | /*Call Management Functional Descriptor*/ |
208 | /*Call Management Functional Descriptor*/ |
213 | 0x05, /* bFunctionLength */ |
209 | 0x05, /* bFunctionLength */ |
214 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
210 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
215 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
211 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
216 | 0x00, /* bmCapabilities: D0+D1 */ |
212 | 0x00, /* bmCapabilities: D0+D1 */ |
217 | 0x01, /* bDataInterface: 1 */ |
213 | 0x01, /* bDataInterface: 1 */ |
218 | 214 | ||
219 | /*ACM Functional Descriptor*/ |
215 | /*ACM Functional Descriptor*/ |
220 | 0x04, /* bFunctionLength */ |
216 | 0x04, /* bFunctionLength */ |
221 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
217 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
222 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
218 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
223 | 0x02, /* bmCapabilities */ |
219 | 0x02, /* bmCapabilities */ |
224 | 220 | ||
225 | /*Union Functional Descriptor*/ |
221 | /*Union Functional Descriptor*/ |
226 | 0x05, /* bFunctionLength */ |
222 | 0x05, /* bFunctionLength */ |
227 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
223 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
228 | 0x06, /* bDescriptorSubtype: Union func desc */ |
224 | 0x06, /* bDescriptorSubtype: Union func desc */ |
229 | 0x00, /* bMasterInterface: Communication class interface */ |
225 | 0x00, /* bMasterInterface: Communication class interface */ |
230 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
226 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
231 | 227 | ||
232 | /*Endpoint 2 Descriptor*/ |
228 | /*Endpoint 2 Descriptor*/ |
233 | 0x07, /* bLength: Endpoint Descriptor size */ |
229 | 0x07, /* bLength: Endpoint Descriptor size */ |
234 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
230 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
235 | CDC_CMD_EP, /* bEndpointAddress */ |
231 | CDC_CMD_EP, /* bEndpointAddress */ |
236 | 0x03, /* bmAttributes: Interrupt */ |
232 | 0x03, /* bmAttributes: Interrupt */ |
237 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
233 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
238 | HIBYTE(CDC_CMD_PACKET_SIZE), |
234 | HIBYTE(CDC_CMD_PACKET_SIZE), |
239 | 0x10, /* bInterval: */ |
235 | CDC_HS_BINTERVAL, /* bInterval: */ |
240 | /*---------------------------------------------------------------------------*/ |
236 | /*---------------------------------------------------------------------------*/ |
241 | 237 | ||
242 | /*Data class interface descriptor*/ |
238 | /*Data class interface descriptor*/ |
243 | 0x09, /* bLength: Endpoint Descriptor size */ |
239 | 0x09, /* bLength: Endpoint Descriptor size */ |
244 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
240 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
245 | 0x01, /* bInterfaceNumber: Number of Interface */ |
241 | 0x01, /* bInterfaceNumber: Number of Interface */ |
246 | 0x00, /* bAlternateSetting: Alternate setting */ |
242 | 0x00, /* bAlternateSetting: Alternate setting */ |
247 | 0x02, /* bNumEndpoints: Two endpoints used */ |
243 | 0x02, /* bNumEndpoints: Two endpoints used */ |
248 | 0x0A, /* bInterfaceClass: CDC */ |
244 | 0x0A, /* bInterfaceClass: CDC */ |
249 | 0x00, /* bInterfaceSubClass: */ |
245 | 0x00, /* bInterfaceSubClass: */ |
250 | 0x00, /* bInterfaceProtocol: */ |
246 | 0x00, /* bInterfaceProtocol: */ |
251 | 0x00, /* iInterface: */ |
247 | 0x00, /* iInterface: */ |
252 | 248 | ||
253 | /*Endpoint OUT Descriptor*/ |
249 | /*Endpoint OUT Descriptor*/ |
254 | 0x07, /* bLength: Endpoint Descriptor size */ |
250 | 0x07, /* bLength: Endpoint Descriptor size */ |
255 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
251 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
256 | CDC_OUT_EP, /* bEndpointAddress */ |
252 | CDC_OUT_EP, /* bEndpointAddress */ |
257 | 0x02, /* bmAttributes: Bulk */ |
253 | 0x02, /* bmAttributes: Bulk */ |
258 | LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ |
254 | LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ |
259 | HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), |
255 | HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), |
260 | 0x00, /* bInterval: ignore for Bulk transfer */ |
256 | 0x00, /* bInterval: ignore for Bulk transfer */ |
261 | 257 | ||
262 | /*Endpoint IN Descriptor*/ |
258 | /*Endpoint IN Descriptor*/ |
263 | 0x07, /* bLength: Endpoint Descriptor size */ |
259 | 0x07, /* bLength: Endpoint Descriptor size */ |
264 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
260 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
265 | CDC_IN_EP, /* bEndpointAddress */ |
261 | CDC_IN_EP, /* bEndpointAddress */ |
266 | 0x02, /* bmAttributes: Bulk */ |
262 | 0x02, /* bmAttributes: Bulk */ |
Line 281... | Line 277... | ||
281 | 0x02, /* bNumInterfaces: 2 interface */ |
277 | 0x02, /* bNumInterfaces: 2 interface */ |
282 | 0x01, /* bConfigurationValue: Configuration value */ |
278 | 0x01, /* bConfigurationValue: Configuration value */ |
283 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ |
279 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ |
284 | 0xC0, /* bmAttributes: self powered */ |
280 | 0xC0, /* bmAttributes: self powered */ |
285 | 0x32, /* MaxPower 0 mA */ |
281 | 0x32, /* MaxPower 0 mA */ |
286 | 282 | ||
287 | /*---------------------------------------------------------------------------*/ |
283 | /*---------------------------------------------------------------------------*/ |
288 | 284 | ||
289 | /*Interface Descriptor */ |
285 | /*Interface Descriptor */ |
290 | 0x09, /* bLength: Interface Descriptor size */ |
286 | 0x09, /* bLength: Interface Descriptor size */ |
291 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
287 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
292 | /* Interface descriptor type */ |
288 | /* Interface descriptor type */ |
293 | 0x00, /* bInterfaceNumber: Number of Interface */ |
289 | 0x00, /* bInterfaceNumber: Number of Interface */ |
Line 295... | Line 291... | ||
295 | 0x01, /* bNumEndpoints: One endpoints used */ |
291 | 0x01, /* bNumEndpoints: One endpoints used */ |
296 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
292 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
297 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
293 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
298 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
294 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
299 | 0x00, /* iInterface: */ |
295 | 0x00, /* iInterface: */ |
300 | 296 | ||
301 | /*Header Functional Descriptor*/ |
297 | /*Header Functional Descriptor*/ |
302 | 0x05, /* bLength: Endpoint Descriptor size */ |
298 | 0x05, /* bLength: Endpoint Descriptor size */ |
303 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
299 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
304 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
300 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
305 | 0x10, /* bcdCDC: spec release number */ |
301 | 0x10, /* bcdCDC: spec release number */ |
306 | 0x01, |
302 | 0x01, |
307 | 303 | ||
308 | /*Call Management Functional Descriptor*/ |
304 | /*Call Management Functional Descriptor*/ |
309 | 0x05, /* bFunctionLength */ |
305 | 0x05, /* bFunctionLength */ |
310 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
306 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
311 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
307 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
312 | 0x00, /* bmCapabilities: D0+D1 */ |
308 | 0x00, /* bmCapabilities: D0+D1 */ |
313 | 0x01, /* bDataInterface: 1 */ |
309 | 0x01, /* bDataInterface: 1 */ |
314 | 310 | ||
315 | /*ACM Functional Descriptor*/ |
311 | /*ACM Functional Descriptor*/ |
316 | 0x04, /* bFunctionLength */ |
312 | 0x04, /* bFunctionLength */ |
317 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
313 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
318 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
314 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
319 | 0x02, /* bmCapabilities */ |
315 | 0x02, /* bmCapabilities */ |
320 | 316 | ||
321 | /*Union Functional Descriptor*/ |
317 | /*Union Functional Descriptor*/ |
322 | 0x05, /* bFunctionLength */ |
318 | 0x05, /* bFunctionLength */ |
323 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
319 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
324 | 0x06, /* bDescriptorSubtype: Union func desc */ |
320 | 0x06, /* bDescriptorSubtype: Union func desc */ |
325 | 0x00, /* bMasterInterface: Communication class interface */ |
321 | 0x00, /* bMasterInterface: Communication class interface */ |
326 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
322 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
327 | 323 | ||
328 | /*Endpoint 2 Descriptor*/ |
324 | /*Endpoint 2 Descriptor*/ |
329 | 0x07, /* bLength: Endpoint Descriptor size */ |
325 | 0x07, /* bLength: Endpoint Descriptor size */ |
330 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
326 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
331 | CDC_CMD_EP, /* bEndpointAddress */ |
327 | CDC_CMD_EP, /* bEndpointAddress */ |
332 | 0x03, /* bmAttributes: Interrupt */ |
328 | 0x03, /* bmAttributes: Interrupt */ |
333 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
329 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
334 | HIBYTE(CDC_CMD_PACKET_SIZE), |
330 | HIBYTE(CDC_CMD_PACKET_SIZE), |
335 | 0x10, /* bInterval: */ |
331 | CDC_FS_BINTERVAL, /* bInterval: */ |
336 | /*---------------------------------------------------------------------------*/ |
332 | /*---------------------------------------------------------------------------*/ |
337 | 333 | ||
338 | /*Data class interface descriptor*/ |
334 | /*Data class interface descriptor*/ |
339 | 0x09, /* bLength: Endpoint Descriptor size */ |
335 | 0x09, /* bLength: Endpoint Descriptor size */ |
340 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
336 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
341 | 0x01, /* bInterfaceNumber: Number of Interface */ |
337 | 0x01, /* bInterfaceNumber: Number of Interface */ |
342 | 0x00, /* bAlternateSetting: Alternate setting */ |
338 | 0x00, /* bAlternateSetting: Alternate setting */ |
343 | 0x02, /* bNumEndpoints: Two endpoints used */ |
339 | 0x02, /* bNumEndpoints: Two endpoints used */ |
344 | 0x0A, /* bInterfaceClass: CDC */ |
340 | 0x0A, /* bInterfaceClass: CDC */ |
345 | 0x00, /* bInterfaceSubClass: */ |
341 | 0x00, /* bInterfaceSubClass: */ |
346 | 0x00, /* bInterfaceProtocol: */ |
342 | 0x00, /* bInterfaceProtocol: */ |
347 | 0x00, /* iInterface: */ |
343 | 0x00, /* iInterface: */ |
348 | 344 | ||
349 | /*Endpoint OUT Descriptor*/ |
345 | /*Endpoint OUT Descriptor*/ |
350 | 0x07, /* bLength: Endpoint Descriptor size */ |
346 | 0x07, /* bLength: Endpoint Descriptor size */ |
351 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
347 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
352 | CDC_OUT_EP, /* bEndpointAddress */ |
348 | CDC_OUT_EP, /* bEndpointAddress */ |
353 | 0x02, /* bmAttributes: Bulk */ |
349 | 0x02, /* bmAttributes: Bulk */ |
354 | LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ |
350 | LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ |
355 | HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), |
351 | HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), |
356 | 0x00, /* bInterval: ignore for Bulk transfer */ |
352 | 0x00, /* bInterval: ignore for Bulk transfer */ |
357 | 353 | ||
358 | /*Endpoint IN Descriptor*/ |
354 | /*Endpoint IN Descriptor*/ |
359 | 0x07, /* bLength: Endpoint Descriptor size */ |
355 | 0x07, /* bLength: Endpoint Descriptor size */ |
360 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
356 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
361 | CDC_IN_EP, /* bEndpointAddress */ |
357 | CDC_IN_EP, /* bEndpointAddress */ |
362 | 0x02, /* bmAttributes: Bulk */ |
358 | 0x02, /* bmAttributes: Bulk */ |
Line 364... | Line 360... | ||
364 | HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), |
360 | HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), |
365 | 0x00 /* bInterval: ignore for Bulk transfer */ |
361 | 0x00 /* bInterval: ignore for Bulk transfer */ |
366 | } ; |
362 | } ; |
367 | 363 | ||
368 | __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = |
364 | __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = |
369 | { |
365 | { |
370 | 0x09, /* bLength: Configuation Descriptor size */ |
366 | 0x09, /* bLength: Configuation Descriptor size */ |
371 | USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, |
367 | USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, |
372 | USB_CDC_CONFIG_DESC_SIZ, |
368 | USB_CDC_CONFIG_DESC_SIZ, |
373 | 0x00, |
369 | 0x00, |
374 | 0x02, /* bNumInterfaces: 2 interfaces */ |
370 | 0x02, /* bNumInterfaces: 2 interfaces */ |
375 | 0x01, /* bConfigurationValue: */ |
371 | 0x01, /* bConfigurationValue: */ |
376 | 0x04, /* iConfiguration: */ |
372 | 0x04, /* iConfiguration: */ |
377 | 0xC0, /* bmAttributes: */ |
373 | 0xC0, /* bmAttributes: */ |
378 | 0x32, /* MaxPower 100 mA */ |
374 | 0x32, /* MaxPower 100 mA */ |
379 | 375 | ||
380 | /*Interface Descriptor */ |
376 | /*Interface Descriptor */ |
381 | 0x09, /* bLength: Interface Descriptor size */ |
377 | 0x09, /* bLength: Interface Descriptor size */ |
382 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
378 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
383 | /* Interface descriptor type */ |
379 | /* Interface descriptor type */ |
384 | 0x00, /* bInterfaceNumber: Number of Interface */ |
380 | 0x00, /* bInterfaceNumber: Number of Interface */ |
Line 386... | Line 382... | ||
386 | 0x01, /* bNumEndpoints: One endpoints used */ |
382 | 0x01, /* bNumEndpoints: One endpoints used */ |
387 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
383 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
388 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
384 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
389 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
385 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
390 | 0x00, /* iInterface: */ |
386 | 0x00, /* iInterface: */ |
391 | 387 | ||
392 | /*Header Functional Descriptor*/ |
388 | /*Header Functional Descriptor*/ |
393 | 0x05, /* bLength: Endpoint Descriptor size */ |
389 | 0x05, /* bLength: Endpoint Descriptor size */ |
394 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
390 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
395 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
391 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
396 | 0x10, /* bcdCDC: spec release number */ |
392 | 0x10, /* bcdCDC: spec release number */ |
397 | 0x01, |
393 | 0x01, |
398 | 394 | ||
399 | /*Call Management Functional Descriptor*/ |
395 | /*Call Management Functional Descriptor*/ |
400 | 0x05, /* bFunctionLength */ |
396 | 0x05, /* bFunctionLength */ |
401 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
397 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
402 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
398 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
403 | 0x00, /* bmCapabilities: D0+D1 */ |
399 | 0x00, /* bmCapabilities: D0+D1 */ |
404 | 0x01, /* bDataInterface: 1 */ |
400 | 0x01, /* bDataInterface: 1 */ |
405 | 401 | ||
406 | /*ACM Functional Descriptor*/ |
402 | /*ACM Functional Descriptor*/ |
407 | 0x04, /* bFunctionLength */ |
403 | 0x04, /* bFunctionLength */ |
408 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
404 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
409 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
405 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
410 | 0x02, /* bmCapabilities */ |
406 | 0x02, /* bmCapabilities */ |
411 | 407 | ||
412 | /*Union Functional Descriptor*/ |
408 | /*Union Functional Descriptor*/ |
413 | 0x05, /* bFunctionLength */ |
409 | 0x05, /* bFunctionLength */ |
414 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
410 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
415 | 0x06, /* bDescriptorSubtype: Union func desc */ |
411 | 0x06, /* bDescriptorSubtype: Union func desc */ |
416 | 0x00, /* bMasterInterface: Communication class interface */ |
412 | 0x00, /* bMasterInterface: Communication class interface */ |
417 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
413 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
418 | 414 | ||
419 | /*Endpoint 2 Descriptor*/ |
415 | /*Endpoint 2 Descriptor*/ |
420 | 0x07, /* bLength: Endpoint Descriptor size */ |
416 | 0x07, /* bLength: Endpoint Descriptor size */ |
421 | USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */ |
417 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
422 | CDC_CMD_EP, /* bEndpointAddress */ |
418 | CDC_CMD_EP, /* bEndpointAddress */ |
423 | 0x03, /* bmAttributes: Interrupt */ |
419 | 0x03, /* bmAttributes: Interrupt */ |
424 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
420 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
425 | HIBYTE(CDC_CMD_PACKET_SIZE), |
421 | HIBYTE(CDC_CMD_PACKET_SIZE), |
426 | 0xFF, /* bInterval: */ |
422 | CDC_FS_BINTERVAL, /* bInterval: */ |
427 | 423 | ||
428 | /*---------------------------------------------------------------------------*/ |
424 | /*---------------------------------------------------------------------------*/ |
429 | 425 | ||
430 | /*Data class interface descriptor*/ |
426 | /*Data class interface descriptor*/ |
431 | 0x09, /* bLength: Endpoint Descriptor size */ |
427 | 0x09, /* bLength: Endpoint Descriptor size */ |
432 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
428 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
433 | 0x01, /* bInterfaceNumber: Number of Interface */ |
429 | 0x01, /* bInterfaceNumber: Number of Interface */ |
434 | 0x00, /* bAlternateSetting: Alternate setting */ |
430 | 0x00, /* bAlternateSetting: Alternate setting */ |
435 | 0x02, /* bNumEndpoints: Two endpoints used */ |
431 | 0x02, /* bNumEndpoints: Two endpoints used */ |
436 | 0x0A, /* bInterfaceClass: CDC */ |
432 | 0x0A, /* bInterfaceClass: CDC */ |
437 | 0x00, /* bInterfaceSubClass: */ |
433 | 0x00, /* bInterfaceSubClass: */ |
438 | 0x00, /* bInterfaceProtocol: */ |
434 | 0x00, /* bInterfaceProtocol: */ |
439 | 0x00, /* iInterface: */ |
435 | 0x00, /* iInterface: */ |
440 | 436 | ||
441 | /*Endpoint OUT Descriptor*/ |
437 | /*Endpoint OUT Descriptor*/ |
442 | 0x07, /* bLength: Endpoint Descriptor size */ |
438 | 0x07, /* bLength: Endpoint Descriptor size */ |
443 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
439 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
444 | CDC_OUT_EP, /* bEndpointAddress */ |
440 | CDC_OUT_EP, /* bEndpointAddress */ |
445 | 0x02, /* bmAttributes: Bulk */ |
441 | 0x02, /* bmAttributes: Bulk */ |
446 | 0x40, /* wMaxPacketSize: */ |
442 | 0x40, /* wMaxPacketSize: */ |
447 | 0x00, |
443 | 0x00, |
448 | 0x00, /* bInterval: ignore for Bulk transfer */ |
444 | 0x00, /* bInterval: ignore for Bulk transfer */ |
449 | 445 | ||
450 | /*Endpoint IN Descriptor*/ |
446 | /*Endpoint IN Descriptor*/ |
451 | 0x07, /* bLength: Endpoint Descriptor size */ |
447 | 0x07, /* bLength: Endpoint Descriptor size */ |
452 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
448 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
453 | CDC_IN_EP, /* bEndpointAddress */ |
449 | CDC_IN_EP, /* bEndpointAddress */ |
454 | 0x02, /* bmAttributes: Bulk */ |
450 | 0x02, /* bmAttributes: Bulk */ |
Line 457... | Line 453... | ||
457 | 0x00 /* bInterval */ |
453 | 0x00 /* bInterval */ |
458 | }; |
454 | }; |
459 | 455 | ||
460 | /** |
456 | /** |
461 | * @} |
457 | * @} |
462 | */ |
458 | */ |
463 | 459 | ||
464 | /** @defgroup USBD_CDC_Private_Functions |
460 | /** @defgroup USBD_CDC_Private_Functions |
465 | * @{ |
461 | * @{ |
466 | */ |
462 | */ |
467 | 463 | ||
468 | /** |
464 | /** |
469 | * @brief USBD_CDC_Init |
465 | * @brief USBD_CDC_Init |
470 | * Initialize the CDC interface |
466 | * Initialize the CDC interface |
471 | * @param pdev: device instance |
467 | * @param pdev: device instance |
472 | * @param cfgidx: Configuration index |
468 | * @param cfgidx: Configuration index |
473 | * @retval status |
469 | * @retval status |
474 | */ |
470 | */ |
475 | static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, |
471 | static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
476 | uint8_t cfgidx) |
- | |
477 | { |
472 | { |
478 | uint8_t ret = 0; |
473 | uint8_t ret = 0U; |
479 | USBD_CDC_HandleTypeDef *hcdc; |
474 | USBD_CDC_HandleTypeDef *hcdc; |
480 | 475 | ||
481 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
476 | if (pdev->dev_speed == USBD_SPEED_HIGH) |
482 | { |
477 | { |
483 | /* Open EP IN */ |
478 | /* Open EP IN */ |
484 | USBD_LL_OpenEP(pdev, |
- | |
485 | CDC_IN_EP, |
- | |
486 | USBD_EP_TYPE_BULK, |
479 | USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK, |
487 | CDC_DATA_HS_IN_PACKET_SIZE); |
480 | CDC_DATA_HS_IN_PACKET_SIZE); |
- | 481 | ||
- | 482 | pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U; |
|
488 | 483 | ||
489 | /* Open EP OUT */ |
484 | /* Open EP OUT */ |
490 | USBD_LL_OpenEP(pdev, |
- | |
491 | CDC_OUT_EP, |
- | |
492 | USBD_EP_TYPE_BULK, |
485 | USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK, |
493 | CDC_DATA_HS_OUT_PACKET_SIZE); |
486 | CDC_DATA_HS_OUT_PACKET_SIZE); |
- | 487 | ||
- | 488 | pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U; |
|
494 | 489 | ||
495 | } |
490 | } |
496 | else |
491 | else |
497 | { |
492 | { |
498 | /* Open EP IN */ |
493 | /* Open EP IN */ |
499 | USBD_LL_OpenEP(pdev, |
- | |
500 | CDC_IN_EP, |
- | |
501 | USBD_EP_TYPE_BULK, |
494 | USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK, |
502 | CDC_DATA_FS_IN_PACKET_SIZE); |
495 | CDC_DATA_FS_IN_PACKET_SIZE); |
- | 496 | ||
- | 497 | pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U; |
|
503 | 498 | ||
504 | /* Open EP OUT */ |
499 | /* Open EP OUT */ |
505 | USBD_LL_OpenEP(pdev, |
- | |
506 | CDC_OUT_EP, |
- | |
507 | USBD_EP_TYPE_BULK, |
500 | USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK, |
508 | CDC_DATA_FS_OUT_PACKET_SIZE); |
501 | CDC_DATA_FS_OUT_PACKET_SIZE); |
- | 502 | ||
- | 503 | pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U; |
|
509 | } |
504 | } |
510 | /* Open Command IN EP */ |
505 | /* Open Command IN EP */ |
511 | USBD_LL_OpenEP(pdev, |
- | |
512 | CDC_CMD_EP, |
- | |
513 | USBD_EP_TYPE_INTR, |
506 | USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE); |
514 | CDC_CMD_PACKET_SIZE); |
507 | pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U; |
515 | 508 | ||
516 | - | ||
517 | pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef)); |
509 | pdev->pClassData = USBD_malloc(sizeof(USBD_CDC_HandleTypeDef)); |
518 | 510 | ||
519 | if(pdev->pClassData == NULL) |
511 | if (pdev->pClassData == NULL) |
520 | { |
512 | { |
521 | ret = 1; |
513 | ret = 1U; |
522 | } |
514 | } |
523 | else |
515 | else |
524 | { |
516 | { |
525 | hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
517 | hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; |
526 | 518 | ||
527 | /* Init physical Interface components */ |
519 | /* Init physical Interface components */ |
528 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init(); |
520 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init(); |
529 | 521 | ||
530 | /* Init Xfer states */ |
522 | /* Init Xfer states */ |
531 | hcdc->TxState =0; |
523 | hcdc->TxState = 0U; |
532 | hcdc->RxState =0; |
524 | hcdc->RxState = 0U; |
533 | 525 | ||
534 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
526 | if (pdev->dev_speed == USBD_SPEED_HIGH) |
535 | { |
527 | { |
536 | /* Prepare Out endpoint to receive next packet */ |
528 | /* Prepare Out endpoint to receive next packet */ |
537 | USBD_LL_PrepareReceive(pdev, |
529 | USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, |
538 | CDC_OUT_EP, |
- | |
539 | hcdc->RxBuffer, |
- | |
540 | CDC_DATA_HS_OUT_PACKET_SIZE); |
530 | CDC_DATA_HS_OUT_PACKET_SIZE); |
541 | } |
531 | } |
542 | else |
532 | else |
543 | { |
533 | { |
544 | /* Prepare Out endpoint to receive next packet */ |
534 | /* Prepare Out endpoint to receive next packet */ |
545 | USBD_LL_PrepareReceive(pdev, |
535 | USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, |
546 | CDC_OUT_EP, |
- | |
547 | hcdc->RxBuffer, |
- | |
548 | CDC_DATA_FS_OUT_PACKET_SIZE); |
536 | CDC_DATA_FS_OUT_PACKET_SIZE); |
549 | } |
537 | } |
550 | - | ||
551 | - | ||
552 | } |
538 | } |
553 | return ret; |
539 | return ret; |
554 | } |
540 | } |
555 | 541 | ||
556 | /** |
542 | /** |
Line 558... | Line 544... | ||
558 | * DeInitialize the CDC layer |
544 | * DeInitialize the CDC layer |
559 | * @param pdev: device instance |
545 | * @param pdev: device instance |
560 | * @param cfgidx: Configuration index |
546 | * @param cfgidx: Configuration index |
561 | * @retval status |
547 | * @retval status |
562 | */ |
548 | */ |
563 | static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, |
549 | static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
564 | uint8_t cfgidx) |
- | |
565 | { |
550 | { |
566 | uint8_t ret = 0; |
551 | uint8_t ret = 0U; |
567 | 552 | ||
568 | /* Open EP IN */ |
553 | /* Close EP IN */ |
569 | USBD_LL_CloseEP(pdev, |
554 | USBD_LL_CloseEP(pdev, CDC_IN_EP); |
570 | CDC_IN_EP); |
555 | pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 0U; |
571 | 556 | ||
572 | /* Open EP OUT */ |
557 | /* Close EP OUT */ |
573 | USBD_LL_CloseEP(pdev, |
558 | USBD_LL_CloseEP(pdev, CDC_OUT_EP); |
574 | CDC_OUT_EP); |
559 | pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 0U; |
575 | 560 | ||
576 | /* Open Command IN EP */ |
561 | /* Close Command IN EP */ |
577 | USBD_LL_CloseEP(pdev, |
562 | USBD_LL_CloseEP(pdev, CDC_CMD_EP); |
578 | CDC_CMD_EP); |
563 | pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U; |
579 | - | ||
580 | 564 | ||
581 | /* DeInit physical Interface components */ |
565 | /* DeInit physical Interface components */ |
582 | if(pdev->pClassData != NULL) |
566 | if (pdev->pClassData != NULL) |
583 | { |
567 | { |
584 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit(); |
568 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit(); |
585 | USBD_free(pdev->pClassData); |
569 | USBD_free(pdev->pClassData); |
586 | pdev->pClassData = NULL; |
570 | pdev->pClassData = NULL; |
587 | } |
571 | } |
588 | 572 | ||
589 | return ret; |
573 | return ret; |
590 | } |
574 | } |
591 | 575 | ||
592 | /** |
576 | /** |
593 | * @brief USBD_CDC_Setup |
577 | * @brief USBD_CDC_Setup |
594 | * Handle the CDC specific requests |
578 | * Handle the CDC specific requests |
595 | * @param pdev: instance |
579 | * @param pdev: instance |
596 | * @param req: usb requests |
580 | * @param req: usb requests |
597 | * @retval status |
581 | * @retval status |
598 | */ |
582 | */ |
599 | static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, |
583 | static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, |
600 | USBD_SetupReqTypedef *req) |
584 | USBD_SetupReqTypedef *req) |
601 | { |
585 | { |
602 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
586 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; |
603 | static uint8_t ifalt = 0; |
587 | uint8_t ifalt = 0U; |
- | 588 | uint16_t status_info = 0U; |
|
- | 589 | uint8_t ret = USBD_OK; |
|
604 | 590 | ||
605 | switch (req->bmRequest & USB_REQ_TYPE_MASK) |
591 | switch (req->bmRequest & USB_REQ_TYPE_MASK) |
606 | { |
592 | { |
607 | case USB_REQ_TYPE_CLASS : |
593 | case USB_REQ_TYPE_CLASS : |
608 | if (req->wLength) |
594 | if (req->wLength) |
609 | { |
- | |
610 | if (req->bmRequest & 0x80) |
- | |
611 | { |
595 | { |
- | 596 | if (req->bmRequest & 0x80U) |
|
- | 597 | { |
|
612 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, |
598 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, |
613 | (uint8_t *)hcdc->data, |
599 | (uint8_t *)(void *)hcdc->data, |
614 | req->wLength); |
600 | req->wLength); |
- | 601 | ||
- | 602 | USBD_CtlSendData(pdev, (uint8_t *)(void *)hcdc->data, req->wLength); |
|
- | 603 | } |
|
- | 604 | else |
|
- | 605 | { |
|
615 | USBD_CtlSendData (pdev, |
606 | hcdc->CmdOpCode = req->bRequest; |
616 | (uint8_t *)hcdc->data, |
607 | hcdc->CmdLength = (uint8_t)req->wLength; |
- | 608 | ||
617 | req->wLength); |
609 | USBD_CtlPrepareRx(pdev, (uint8_t *)(void *)hcdc->data, req->wLength); |
- | 610 | } |
|
618 | } |
611 | } |
619 | else |
612 | else |
620 | { |
613 | { |
621 | hcdc->CmdOpCode = req->bRequest; |
614 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, |
622 | hcdc->CmdLength = req->wLength; |
- | |
623 | - | ||
624 | USBD_CtlPrepareRx (pdev, |
- | |
625 | (uint8_t *)hcdc->data, |
615 | (uint8_t *)(void *)req, 0U); |
626 | req->wLength); |
- | |
627 | } |
616 | } |
628 | - | ||
629 | } |
- | |
630 | else |
- | |
631 | { |
- | |
632 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, |
- | |
633 | (uint8_t*)req, |
- | |
634 | 0); |
- | |
635 | } |
- | |
636 | break; |
617 | break; |
637 | 618 | ||
638 | case USB_REQ_TYPE_STANDARD: |
619 | case USB_REQ_TYPE_STANDARD: |
639 | switch (req->bRequest) |
620 | switch (req->bRequest) |
- | 621 | { |
|
- | 622 | case USB_REQ_GET_STATUS: |
|
- | 623 | if (pdev->dev_state == USBD_STATE_CONFIGURED) |
|
- | 624 | { |
|
- | 625 | USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U); |
|
- | 626 | } |
|
- | 627 | else |
|
- | 628 | { |
|
- | 629 | USBD_CtlError(pdev, req); |
|
- | 630 | ret = USBD_FAIL; |
|
640 | { |
631 | } |
- | 632 | break; |
|
- | 633 | ||
641 | case USB_REQ_GET_INTERFACE : |
634 | case USB_REQ_GET_INTERFACE: |
- | 635 | if (pdev->dev_state == USBD_STATE_CONFIGURED) |
|
- | 636 | { |
|
642 | USBD_CtlSendData (pdev, |
637 | USBD_CtlSendData(pdev, &ifalt, 1U); |
- | 638 | } |
|
- | 639 | else |
|
- | 640 | { |
|
- | 641 | USBD_CtlError(pdev, req); |
|
643 | &ifalt, |
642 | ret = USBD_FAIL; |
- | 643 | } |
|
- | 644 | break; |
|
- | 645 | ||
- | 646 | case USB_REQ_SET_INTERFACE: |
|
- | 647 | if (pdev->dev_state != USBD_STATE_CONFIGURED) |
|
- | 648 | { |
|
- | 649 | USBD_CtlError(pdev, req); |
|
644 | 1); |
650 | ret = USBD_FAIL; |
- | 651 | } |
|
- | 652 | break; |
|
- | 653 | ||
- | 654 | default: |
|
- | 655 | USBD_CtlError(pdev, req); |
|
- | 656 | ret = USBD_FAIL; |
|
- | 657 | break; |
|
- | 658 | } |
|
645 | break; |
659 | break; |
- | 660 | ||
646 | 661 | default: |
|
647 | case USB_REQ_SET_INTERFACE : |
662 | USBD_CtlError(pdev, req); |
- | 663 | ret = USBD_FAIL; |
|
648 | break; |
664 | break; |
649 | } |
- | |
650 | - | ||
651 | default: |
- | |
652 | break; |
- | |
653 | } |
665 | } |
- | 666 | ||
654 | return USBD_OK; |
667 | return ret; |
655 | } |
668 | } |
656 | 669 | ||
657 | /** |
670 | /** |
658 | * @brief USBD_CDC_DataIn |
671 | * @brief USBD_CDC_DataIn |
659 | * Data sent on non-control IN endpoint |
672 | * Data sent on non-control IN endpoint |
660 | * @param pdev: device instance |
673 | * @param pdev: device instance |
661 | * @param epnum: endpoint number |
674 | * @param epnum: endpoint number |
662 | * @retval status |
675 | * @retval status |
663 | */ |
676 | */ |
664 | static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) |
677 | static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) |
665 | { |
678 | { |
666 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
679 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData; |
- | 680 | PCD_HandleTypeDef *hpcd = pdev->pData; |
|
667 | 681 | ||
668 | if(pdev->pClassData != NULL) |
682 | if (pdev->pClassData != NULL) |
669 | { |
683 | { |
- | 684 | if ((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) |
|
670 | 685 | { |
|
- | 686 | /* Update the packet total length */ |
|
671 | hcdc->TxState = 0; |
687 | pdev->ep_in[epnum].total_length = 0U; |
672 | 688 | ||
- | 689 | /* Send ZLP */ |
|
- | 690 | USBD_LL_Transmit(pdev, epnum, NULL, 0U); |
|
- | 691 | } |
|
- | 692 | else |
|
- | 693 | { |
|
- | 694 | hcdc->TxState = 0U; |
|
- | 695 | } |
|
673 | return USBD_OK; |
696 | return USBD_OK; |
674 | } |
697 | } |
675 | else |
698 | else |
676 | { |
699 | { |
677 | return USBD_FAIL; |
700 | return USBD_FAIL; |
Line 683... | Line 706... | ||
683 | * Data received on non-control Out endpoint |
706 | * Data received on non-control Out endpoint |
684 | * @param pdev: device instance |
707 | * @param pdev: device instance |
685 | * @param epnum: endpoint number |
708 | * @param epnum: endpoint number |
686 | * @retval status |
709 | * @retval status |
687 | */ |
710 | */ |
688 | static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) |
711 | static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) |
689 | { |
712 | { |
690 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
713 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; |
691 | 714 | ||
692 | /* Get the received data length */ |
715 | /* Get the received data length */ |
693 | hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); |
716 | hcdc->RxLength = USBD_LL_GetRxDataSize(pdev, epnum); |
694 | 717 | ||
695 | /* USB data will be immediately processed, this allow next USB traffic being |
718 | /* USB data will be immediately processed, this allow next USB traffic being |
696 | NAKed till the end of the application Xfer */ |
719 | NAKed till the end of the application Xfer */ |
697 | if(pdev->pClassData != NULL) |
720 | if (pdev->pClassData != NULL) |
698 | { |
721 | { |
699 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength); |
722 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength); |
700 | 723 | ||
701 | return USBD_OK; |
724 | return USBD_OK; |
702 | } |
725 | } |
Line 704... | Line 727... | ||
704 | { |
727 | { |
705 | return USBD_FAIL; |
728 | return USBD_FAIL; |
706 | } |
729 | } |
707 | } |
730 | } |
708 | 731 | ||
709 | - | ||
710 | - | ||
711 | /** |
732 | /** |
712 | * @brief USBD_CDC_DataOut |
733 | * @brief USBD_CDC_EP0_RxReady |
713 | * Data received on non-control Out endpoint |
734 | * Handle EP0 Rx Ready event |
714 | * @param pdev: device instance |
735 | * @param pdev: device instance |
715 | * @param epnum: endpoint number |
- | |
716 | * @retval status |
736 | * @retval status |
717 | */ |
737 | */ |
718 | static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) |
738 | static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev) |
719 | { |
739 | { |
720 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
740 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; |
721 | 741 | ||
722 | if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFF)) |
742 | if ((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU)) |
723 | { |
743 | { |
724 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode, |
744 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode, |
725 | (uint8_t *)hcdc->data, |
745 | (uint8_t *)(void *)hcdc->data, |
726 | hcdc->CmdLength); |
746 | (uint16_t)hcdc->CmdLength); |
727 | hcdc->CmdOpCode = 0xFF; |
747 | hcdc->CmdOpCode = 0xFFU; |
728 | 748 | ||
729 | } |
749 | } |
730 | return USBD_OK; |
750 | return USBD_OK; |
731 | } |
751 | } |
732 | 752 | ||
733 | /** |
753 | /** |
734 | * @brief USBD_CDC_GetFSCfgDesc |
754 | * @brief USBD_CDC_GetFSCfgDesc |
735 | * Return configuration descriptor |
755 | * Return configuration descriptor |
736 | * @param speed : current device speed |
756 | * @param speed : current device speed |
737 | * @param length : pointer data length |
757 | * @param length : pointer data length |
738 | * @retval pointer to descriptor buffer |
758 | * @retval pointer to descriptor buffer |
739 | */ |
759 | */ |
740 | static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length) |
760 | static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length) |
741 | { |
761 | { |
742 | *length = sizeof (USBD_CDC_CfgFSDesc); |
762 | *length = sizeof(USBD_CDC_CfgFSDesc); |
743 | return USBD_CDC_CfgFSDesc; |
763 | return USBD_CDC_CfgFSDesc; |
744 | } |
764 | } |
745 | 765 | ||
746 | /** |
766 | /** |
747 | * @brief USBD_CDC_GetHSCfgDesc |
767 | * @brief USBD_CDC_GetHSCfgDesc |
748 | * Return configuration descriptor |
768 | * Return configuration descriptor |
749 | * @param speed : current device speed |
769 | * @param speed : current device speed |
750 | * @param length : pointer data length |
770 | * @param length : pointer data length |
751 | * @retval pointer to descriptor buffer |
771 | * @retval pointer to descriptor buffer |
752 | */ |
772 | */ |
753 | static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length) |
773 | static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length) |
754 | { |
774 | { |
755 | *length = sizeof (USBD_CDC_CfgHSDesc); |
775 | *length = sizeof(USBD_CDC_CfgHSDesc); |
756 | return USBD_CDC_CfgHSDesc; |
776 | return USBD_CDC_CfgHSDesc; |
757 | } |
777 | } |
758 | 778 | ||
759 | /** |
779 | /** |
760 | * @brief USBD_CDC_GetCfgDesc |
780 | * @brief USBD_CDC_GetCfgDesc |
761 | * Return configuration descriptor |
781 | * Return configuration descriptor |
762 | * @param speed : current device speed |
782 | * @param speed : current device speed |
763 | * @param length : pointer data length |
783 | * @param length : pointer data length |
764 | * @retval pointer to descriptor buffer |
784 | * @retval pointer to descriptor buffer |
765 | */ |
785 | */ |
766 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) |
786 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length) |
767 | { |
787 | { |
768 | *length = sizeof (USBD_CDC_OtherSpeedCfgDesc); |
788 | *length = sizeof(USBD_CDC_OtherSpeedCfgDesc); |
769 | return USBD_CDC_OtherSpeedCfgDesc; |
789 | return USBD_CDC_OtherSpeedCfgDesc; |
770 | } |
790 | } |
771 | 791 | ||
772 | /** |
792 | /** |
773 | * @brief DeviceQualifierDescriptor |
793 | * @brief DeviceQualifierDescriptor |
774 | * return Device Qualifier descriptor |
794 | * return Device Qualifier descriptor |
775 | * @param length : pointer data length |
795 | * @param length : pointer data length |
776 | * @retval pointer to descriptor buffer |
796 | * @retval pointer to descriptor buffer |
777 | */ |
797 | */ |
778 | uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length) |
798 | uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length) |
779 | { |
799 | { |
780 | *length = sizeof (USBD_CDC_DeviceQualifierDesc); |
800 | *length = sizeof(USBD_CDC_DeviceQualifierDesc); |
781 | return USBD_CDC_DeviceQualifierDesc; |
801 | return USBD_CDC_DeviceQualifierDesc; |
782 | } |
802 | } |
783 | 803 | ||
784 | /** |
804 | /** |
785 | * @brief USBD_CDC_RegisterInterface |
805 | * @brief USBD_CDC_RegisterInterface |
786 | * @param pdev: device instance |
806 | * @param pdev: device instance |
787 | * @param fops: CD Interface callback |
807 | * @param fops: CD Interface callback |
788 | * @retval status |
808 | * @retval status |
789 | */ |
809 | */ |
790 | uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, |
810 | uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, |
791 | USBD_CDC_ItfTypeDef *fops) |
811 | USBD_CDC_ItfTypeDef *fops) |
792 | { |
812 | { |
793 | uint8_t ret = USBD_FAIL; |
813 | uint8_t ret = USBD_FAIL; |
794 | 814 | ||
795 | if(fops != NULL) |
815 | if (fops != NULL) |
796 | { |
816 | { |
797 | pdev->pUserData= fops; |
817 | pdev->pUserData = fops; |
798 | ret = USBD_OK; |
818 | ret = USBD_OK; |
799 | } |
819 | } |
800 | 820 | ||
801 | return ret; |
821 | return ret; |
802 | } |
822 | } |
803 | 823 | ||
804 | /** |
824 | /** |
805 | * @brief USBD_CDC_SetTxBuffer |
825 | * @brief USBD_CDC_SetTxBuffer |
806 | * @param pdev: device instance |
826 | * @param pdev: device instance |
807 | * @param pbuff: Tx Buffer |
827 | * @param pbuff: Tx Buffer |
808 | * @retval status |
828 | * @retval status |
809 | */ |
829 | */ |
810 | uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, |
830 | uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, |
811 | uint8_t *pbuff, |
831 | uint8_t *pbuff, |
812 | uint16_t length) |
832 | uint16_t length) |
813 | { |
833 | { |
814 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
834 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; |
815 | 835 | ||
816 | hcdc->TxBuffer = pbuff; |
836 | hcdc->TxBuffer = pbuff; |
817 | hcdc->TxLength = length; |
837 | hcdc->TxLength = length; |
818 | 838 | ||
819 | return USBD_OK; |
839 | return USBD_OK; |
820 | } |
840 | } |
821 | 841 | ||
822 | 842 | ||
823 | /** |
843 | /** |
824 | * @brief USBD_CDC_SetRxBuffer |
844 | * @brief USBD_CDC_SetRxBuffer |
825 | * @param pdev: device instance |
845 | * @param pdev: device instance |
826 | * @param pbuff: Rx Buffer |
846 | * @param pbuff: Rx Buffer |
827 | * @retval status |
847 | * @retval status |
828 | */ |
848 | */ |
829 | uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, |
849 | uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, |
830 | uint8_t *pbuff) |
850 | uint8_t *pbuff) |
831 | { |
851 | { |
832 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
852 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; |
833 | 853 | ||
834 | hcdc->RxBuffer = pbuff; |
854 | hcdc->RxBuffer = pbuff; |
835 | 855 | ||
836 | return USBD_OK; |
856 | return USBD_OK; |
837 | } |
857 | } |
838 | 858 | ||
839 | /** |
859 | /** |
840 | * @brief USBD_CDC_DataOut |
860 | * @brief USBD_CDC_TransmitPacket |
841 | * Data received on non-control Out endpoint |
861 | * Transmit packet on IN endpoint |
842 | * @param pdev: device instance |
862 | * @param pdev: device instance |
843 | * @param epnum: endpoint number |
- | |
844 | * @retval status |
863 | * @retval status |
845 | */ |
864 | */ |
846 | uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) |
865 | uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) |
847 | { |
866 | { |
848 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
867 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; |
849 | 868 | ||
850 | if(pdev->pClassData != NULL) |
869 | if (pdev->pClassData != NULL) |
851 | { |
870 | { |
852 | if(hcdc->TxState == 0) |
871 | if (hcdc->TxState == 0U) |
853 | { |
872 | { |
854 | /* Tx Transfer in progress */ |
873 | /* Tx Transfer in progress */ |
855 | hcdc->TxState = 1; |
874 | hcdc->TxState = 1U; |
- | 875 | ||
- | 876 | /* Update the packet total length */ |
|
- | 877 | pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength; |
|
856 | 878 | ||
857 | /* Transmit next packet */ |
879 | /* Transmit next packet */ |
858 | USBD_LL_Transmit(pdev, |
880 | USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer, |
859 | CDC_IN_EP, |
- | |
860 | hcdc->TxBuffer, |
- | |
861 | hcdc->TxLength); |
881 | (uint16_t)hcdc->TxLength); |
862 | 882 | ||
863 | return USBD_OK; |
883 | return USBD_OK; |
864 | } |
884 | } |
865 | else |
885 | else |
866 | { |
886 | { |
867 | return USBD_BUSY; |
887 | return USBD_BUSY; |
Line 879... | Line 899... | ||
879 | * prepare OUT Endpoint for reception |
899 | * prepare OUT Endpoint for reception |
880 | * @param pdev: device instance |
900 | * @param pdev: device instance |
881 | * @retval status |
901 | * @retval status |
882 | */ |
902 | */ |
883 | uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) |
903 | uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) |
884 | { |
904 | { |
885 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
905 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; |
886 | 906 | ||
887 | /* Suspend or Resume USB Out process */ |
907 | /* Suspend or Resume USB Out process */ |
888 | if(pdev->pClassData != NULL) |
908 | if (pdev->pClassData != NULL) |
889 | { |
909 | { |
890 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
910 | if (pdev->dev_speed == USBD_SPEED_HIGH) |
891 | { |
911 | { |
892 | /* Prepare Out endpoint to receive next packet */ |
912 | /* Prepare Out endpoint to receive next packet */ |
893 | USBD_LL_PrepareReceive(pdev, |
913 | USBD_LL_PrepareReceive(pdev, |
894 | CDC_OUT_EP, |
914 | CDC_OUT_EP, |
895 | hcdc->RxBuffer, |
915 | hcdc->RxBuffer, |
896 | CDC_DATA_HS_OUT_PACKET_SIZE); |
916 | CDC_DATA_HS_OUT_PACKET_SIZE); |
Line 910... | Line 930... | ||
910 | return USBD_FAIL; |
930 | return USBD_FAIL; |
911 | } |
931 | } |
912 | } |
932 | } |
913 | /** |
933 | /** |
914 | * @} |
934 | * @} |
915 | */ |
935 | */ |
916 | 936 | ||
917 | /** |
937 | /** |
918 | * @} |
938 | * @} |
919 | */ |
939 | */ |
920 | 940 | ||
921 | /** |
941 | /** |
922 | * @} |
942 | * @} |
923 | */ |
943 | */ |
924 | 944 | ||
925 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
945 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |