tinyusb_hw_defaults.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Gunar Schorcht
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
34 #ifndef TINYUSB_HW_DEFAULTS_H
35 #define TINYUSB_HW_DEFAULTS_H
36 
37 #include "periph_conf.h"
38 
39 #if !DOXYGEN
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
63 #if defined(DWC2_USB_OTG_HS_ENABLED) && defined(DWC2_USB_OTG_FS_ENABLED)
64 
65 #ifndef TINYUSB_TUD_RHPORT
66 #define TINYUSB_TUD_RHPORT 0
67 #endif
68 
69 #ifndef TINYUSB_TUH_RHPORT
70 #define TINYUSB_TUH_RHPORT 1
71 #endif
72 
73 #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)
74 #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
75 
76 #elif defined(DWC2_USB_OTG_HS_ENABLED)
77 
78 #ifndef TINYUSB_TUD_RHPORT
79 #define TINYUSB_TUD_RHPORT 1
80 #endif
81 
82 #ifndef TINYUSB_TUH_RHPORT
83 #define TINYUSB_TUH_RHPORT 1
84 #endif
85 
86 /*
87  * Only if the module `periph_usbdev_hs_utmi` or `periph_usbdev_hs_ulpi` is
88  * enabled for the HS port, a HS PHY is used and OPT_MODE_HIGH_SPEED must be
89  * set. Otherwise, the built-in on-chip FS PHY is used and
90  * OPT_MODE_DEFAULT_SPEED should be set so tinyUSB can select the correct speed.
91  */
92 #if (MODULE_PERIPH_USBDEV_HS_UTMI || MODULE_PERIPH_USBDEV_HS_ULPI)
93 #define TINYUSB_OPT_SPEED OPT_MODE_HIGH_SPEED
94 #else
95 #define TINYUSB_OPT_SPEED OPT_MODE_DEFAULT_SPEED
96 #endif
97 
98 /*
99  * Since tinyUSB does not support host mode for STM32 MCUs yet, only
100  * OPT_MODE_DEVICE is enabled for the port. Once tinyUSB supports the host mode,
101  * OPT_MODE_HOST could be added to CFG_TUSB_RHPORT1_MODE
102  */
103 #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | TINYUSB_OPT_SPEED)
104 
105 #else
106 
107 #ifndef TINYUSB_TUD_RHPORT
108 #define TINYUSB_TUD_RHPORT 0
109 #endif
110 
111 #ifndef TINYUSB_TUH_RHPORT
112 #define TINYUSB_TUH_RHPORT 0
113 #endif
114 
115 /*
116  * Since tinyUSB does not support host mode for STM32 MCUs yet, only
117  * OPT_MODE_DEVICE is enabled for the port. Once tinyUSB supports the host mode,
118  * OPT_MODE_HOST could be added to CFG_TUSB_RHPORT0_MODE.
119  */
120 #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)
121 
122 #endif
125 #ifdef USB_HS_PHYC
132 #define HSE_VALUE CONFIG_CLOCK_HSE
133 #endif
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif /* !DOXYGEN */
140 #endif /* TINYUSB_HW_DEFAULTS_H */