1 /*
2  * Copyright (c) 2025, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2025-01-17     Supperthomas first version
9  */
10 #ifndef CHERRYUSB_CONFIG_H
11 #define CHERRYUSB_CONFIG_H
12 
13 /* ================ USB common Configuration ================ */
14 #include "rtthread.h"
15 
16 #define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
17 
18 #ifndef CONFIG_USB_DBG_LEVEL
19 #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
20 #endif
21 
22 /* Enable print with color */
23 #define CONFIG_USB_PRINTF_COLOR_ENABLE
24 
25 /* data align size when use dma */
26 #ifndef CONFIG_USB_ALIGN_SIZE
27 #define CONFIG_USB_ALIGN_SIZE 4
28 #endif
29 
30 /* attribute data into no cache ram */
31 #define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
32 
33 /* ================= USB Device Stack Configuration ================ */
34 
35 /* Ep0 in and out transfer buffer */
36 #ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
37 #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
38 #endif
39 
40 /* Setup packet log for debug */
41 // #define CONFIG_USBDEV_SETUP_LOG_PRINT
42 
43 /* Check if the input descriptor is correct */
44 // #define CONFIG_USBDEV_DESC_CHECK
45 
46 /* Enable test mode */
47 // #define CONFIG_USBDEV_TEST_MODE
48 
49 #ifndef CONFIG_USBDEV_MSC_MAX_LUN
50 #define CONFIG_USBDEV_MSC_MAX_LUN 1
51 #endif
52 
53 #ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
54 #define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
55 #endif
56 
57 #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
58 #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
59 #endif
60 
61 #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
62 #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
63 #endif
64 
65 #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
66 #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
67 #endif
68 
69 // #define CONFIG_USBDEV_MSC_THREAD
70 
71 #ifndef CONFIG_USBDEV_MSC_PRIO
72 #define CONFIG_USBDEV_MSC_PRIO 4
73 #endif
74 
75 #ifndef CONFIG_USBDEV_MSC_STACKSIZE
76 #define CONFIG_USBDEV_MSC_STACKSIZE 2048
77 #endif
78 
79 #ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
80 #define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
81 #endif
82 
83 #ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
84 #define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 2048
85 #endif
86 
87 #ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
88 #define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
89 #endif
90 
91 #ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
92 #define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
93 #endif
94 
95 #define CONFIG_USBDEV_RNDIS_USING_LWIP
96 
97 /* ================ USB HOST Stack Configuration ================== */
98 
99 #define CONFIG_USBHOST_MAX_RHPORTS          1
100 #define CONFIG_USBHOST_MAX_EXTHUBS          1
101 #define CONFIG_USBHOST_MAX_EHPORTS          4
102 #define CONFIG_USBHOST_MAX_INTERFACES       8
103 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
104 #define CONFIG_USBHOST_MAX_ENDPOINTS        4
105 
106 #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
107 #define CONFIG_USBHOST_MAX_HID_CLASS     4
108 #define CONFIG_USBHOST_MAX_MSC_CLASS     2
109 #define CONFIG_USBHOST_MAX_AUDIO_CLASS   1
110 #define CONFIG_USBHOST_MAX_VIDEO_CLASS   1
111 
112 #define CONFIG_USBHOST_DEV_NAMELEN 16
113 
114 #ifndef CONFIG_USBHOST_PSC_PRIO
115 #define CONFIG_USBHOST_PSC_PRIO 0
116 #endif
117 #ifndef CONFIG_USBHOST_PSC_STACKSIZE
118 #define CONFIG_USBHOST_PSC_STACKSIZE 2048
119 #endif
120 
121 //#define CONFIG_USBHOST_GET_STRING_DESC
122 
123 // #define CONFIG_USBHOST_MSOS_ENABLE
124 #ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
125 #define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
126 #endif
127 
128 /* Ep0 max transfer buffer */
129 #ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
130 #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
131 #endif
132 
133 #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
134 #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
135 #endif
136 
137 #ifndef CONFIG_USBHOST_MSC_TIMEOUT
138 #define CONFIG_USBHOST_MSC_TIMEOUT 5000
139 #endif
140 
141 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
142  * you can change with 2K,4K,8K,16K,default is 2K to get one TCP_MSS
143  */
144 #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
145 #define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
146 #endif
147 #ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
148 #define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
149 #endif
150 
151 /* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
152  * you can change with 2K,4K,8K,16K,default is 2K to get one TCP_MSS
153  */
154 #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
155 #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
156 #endif
157 #ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
158 #define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
159 #endif
160 
161 #define CONFIG_USBHOST_BLUETOOTH_HCI_H4
162 // #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
163 
164 #ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
165 #define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
166 #endif
167 #ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
168 #define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
169 #endif
170 
171 /* ================ USB Device Port Configuration ================*/
172 
173 #ifndef CONFIG_USBDEV_MAX_BUS
174 #define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip
175 #endif
176 
177 #ifndef CONFIG_USBDEV_EP_NUM
178 #define CONFIG_USBDEV_EP_NUM 4
179 #endif
180 
181 /* ---------------- FSDEV Configuration ---------------- */
182 //#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
183 
184 /* ---------------- DWC2 Configuration ---------------- */
185 // #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
186 #define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
187 #define CONFIG_USB_DWC2_TX1_FIFO_SIZE (64 / 4)
188 #define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
189 #define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
190 // #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
191 // #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
192 // #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
193 // #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
194 // #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
195 
196 /* ---------------- MUSB Configuration ---------------- */
197 // #define CONFIG_USB_MUSB_SUNXI
198 
199 /* ================ USB Host Port Configuration ==================*/
200 #ifndef CONFIG_USBHOST_MAX_BUS
201 #define CONFIG_USBHOST_MAX_BUS 1
202 #endif
203 
204 #ifndef CONFIG_USBHOST_PIPE_NUM
205 #define CONFIG_USBHOST_PIPE_NUM 12
206 #endif
207 
208 /* ---------------- EHCI Configuration ---------------- */
209 
210 #define CONFIG_USB_EHCI_HCCR_OFFSET     (0x0)
211 #define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
212 #define CONFIG_USB_EHCI_QH_NUM          CONFIG_USBHOST_PIPE_NUM
213 #define CONFIG_USB_EHCI_QTD_NUM         3
214 #define CONFIG_USB_EHCI_ITD_NUM         20
215 // #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
216 // #define CONFIG_USB_EHCI_CONFIGFLAG
217 // #define CONFIG_USB_EHCI_ISO
218 // #define CONFIG_USB_EHCI_WITH_OHCI
219 
220 /* ---------------- OHCI Configuration ---------------- */
221 #define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
222 
223 /* ---------------- XHCI Configuration ---------------- */
224 #define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
225 
226 /* ---------------- DWC2 Configuration ---------------- */
227 /* largest non-periodic USB packet used / 4 */
228 // #define CONFIG_USB_DWC2_NPTX_FIFO_SIZE (512 / 4)
229 /* largest periodic USB packet used / 4 */
230 // #define CONFIG_USB_DWC2_PTX_FIFO_SIZE (1024 / 4)
231 /*
232  * (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
233  * 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
234  */
235 // #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
236 
237 /* ---------------- MUSB Configuration ---------------- */
238 // #define CONFIG_USB_MUSB_SUNXI
239 
240 #endif
241