mikroSDK Reference Manual
tusb_mcu.h
1
/*
2
* The MIT License (MIT)
3
*
4
* Copyright (c) 2021, Ha Thach (tinyusb.org)
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to deal
8
* in the Software without restriction, including without limitation the rights
9
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
* THE SOFTWARE.
23
*
24
* This file is part of the TinyUSB stack.
25
*/
26
27
#ifndef TUSB_MCU_H_
28
#define TUSB_MCU_H_
29
30
//--------------------------------------------------------------------+
31
// Port/Platform Specific
32
// TUP stand for TinyUSB Port/Platform (can be renamed)
33
//--------------------------------------------------------------------+
34
35
//------------- Unaligned Memory Access -------------//
36
37
#ifdef __ARM_ARCH
38
// ARM Architecture set __ARM_FEATURE_UNALIGNED to 1 for mcu supports unaligned access
39
#if defined(__ARM_FEATURE_UNALIGNED) && __ARM_FEATURE_UNALIGNED == 1
40
#define TUP_ARCH_STRICT_ALIGN 0
41
#else
42
#define TUP_ARCH_STRICT_ALIGN 1
43
#endif
44
#else
45
// TODO default to strict align for others
46
// Should investigate other architecture such as risv, xtensa, mips for optimal setting
47
#define TUP_ARCH_STRICT_ALIGN 1
48
#endif
49
50
/* USB Controller Attributes for Device, Host or MCU (both)
51
* - ENDPOINT_MAX: max (logical) number of endpoint
52
* - ENDPOINT_EXCLUSIVE_NUMBER: endpoint number with different direction IN and OUT aren't allowed,
53
* e.g EP1 OUT & EP1 IN cannot exist together
54
* - RHPORT_HIGHSPEED: support highspeed with on-chip PHY
55
*/
56
57
//--------------------------------------------------------------------+
58
// NXP
59
//--------------------------------------------------------------------+
60
#if TU_CHECK_MCU(OPT_MCU_LPC11UXX, OPT_MCU_LPC13XX, OPT_MCU_LPC15XX)
61
#define TUP_DCD_ENDPOINT_MAX 5
62
63
#elif TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC40XX)
64
#define TUP_DCD_ENDPOINT_MAX 16
65
#define TUP_USBIP_OHCI
66
#define TUP_OHCI_RHPORTS 2
67
68
#elif TU_CHECK_MCU(OPT_MCU_LPC51UXX)
69
#define TUP_DCD_ENDPOINT_MAX 5
70
71
#elif TU_CHECK_MCU(OPT_MCU_LPC54XXX)
72
// TODO USB0 has 5, USB1 has 6
73
#define TUP_DCD_ENDPOINT_MAX 6
74
75
#elif TU_CHECK_MCU(OPT_MCU_LPC55XX)
76
// TODO USB0 has 5, USB1 has 6
77
#define TUP_DCD_ENDPOINT_MAX 6
78
79
#elif TU_CHECK_MCU(OPT_MCU_LPC18XX, OPT_MCU_LPC43XX)
80
// USB0 has 6 with HS PHY, USB1 has 4 only FS
81
#define TUP_USBIP_CHIPIDEA_HS
82
#define TUP_USBIP_EHCI
83
84
#define TUP_DCD_ENDPOINT_MAX 6
85
#define TUP_RHPORT_HIGHSPEED 1
86
87
#elif TU_CHECK_MCU(OPT_MCU_MCXN9)
88
// USB0 is chipidea FS
89
#define TUP_USBIP_CHIPIDEA_FS
90
#define TUP_USBIP_CHIPIDEA_FS_MCX
91
92
// USB1 is chipidea HS
93
#define TUP_USBIP_CHIPIDEA_HS
94
#define TUP_USBIP_EHCI
95
96
#define TUP_DCD_ENDPOINT_MAX 8
97
#define TUP_RHPORT_HIGHSPEED 1
98
99
#elif TU_CHECK_MCU(OPT_MCU_MIMXRT1XXX)
100
#define TUP_USBIP_CHIPIDEA_HS
101
#define TUP_USBIP_EHCI
102
103
#define TUP_DCD_ENDPOINT_MAX 8
104
#define TUP_RHPORT_HIGHSPEED 1
105
106
#elif TU_CHECK_MCU(OPT_MCU_KINETIS_KL, OPT_MCU_KINETIS_K32L)
107
#define TUP_USBIP_CHIPIDEA_FS
108
#define TUP_USBIP_CHIPIDEA_FS_KINETIS
109
#define TUP_DCD_ENDPOINT_MAX 16
110
111
#elif TU_CHECK_MCU(OPT_MCU_MM32F327X)
112
#define TUP_DCD_ENDPOINT_MAX 16
113
114
//--------------------------------------------------------------------+
115
// Nordic
116
//--------------------------------------------------------------------+
117
#elif TU_CHECK_MCU(OPT_MCU_NRF5X)
118
// 8 CBI + 1 ISO
119
#define TUP_DCD_ENDPOINT_MAX 9
120
121
//--------------------------------------------------------------------+
122
// Microchip
123
//--------------------------------------------------------------------+
124
#elif TU_CHECK_MCU(OPT_MCU_SAMD21, OPT_MCU_SAMD51, OPT_MCU_SAME5X) || \
125
TU_CHECK_MCU(OPT_MCU_SAMD11, OPT_MCU_SAML21, OPT_MCU_SAML22)
126
#define TUP_DCD_ENDPOINT_MAX 8
127
128
#elif TU_CHECK_MCU(OPT_MCU_SAMG)
129
#define TUP_DCD_ENDPOINT_MAX 6
130
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
131
132
#elif TU_CHECK_MCU(OPT_MCU_SAMX7X)
133
#define TUP_DCD_ENDPOINT_MAX 10
134
#define TUP_RHPORT_HIGHSPEED 1
135
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
136
137
#elif TU_CHECK_MCU(OPT_MCU_PIC32MZ)
138
#define TUP_DCD_ENDPOINT_MAX 8
139
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
140
141
#elif TU_CHECK_MCU(OPT_MCU_PIC32MX, OPT_MCU_PIC32MM, OPT_MCU_PIC32MK) || \
142
TU_CHECK_MCU(OPT_MCU_PIC24, OPT_MCU_DSPIC33)
143
#define TUP_DCD_ENDPOINT_MAX 16
144
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
145
146
//--------------------------------------------------------------------+
147
// ST
148
//--------------------------------------------------------------------+
149
#elif TU_CHECK_MCU(OPT_MCU_STM32F0)
150
#define TUP_USBIP_FSDEV
151
#define TUP_USBIP_FSDEV_STM32
152
#define TUP_DCD_ENDPOINT_MAX 8
153
154
#elif TU_CHECK_MCU(OPT_MCU_STM32F1)
155
// - F102, F103 use fsdev
156
// - F105, F107 use dwc2
157
#if defined (STM32F105x8) || defined (STM32F105xB) || defined (STM32F105xC) || \
158
defined (STM32F107xB) || defined (STM32F107xC)
159
#define TUP_USBIP_DWC2
160
#define TUP_USBIP_DWC2_STM32
161
162
#define TUP_DCD_ENDPOINT_MAX 4
163
// Note: STM32F10[23]x[48CDEFG] MCUs are added for MikroE implementation.
164
#elif defined(STM32F102x4) || defined(STM32F102x6) || defined(STM32F102x8) || \
165
defined(STM32F102xB) || defined(STM32F102xC) || defined(STM32F102xD) || \
166
defined(STM32F102xE) || defined(STM32F102xF) || defined(STM32F102xG) || \
167
defined(STM32F103x4) || defined(STM32F103x6) || defined(STM32F103x8) || \
168
defined(STM32F103xB) || defined(STM32F103xC) || defined(STM32F103xD) || \
169
defined(STM32F103xE) || defined(STM32F103xF) || defined(STM32F103xG)
170
#define TUP_USBIP_FSDEV
171
#define TUP_USBIP_FSDEV_STM32
172
#define TUP_DCD_ENDPOINT_MAX 8
173
#else
174
#error "Unsupported STM32F1 mcu"
175
#endif
176
177
#elif TU_CHECK_MCU(OPT_MCU_STM32F2)
178
#define TUP_USBIP_DWC2
179
#define TUP_USBIP_DWC2_STM32
180
181
// FS has 4 ep, HS has 5 ep
182
#define TUP_DCD_ENDPOINT_MAX 6
183
184
#elif TU_CHECK_MCU(OPT_MCU_STM32F3)
185
#define TUP_USBIP_FSDEV
186
#define TUP_USBIP_FSDEV_STM32
187
#define TUP_DCD_ENDPOINT_MAX 8
188
189
#elif TU_CHECK_MCU(OPT_MCU_STM32F4)
190
#define TUP_USBIP_DWC2
191
#define TUP_USBIP_DWC2_STM32
192
193
// For most mcu, FS has 4, HS has 6. TODO 446/469/479 HS has 9
194
#define TUP_DCD_ENDPOINT_MAX 6
195
196
#elif TU_CHECK_MCU(OPT_MCU_STM32F7)
197
#define TUP_USBIP_DWC2
198
#define TUP_USBIP_DWC2_STM32
199
200
// FS has 6, HS has 9
201
#define TUP_DCD_ENDPOINT_MAX 9
202
203
// MCU with on-chip HS Phy
204
#if defined(STM32F723xx) || defined(STM32F730xx) || defined(STM32F733xx)
205
#define TUP_RHPORT_HIGHSPEED 1
// Port0: FS, Port1: HS
206
#endif
207
208
#elif TU_CHECK_MCU(OPT_MCU_STM32H7)
209
#define TUP_USBIP_DWC2
210
#define TUP_USBIP_DWC2_STM32
211
212
#define TUP_DCD_ENDPOINT_MAX 9
213
214
#elif TU_CHECK_MCU(OPT_MCU_STM32G4)
215
// Device controller
216
#define TUP_USBIP_FSDEV
217
#define TUP_USBIP_FSDEV_STM32
218
219
// TypeC controller
220
#define TUP_USBIP_TYPEC_STM32
221
222
#define TUP_DCD_ENDPOINT_MAX 8
223
224
#define TUP_TYPEC_RHPORTS_NUM 1
225
226
#elif TU_CHECK_MCU(OPT_MCU_STM32G0)
227
#define TUP_USBIP_FSDEV
228
#define TUP_USBIP_FSDEV_STM32
229
#define TUP_DCD_ENDPOINT_MAX 8
230
231
#elif TU_CHECK_MCU(OPT_MCU_STM32L0, OPT_MCU_STM32L1)
232
#define TUP_USBIP_FSDEV
233
#define TUP_USBIP_FSDEV_STM32
234
#define TUP_DCD_ENDPOINT_MAX 8
235
236
#elif TU_CHECK_MCU(OPT_MCU_STM32L4)
237
// - L4x2, L4x3 use fsdev
238
// - L4x4, L4x6, L4x7, L4x9 use dwc2
239
#if defined (STM32L475xx) || defined (STM32L476xx) || \
240
defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || \
241
defined (STM32L4A6xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
242
defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || \
243
defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
244
#define TUP_USBIP_DWC2
245
#define TUP_USBIP_DWC2_STM32
246
247
#define TUP_DCD_ENDPOINT_MAX 6
248
#elif defined(STM32L412xx) || defined(STM32L422xx) || defined(STM32L432xx) || defined(STM32L433xx) || \
249
defined(STM32L442xx) || defined(STM32L443xx) || defined(STM32L452xx) || defined(STM32L462xx)
250
#define TUP_USBIP_FSDEV
251
#define TUP_USBIP_FSDEV_STM32
252
#define TUP_DCD_ENDPOINT_MAX 8
253
#else
254
#error "Unsupported STM32L4 mcu"
255
#endif
256
257
#elif TU_CHECK_MCU(OPT_MCU_STM32WB)
258
#define TUP_USBIP_FSDEV
259
#define TUP_USBIP_FSDEV_STM32
260
#define TUP_DCD_ENDPOINT_MAX 8
261
262
#elif TU_CHECK_MCU(OPT_MCU_STM32U5)
263
#define TUP_USBIP_DWC2
264
#define TUP_USBIP_DWC2_STM32
265
#define TUP_DCD_ENDPOINT_MAX 6
266
267
#elif TU_CHECK_MCU(OPT_MCU_STM32L5)
268
#define TUP_USBIP_FSDEV
269
#define TUP_USBIP_FSDEV_STM32
270
#define TUP_DCD_ENDPOINT_MAX 8
271
272
273
//--------------------------------------------------------------------+
274
// Sony
275
//--------------------------------------------------------------------+
276
#elif TU_CHECK_MCU(OPT_MCU_CXD56)
277
#define TUP_DCD_ENDPOINT_MAX 7
278
#define TUP_RHPORT_HIGHSPEED 1
279
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
280
281
//--------------------------------------------------------------------+
282
// TI
283
//--------------------------------------------------------------------+
284
#elif TU_CHECK_MCU(OPT_MCU_MSP430x5xx)
285
#define TUP_DCD_ENDPOINT_MAX 8
286
287
#elif TU_CHECK_MCU(OPT_MCU_MSP432E4, OPT_MCU_TM4C123, OPT_MCU_TM4C129)
288
#define TUP_DCD_ENDPOINT_MAX 8
289
290
//--------------------------------------------------------------------+
291
// ValentyUSB (Litex)
292
//--------------------------------------------------------------------+
293
#elif TU_CHECK_MCU(OPT_MCU_VALENTYUSB_EPTRI)
294
#define TUP_DCD_ENDPOINT_MAX 16
295
296
//--------------------------------------------------------------------+
297
// Nuvoton
298
//--------------------------------------------------------------------+
299
#elif TU_CHECK_MCU(OPT_MCU_NUC121, OPT_MCU_NUC126)
300
#define TUP_DCD_ENDPOINT_MAX 8
301
302
#elif TU_CHECK_MCU(OPT_MCU_NUC120)
303
#define TUP_DCD_ENDPOINT_MAX 6
304
305
#elif TU_CHECK_MCU(OPT_MCU_NUC505)
306
#define TUP_DCD_ENDPOINT_MAX 12
307
#define TUP_RHPORT_HIGHSPEED 1
308
309
//--------------------------------------------------------------------+
310
// Espressif
311
//--------------------------------------------------------------------+
312
#elif TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
313
#define TUP_USBIP_DWC2
314
#define TUP_DCD_ENDPOINT_MAX 6
315
316
//--------------------------------------------------------------------+
317
// Dialog
318
//--------------------------------------------------------------------+
319
#elif TU_CHECK_MCU(OPT_MCU_DA1469X)
320
#define TUP_DCD_ENDPOINT_MAX 4
321
322
//--------------------------------------------------------------------+
323
// Raspberry Pi
324
//--------------------------------------------------------------------+
325
#elif TU_CHECK_MCU(OPT_MCU_RP2040)
326
#define TUP_DCD_ENDPOINT_MAX 16
327
328
#define TU_ATTR_FAST_FUNC __attribute__((section(".time_critical.tinyusb")))
329
330
//--------------------------------------------------------------------+
331
// Silabs
332
//--------------------------------------------------------------------+
333
#elif TU_CHECK_MCU(OPT_MCU_EFM32GG)
334
#define TUP_USBIP_DWC2
335
#define TUP_DCD_ENDPOINT_MAX 7
336
337
//--------------------------------------------------------------------+
338
// Renesas
339
//--------------------------------------------------------------------+
340
#elif TU_CHECK_MCU(OPT_MCU_RX63X, OPT_MCU_RX65X, OPT_MCU_RX72N, OPT_MCU_RAXXX)
341
#define TUP_USBIP_RUSB2
342
#define TUP_DCD_ENDPOINT_MAX 10
343
344
//--------------------------------------------------------------------+
345
// GigaDevice
346
//--------------------------------------------------------------------+
347
#elif TU_CHECK_MCU(OPT_MCU_GD32VF103)
348
#define TUP_USBIP_DWC2
349
#define TUP_DCD_ENDPOINT_MAX 4
350
351
//--------------------------------------------------------------------+
352
// Broadcom
353
//--------------------------------------------------------------------+
354
#elif TU_CHECK_MCU(OPT_MCU_BCM2711, OPT_MCU_BCM2835, OPT_MCU_BCM2837)
355
#define TUP_USBIP_DWC2
356
#define TUP_DCD_ENDPOINT_MAX 8
357
#define TUP_RHPORT_HIGHSPEED 1
358
359
//--------------------------------------------------------------------+
360
// Infineon
361
//--------------------------------------------------------------------+
362
#elif TU_CHECK_MCU(OPT_MCU_XMC4000)
363
#define TUP_USBIP_DWC2
364
#define TUP_DCD_ENDPOINT_MAX 8
365
366
//--------------------------------------------------------------------+
367
// BridgeTek
368
//--------------------------------------------------------------------+
369
#elif TU_CHECK_MCU(OPT_MCU_FT90X)
370
#define TUP_DCD_ENDPOINT_MAX 8
371
#define TUP_RHPORT_HIGHSPEED 1
372
373
#elif TU_CHECK_MCU(OPT_MCU_FT93X)
374
#define TUP_DCD_ENDPOINT_MAX 16
375
#define TUP_RHPORT_HIGHSPEED 1
376
377
//--------------------------------------------------------------------+
378
// Allwinner
379
//--------------------------------------------------------------------+
380
#elif TU_CHECK_MCU(OPT_MCU_F1C100S)
381
#define TUP_DCD_ENDPOINT_MAX 4
382
383
//------------- WCH -------------//
384
#elif TU_CHECK_MCU(OPT_MCU_CH32V307)
385
#define TUP_DCD_ENDPOINT_MAX 16
386
#define TUP_RHPORT_HIGHSPEED 1
387
#endif
388
389
//--------------------------------------------------------------------+
390
// Default Values
391
//--------------------------------------------------------------------+
392
393
#ifndef TUP_MCU_MULTIPLE_CORE
394
#define TUP_MCU_MULTIPLE_CORE 0
395
#endif
396
397
#ifndef TUP_DCD_ENDPOINT_MAX
398
#warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
399
#define TUP_DCD_ENDPOINT_MAX 8
400
#endif
401
402
// Default to fullspeed if not defined
403
#ifndef TUP_RHPORT_HIGHSPEED
404
#define TUP_RHPORT_HIGHSPEED 0
405
#endif
406
407
// fast function, normally mean placing function in SRAM
408
#ifndef TU_ATTR_FAST_FUNC
409
#define TU_ATTR_FAST_FUNC
410
#endif
411
412
#endif