1 /*
2  * Copyright (c) 2022, sakumisu
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef CHERRYUSB_CONFIG_H
7 #define CHERRYUSB_CONFIG_H
8 
9 /* ================ USB common Configuration ================ */
10 
11 #ifdef __RTTHREAD__
12 #include <rtthread.h>
13 
14 #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
15 #else
16 #define CONFIG_USB_PRINTF(...) printf(__VA_ARGS__)
17 #endif
18 
19 #ifndef CONFIG_USB_DBG_LEVEL
20 #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
21 #endif
22 
23 /* Enable print with color */
24 #define CONFIG_USB_PRINTF_COLOR_ENABLE
25 
26 // #define CONFIG_USB_DCACHE_ENABLE
27 
28 /* data align size when use dma or use dcache */
29 #ifdef CONFIG_USB_DCACHE_ENABLE
30 #define CONFIG_USB_ALIGN_SIZE 32 // 32 or 64
31 #else
32 #define CONFIG_USB_ALIGN_SIZE 4
33 #endif
34 
35 /* attribute data into no cache ram */
36 #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
37 
38 /* use usb_memcpy default for high performance but cost more flash memory.
39  * And, arm libc has a bug that memcpy() may cause data misalignment when the size is not a multiple of 4.
40 */
41 // #define CONFIG_USB_MEMCPY_DISABLE
42 
43 /* ================= USB Device Stack Configuration ================ */
44 
45 /* Ep0 in and out transfer buffer */
46 #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
47 #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
48 #endif
49 
50 /* Send ep0 in data from user buffer instead of copying into ep0 reqdata
51  * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
52 */
53 // #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
54 
55 /* Check if the input descriptor is correct */
56 // #define CONFIG_USBDEV_DESC_CHECK
57 
58 /* Enable test mode */
59 // #define CONFIG_USBDEV_TEST_MODE
60 
61 /* enable advance desc register api */
62 #define CONFIG_USBDEV_ADVANCE_DESC
63 
64 /* move ep0 setup handler from isr to thread */
65 // #define CONFIG_USBDEV_EP0_THREAD
66 
67 #ifndef CONFIG_USBDEV_EP0_PRIO
68 #define CONFIG_USBDEV_EP0_PRIO 4
69 #endif
70 
71 #ifndef CONFIG_USBDEV_EP0_STACKSIZE
72 #define CONFIG_USBDEV_EP0_STACKSIZE 2048
73 #endif
74 
75 #ifndef CONFIG_USBDEV_MSC_MAX_LUN
76 #define CONFIG_USBDEV_MSC_MAX_LUN 1
77 #endif
78 
79 #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
80 #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
81 #endif
82 
83 #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
84 #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
85 #endif
86 
87 #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
88 #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
89 #endif
90 
91 #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
92 #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
93 #endif
94 
95 /* move msc read & write from isr to while(1), you should call usbd_msc_polling in while(1) */
96 // #define CONFIG_USBDEV_MSC_POLLING
97 
98 /* move msc read & write from isr to thread */
99 // #define CONFIG_USBDEV_MSC_THREAD
100 
101 #ifndef CONFIG_USBDEV_MSC_PRIO
102 #define CONFIG_USBDEV_MSC_PRIO 4
103 #endif
104 
105 #ifndef CONFIG_USBDEV_MSC_STACKSIZE
106 #define CONFIG_USBDEV_MSC_STACKSIZE 2048
107 #endif
108 
109 #ifndef CONFIG_USBDEV_MTP_MAX_BUFSIZE
110 #define CONFIG_USBDEV_MTP_MAX_BUFSIZE 2048
111 #endif
112 
113 #ifndef CONFIG_USBDEV_MTP_MAX_OBJECTS
114 #define CONFIG_USBDEV_MTP_MAX_OBJECTS 256
115 #endif
116 
117 #ifndef CONFIG_USBDEV_MTP_MAX_PATHNAME
118 #define CONFIG_USBDEV_MTP_MAX_PATHNAME 256
119 #endif
120 
121 #define CONFIG_USBDEV_MTP_THREAD
122 
123 #ifndef CONFIG_USBDEV_MTP_PRIO
124 #define CONFIG_USBDEV_MTP_PRIO 4
125 #endif
126 
127 #ifndef CONFIG_USBDEV_MTP_STACKSIZE
128 #define CONFIG_USBDEV_MTP_STACKSIZE 4096
129 #endif
130 
131 #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
132 #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
133 #endif
134 
135 /* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
136 #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
137 #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
138 #endif
139 
140 #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
141 #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
142 #endif
143 
144 #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
145 #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
146 #endif
147 
148 #define CONFIG_USBDEV_RNDIS_USING_LWIP
149 #define CONFIG_USBDEV_CDC_ECM_USING_LWIP
150 
151 /* ================ USB HOST Stack Configuration ================== */
152 
153 #define CONFIG_USBHOST_MAX_RHPORTS          1
154 #define CONFIG_USBHOST_MAX_EXTHUBS          1
155 #define CONFIG_USBHOST_MAX_EHPORTS          4
156 #define CONFIG_USBHOST_MAX_INTERFACES       8
157 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 2
158 #define CONFIG_USBHOST_MAX_ENDPOINTS        4
159 
160 #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
161 #define CONFIG_USBHOST_MAX_HID_CLASS     4
162 #define CONFIG_USBHOST_MAX_MSC_CLASS     2
163 #define CONFIG_USBHOST_MAX_AUDIO_CLASS   1
164 #define CONFIG_USBHOST_MAX_VIDEO_CLASS   1
165 
166 #define CONFIG_USBHOST_DEV_NAMELEN 16
167 
168 #ifndef CONFIG_USBHOST_PSC_PRIO
169 #define CONFIG_USBHOST_PSC_PRIO 0
170 #endif
171 #ifndef CONFIG_USBHOST_PSC_STACKSIZE
172 #define CONFIG_USBHOST_PSC_STACKSIZE 2048
173 #endif
174 
175 //#define CONFIG_USBHOST_GET_STRING_DESC
176 
177 // #define CONFIG_USBHOST_MSOS_ENABLE
178 #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
179 #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
180 #endif
181 
182 /* Ep0 max transfer buffer */
183 #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
184 #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
185 #endif
186 
187 #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
188 #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
189 #endif
190 
191 #ifndef CONFIG_USBHOST_MSC_TIMEOUT
192 #define CONFIG_USBHOST_MSC_TIMEOUT 5000
193 #endif
194 
195 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
196  * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
197  */
198 #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
199 #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
200 #endif
201 
202 /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
203 #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
204 #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
205 #endif
206 
207 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
208  * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
209  */
210 #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
211 #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
212 #endif
213 /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
214 #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
215 #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
216 #endif
217 
218 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
219  * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
220  */
221 #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
222 #define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
223 #endif
224 /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
225 #ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
226 #define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
227 #endif
228 
229 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
230  * you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
231  */
232 #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
233 #define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
234 #endif
235 /* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
236 #ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
237 #define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
238 #endif
239 
240 #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
241 // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
242 
243 #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
244 #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
245 #endif
246 #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
247 #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
248 #endif
249 
250 /* ================ USB Device Port Configuration ================*/
251 
252 #ifndef CONFIG_USBDEV_MAX_BUS
253 #define CONFIG_USBDEV_MAX_BUS 1
254 #endif
255 
256 // #define CONFIG_USBDEV_SOF_ENABLE
257 
258 /* ---------------- FSDEV Configuration ---------------- */
259 //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
260 
261 /* ---------------- DWC2 Configuration ---------------- */
262 /* enable dwc2 buffer dma mode for device
263  * in xxx32 chips, only pb14/pb15 can support dma mode, pa11/pa12 is not supported(only a few supports, but we ignore them)
264 */
265 // #define CONFIG_USB_DWC2_DMA_ENABLE
266 
267 /* ---------------- MUSB Configuration ---------------- */
268 #define CONFIG_USB_MUSB_EP_NUM 8
269 // #define CONFIG_USB_MUSB_SUNXI
270 
271 /* ================ USB Host Port Configuration ==================*/
272 #ifndef CONFIG_USBHOST_MAX_BUS
273 #define CONFIG_USBHOST_MAX_BUS 1
274 #endif
275 
276 /* ---------------- EHCI Configuration ---------------- */
277 
278 #define CONFIG_USB_EHCI_HCCR_OFFSET     (0x0)
279 #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
280 #define CONFIG_USB_EHCI_QH_NUM          10
281 #define CONFIG_USB_EHCI_QTD_NUM         (CONFIG_USB_EHCI_QH_NUM * 3)
282 #define CONFIG_USB_EHCI_ITD_NUM         4
283 // #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
284 // #define CONFIG_USB_EHCI_CONFIGFLAG
285 // #define CONFIG_USB_EHCI_ISO
286 // #define CONFIG_USB_EHCI_WITH_OHCI
287 // #define CONFIG_USB_EHCI_DESC_DCACHE_ENABLE
288 
289 /* ---------------- OHCI Configuration ---------------- */
290 #define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
291 #define CONFIG_USB_OHCI_ED_NUM 10
292 #define CONFIG_USB_OHCI_TD_NUM 3
293 // #define CONFIG_USB_OHCI_DESC_DCACHE_ENABLE
294 
295 /* ---------------- XHCI Configuration ---------------- */
296 #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
297 
298 /* ---------------- DWC2 Configuration ---------------- */
299 // nothing to define
300 
301 /* ---------------- MUSB Configuration ---------------- */
302 #define CONFIG_USB_MUSB_PIPE_NUM 8
303 // #define CONFIG_USB_MUSB_SUNXI
304 
305 /* When your chip hardware supports high-speed and wants to initialize it in high-speed mode,
306  * the relevant IP will configure the internal or external high-speed PHY according to CONFIG_USB_HS.
307  *
308  * in xxx32 chips, only pb14/pb15 can support hs mode, pa11/pa12 is not supported(only a few supports, but we ignore them).
309 */
310 // #define CONFIG_USB_HS
311 
312 #ifndef usb_phyaddr2ramaddr
313 #define usb_phyaddr2ramaddr(addr) (addr)
314 #endif
315 
316 #ifndef usb_ramaddr2phyaddr
317 #define usb_ramaddr2phyaddr(addr) (addr)
318 #endif
319 
320 #endif
321