|
20 | 20 | * |
21 | 21 | * http://www.st.com/software_license_agreement_liberty_v2 |
22 | 22 | * |
23 | | - * Unless required by applicable law or agreed to in writing, software |
24 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
| 23 | + * Unless required by applicable law or agreed to in writing, software |
| 24 | + * distributed under the License is distributed on an "AS IS" BASIS, |
25 | 25 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
26 | 26 | * See the License for the specific language governing permissions and |
27 | 27 | * limitations under the License. |
28 | 28 | * |
29 | 29 | ****************************************************************************** |
30 | 30 | */ |
31 | 31 |
|
32 | | -/* Includes ------------------------------------------------------------------*/ |
33 | 32 | #include "usbd_core.h" |
34 | 33 | #include "usbd_desc.h" |
35 | 34 | #include "usbd_conf.h" |
36 | 35 |
|
37 | | -/* Private typedef -----------------------------------------------------------*/ |
38 | | -/* Private define ------------------------------------------------------------*/ |
39 | | - |
40 | 36 | // So we don't clash with existing ST boards, we use the unofficial FOSS VID. |
41 | 37 | // This needs a proper solution. |
42 | 38 | #define USBD_VID 0xf055 |
|
52 | 48 | #define USBD_CONFIGURATION_FS_STRING "VCP Config" |
53 | 49 | #define USBD_INTERFACE_FS_STRING "VCP Interface" |
54 | 50 |
|
55 | | -/* |
56 | | -#define USBD_VID 0x0483 |
57 | | -#define USBD_PID 0x5740 |
58 | | -#define USBD_LANGID_STRING 0x409 |
59 | | -#define USBD_MANUFACTURER_STRING "STMicroelectronics" |
60 | | -#define USBD_PRODUCT_HS_STRING "STM32 Virtual ComPort in HS Mode" |
61 | | -#define USBD_SERIALNUMBER_HS_STRING "00000000001A" |
62 | | -#define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode" |
63 | | -#define USBD_SERIALNUMBER_FS_STRING "00000000001B" |
64 | | -#define USBD_CONFIGURATION_HS_STRING "VCP Config" |
65 | | -#define USBD_INTERFACE_HS_STRING "VCP Interface" |
66 | | -#define USBD_CONFIGURATION_FS_STRING "VCP Config" |
67 | | -#define USBD_INTERFACE_FS_STRING "VCP Interface" |
68 | | -*/ |
69 | | - |
70 | | -/* Private macro -------------------------------------------------------------*/ |
71 | | -/* Private function prototypes -----------------------------------------------*/ |
72 | | -uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
73 | | -uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
74 | | -uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
75 | | -uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
76 | | -uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
77 | | -uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
78 | | -uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
79 | | -#ifdef USB_SUPPORT_USER_STRING_DESC |
80 | | -uint8_t *USBD_VCP_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); |
81 | | -#endif /* USB_SUPPORT_USER_STRING_DESC */ |
82 | | - |
83 | | -/* Private variables ---------------------------------------------------------*/ |
84 | | -const USBD_DescriptorsTypeDef VCP_Desc = { |
85 | | - USBD_VCP_DeviceDescriptor, |
86 | | - USBD_VCP_LangIDStrDescriptor, |
87 | | - USBD_VCP_ManufacturerStrDescriptor, |
88 | | - USBD_VCP_ProductStrDescriptor, |
89 | | - USBD_VCP_SerialStrDescriptor, |
90 | | - USBD_VCP_ConfigStrDescriptor, |
91 | | - USBD_VCP_InterfaceStrDescriptor, |
| 51 | +// USB Standard Device Descriptor |
| 52 | +__ALIGN_BEGIN static uint8_t hUSBDDeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { |
| 53 | + 0x12, // bLength |
| 54 | + USB_DESC_TYPE_DEVICE, // bDescriptorType |
| 55 | + 0x00, // bcdUSB |
| 56 | + 0x02, |
| 57 | + 0x00, // bDeviceClass |
| 58 | + 0x00, // bDeviceSubClass |
| 59 | + 0x00, // bDeviceProtocol |
| 60 | + USB_MAX_EP0_SIZE, // bMaxPacketSize |
| 61 | + LOBYTE(USBD_VID), // idVendor |
| 62 | + HIBYTE(USBD_VID), // idVendor |
| 63 | + LOBYTE(USBD_PID), // idVendor |
| 64 | + HIBYTE(USBD_PID), // idVendor |
| 65 | + 0x00, // bcdDevice rel. 2.00 |
| 66 | + 0x02, |
| 67 | + USBD_IDX_MFC_STR, // Index of manufacturer string |
| 68 | + USBD_IDX_PRODUCT_STR, // Index of product string |
| 69 | + USBD_IDX_SERIAL_STR, // Index of serial number string |
| 70 | + USBD_MAX_NUM_CONFIGURATION // bNumConfigurations |
92 | 71 | }; |
93 | 72 |
|
94 | | -/* USB Standard Device Descriptor */ |
95 | | -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ |
96 | | - #pragma data_alignment=4 |
97 | | -#endif |
98 | | -__ALIGN_BEGIN static uint8_t hUSBDDeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { |
99 | | - 0x12, /* bLength */ |
100 | | - USB_DESC_TYPE_DEVICE, /* bDescriptorType */ |
101 | | - 0x00, /* bcdUSB */ |
102 | | - 0x02, |
103 | | - 0x00, /* bDeviceClass */ |
104 | | - 0x00, /* bDeviceSubClass */ |
105 | | - 0x00, /* bDeviceProtocol */ |
106 | | - USB_MAX_EP0_SIZE, /* bMaxPacketSize */ |
107 | | - LOBYTE(USBD_VID), /* idVendor */ |
108 | | - HIBYTE(USBD_VID), /* idVendor */ |
109 | | - LOBYTE(USBD_PID), /* idVendor */ |
110 | | - HIBYTE(USBD_PID), /* idVendor */ |
111 | | - 0x00, /* bcdDevice rel. 2.00 */ |
112 | | - 0x02, |
113 | | - USBD_IDX_MFC_STR, /* Index of manufacturer string */ |
114 | | - USBD_IDX_PRODUCT_STR, /* Index of product string */ |
115 | | - USBD_IDX_SERIAL_STR, /* Index of serial number string */ |
116 | | - USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */ |
117 | | -}; /* USB_DeviceDescriptor */ |
118 | | - |
119 | | -/* USB Standard Device Descriptor */ |
120 | | -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ |
121 | | - #pragma data_alignment=4 |
122 | | -#endif |
123 | 73 | __ALIGN_BEGIN static uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = { |
124 | | - USB_LEN_LANGID_STR_DESC, |
125 | | - USB_DESC_TYPE_STRING, |
126 | | - LOBYTE(USBD_LANGID_STRING), |
127 | | - HIBYTE(USBD_LANGID_STRING), |
| 74 | + USB_LEN_LANGID_STR_DESC, |
| 75 | + USB_DESC_TYPE_STRING, |
| 76 | + LOBYTE(USBD_LANGID_STRING), |
| 77 | + HIBYTE(USBD_LANGID_STRING), |
128 | 78 | }; |
129 | 79 |
|
130 | | -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ |
131 | | - #pragma data_alignment=4 |
132 | | -#endif |
133 | 80 | __ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; |
134 | 81 |
|
135 | | -/* Private functions ---------------------------------------------------------*/ |
| 82 | +// set the PID |
| 83 | +void USBD_SetPID(uint16_t pid) { |
| 84 | + hUSBDDeviceDesc[10] = LOBYTE(pid); |
| 85 | + hUSBDDeviceDesc[11] = HIBYTE(pid); |
| 86 | +} |
136 | 87 |
|
137 | 88 | /** |
138 | | - * @brief Returns the device descriptor. |
| 89 | + * @brief Returns the device descriptor. |
139 | 90 | * @param speed: Current device speed |
140 | 91 | * @param length: Pointer to data length variable |
141 | 92 | * @retval Pointer to descriptor buffer |
142 | 93 | */ |
143 | | -uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
144 | | -{ |
145 | | - *length = sizeof(hUSBDDeviceDesc); |
146 | | - return hUSBDDeviceDesc; |
| 94 | +STATIC uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { |
| 95 | + *length = sizeof(hUSBDDeviceDesc); |
| 96 | + return hUSBDDeviceDesc; |
147 | 97 | } |
148 | 98 |
|
149 | 99 | /** |
150 | | - * @brief Returns the LangID string descriptor. |
| 100 | + * @brief Returns the LangID string descriptor. |
151 | 101 | * @param speed: Current device speed |
152 | 102 | * @param length: Pointer to data length variable |
153 | 103 | * @retval Pointer to descriptor buffer |
154 | 104 | */ |
155 | | -uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
156 | | -{ |
157 | | - *length = sizeof(USBD_LangIDDesc); |
158 | | - return USBD_LangIDDesc; |
| 105 | +STATIC uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { |
| 106 | + *length = sizeof(USBD_LangIDDesc); |
| 107 | + return USBD_LangIDDesc; |
159 | 108 | } |
160 | 109 |
|
161 | 110 | /** |
162 | | - * @brief Returns the product string descriptor. |
| 111 | + * @brief Returns the product string descriptor. |
163 | 112 | * @param speed: Current device speed |
164 | 113 | * @param length: Pointer to data length variable |
165 | 114 | * @retval Pointer to descriptor buffer |
166 | 115 | */ |
167 | | -uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
168 | | -{ |
169 | | - if(speed == 0) |
170 | | - { |
171 | | - USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length); |
172 | | - } |
173 | | - else |
174 | | - { |
175 | | - USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); |
176 | | - } |
177 | | - return USBD_StrDesc; |
| 116 | +STATIC uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { |
| 117 | + if(speed == 0) { |
| 118 | + USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length); |
| 119 | + } else { |
| 120 | + USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); |
| 121 | + } |
| 122 | + return USBD_StrDesc; |
178 | 123 | } |
179 | 124 |
|
180 | 125 | /** |
181 | | - * @brief Returns the manufacturer string descriptor. |
| 126 | + * @brief Returns the manufacturer string descriptor. |
182 | 127 | * @param speed: Current device speed |
183 | 128 | * @param length: Pointer to data length variable |
184 | 129 | * @retval Pointer to descriptor buffer |
185 | 130 | */ |
186 | | -uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
187 | | -{ |
188 | | - USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); |
189 | | - return USBD_StrDesc; |
| 131 | +STATIC uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { |
| 132 | + USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); |
| 133 | + return USBD_StrDesc; |
190 | 134 | } |
191 | 135 |
|
192 | 136 | /** |
193 | | - * @brief Returns the serial number string descriptor. |
| 137 | + * @brief Returns the serial number string descriptor. |
194 | 138 | * @param speed: Current device speed |
195 | 139 | * @param length: Pointer to data length variable |
196 | 140 | * @retval Pointer to descriptor buffer |
197 | 141 | */ |
198 | | -uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
199 | | -{ |
200 | | - if(speed == USBD_SPEED_HIGH) |
201 | | - { |
202 | | - USBD_GetString((uint8_t *)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length); |
203 | | - } |
204 | | - else |
205 | | - { |
206 | | - USBD_GetString((uint8_t *)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length); |
207 | | - } |
208 | | - return USBD_StrDesc; |
| 142 | +STATIC uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { |
| 143 | + if(speed == USBD_SPEED_HIGH) { |
| 144 | + USBD_GetString((uint8_t *)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length); |
| 145 | + } else { |
| 146 | + USBD_GetString((uint8_t *)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length); |
| 147 | + } |
| 148 | + return USBD_StrDesc; |
209 | 149 | } |
210 | 150 |
|
211 | 151 | /** |
212 | | - * @brief Returns the configuration string descriptor. |
| 152 | + * @brief Returns the configuration string descriptor. |
213 | 153 | * @param speed: Current device speed |
214 | 154 | * @param length: Pointer to data length variable |
215 | 155 | * @retval Pointer to descriptor buffer |
216 | 156 | */ |
217 | | -uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
218 | | -{ |
219 | | - if(speed == USBD_SPEED_HIGH) |
220 | | - { |
221 | | - USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length); |
222 | | - } |
223 | | - else |
224 | | - { |
225 | | - USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); |
226 | | - } |
227 | | - return USBD_StrDesc; |
| 157 | +STATIC uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { |
| 158 | + if(speed == USBD_SPEED_HIGH) { |
| 159 | + USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length); |
| 160 | + } else { |
| 161 | + USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); |
| 162 | + } |
| 163 | + return USBD_StrDesc; |
228 | 164 | } |
229 | 165 |
|
230 | 166 | /** |
231 | | - * @brief Returns the interface string descriptor. |
| 167 | + * @brief Returns the interface string descriptor. |
232 | 168 | * @param speed: Current device speed |
233 | 169 | * @param length: Pointer to data length variable |
234 | 170 | * @retval Pointer to descriptor buffer |
235 | 171 | */ |
236 | | -uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
237 | | -{ |
238 | | - if(speed == 0) |
239 | | - { |
240 | | - USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length); |
241 | | - } |
242 | | - else |
243 | | - { |
244 | | - USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length); |
245 | | - } |
246 | | - return USBD_StrDesc; |
| 172 | +STATIC uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { |
| 173 | + if(speed == 0) { |
| 174 | + USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length); |
| 175 | + } else { |
| 176 | + USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length); |
| 177 | + } |
| 178 | + return USBD_StrDesc; |
247 | 179 | } |
248 | 180 |
|
249 | | -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
| 181 | +const USBD_DescriptorsTypeDef VCP_Desc = { |
| 182 | + USBD_VCP_DeviceDescriptor, |
| 183 | + USBD_VCP_LangIDStrDescriptor, |
| 184 | + USBD_VCP_ManufacturerStrDescriptor, |
| 185 | + USBD_VCP_ProductStrDescriptor, |
| 186 | + USBD_VCP_SerialStrDescriptor, |
| 187 | + USBD_VCP_ConfigStrDescriptor, |
| 188 | + USBD_VCP_InterfaceStrDescriptor, |
| 189 | +}; |
250 | 190 |
|
| 191 | +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
0 commit comments