Skip to content

Commit 5c2eb10

Browse files
committed
bsp: k230: add usb configurations
We use components/drivers/usb/cherryusb as usb driver. It require bsp provide a configuration file. This patch has dependency on several other usb related patches, such as: - "bsp: k230: define usbh_class_info section" - "components: cherryusb: support k230" Signed-off-by: Wang Chen <[email protected]>
1 parent a2cf4bb commit 5c2eb10

File tree

1 file changed

+276
-0
lines changed

1 file changed

+276
-0
lines changed

bsp/k230/board/usb_config.h

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
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+
#include <rtthread.h>
10+
11+
/* ================ USB common Configuration ================ */
12+
13+
#define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
14+
15+
#define CONFIG_USB_DBG_LEVEL USB_DBG_WARNING
16+
17+
/* Enable print with color */
18+
#define CONFIG_USB_PRINTF_COLOR_ENABLE
19+
20+
/* data align size when use dma */
21+
#ifndef CONFIG_USB_ALIGN_SIZE
22+
#define CONFIG_USB_ALIGN_SIZE 64
23+
#endif
24+
25+
/* attribute data into no cache ram */
26+
#define USB_NOCACHE_RAM_SECTION
27+
28+
/* ================= USB Device Stack Configuration ================ */
29+
30+
/* Ep0 in and out transfer buffer */
31+
#ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
32+
#define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
33+
#endif
34+
35+
/* Setup packet log for debug */
36+
// #define CONFIG_USBDEV_SETUP_LOG_PRINT
37+
38+
/* Send ep0 in data from user buffer instead of copying into ep0 reqdata
39+
* Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
40+
*/
41+
// #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
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+
/* move msc read & write from isr to while(1), you should call usbd_msc_polling in while(1) */
70+
// #define CONFIG_USBDEV_MSC_POLLING
71+
72+
/* move msc read & write from isr to thread */
73+
// #define CONFIG_USBDEV_MSC_THREAD
74+
75+
#ifndef CONFIG_USBDEV_MSC_PRIO
76+
#define CONFIG_USBDEV_MSC_PRIO 4
77+
#endif
78+
79+
#ifndef CONFIG_USBDEV_MSC_STACKSIZE
80+
#define CONFIG_USBDEV_MSC_STACKSIZE 2048
81+
#endif
82+
83+
#ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
84+
#define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
85+
#endif
86+
87+
/* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
88+
#ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
89+
#define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
90+
#endif
91+
92+
#ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
93+
#define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
94+
#endif
95+
96+
#ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
97+
#define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
98+
#endif
99+
100+
#define CONFIG_USBDEV_RNDIS_USING_LWIP
101+
102+
/* ================ USB HOST Stack Configuration ================== */
103+
104+
#define CONFIG_USBHOST_MAX_RHPORTS 1
105+
#define CONFIG_USBHOST_MAX_EXTHUBS 1
106+
#define CONFIG_USBHOST_MAX_EHPORTS 4
107+
#define CONFIG_USBHOST_MAX_INTERFACES 8
108+
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
109+
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
110+
111+
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
112+
#define CONFIG_USBHOST_MAX_HID_CLASS 4
113+
#define CONFIG_USBHOST_MAX_MSC_CLASS 2
114+
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
115+
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
116+
117+
#define CONFIG_USBHOST_DEV_NAMELEN 16
118+
119+
#ifndef CONFIG_USBHOST_PSC_PRIO
120+
#define CONFIG_USBHOST_PSC_PRIO 8
121+
#endif
122+
#ifndef CONFIG_USBHOST_PSC_STACKSIZE
123+
#define CONFIG_USBHOST_PSC_STACKSIZE 8192
124+
#endif
125+
126+
//#define CONFIG_USBHOST_GET_STRING_DESC
127+
128+
// #define CONFIG_USBHOST_MSOS_ENABLE
129+
#ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
130+
#define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
131+
#endif
132+
133+
/* Ep0 max transfer buffer */
134+
#ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
135+
#define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
136+
#endif
137+
138+
#ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
139+
#define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
140+
#endif
141+
142+
#ifndef CONFIG_USBHOST_MSC_TIMEOUT
143+
#define CONFIG_USBHOST_MSC_TIMEOUT 5000
144+
#endif
145+
146+
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
147+
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
148+
*/
149+
#ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
150+
#define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
151+
#endif
152+
153+
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
154+
#ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
155+
#define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
156+
#endif
157+
158+
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
159+
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
160+
*/
161+
#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
162+
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
163+
#endif
164+
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
165+
#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
166+
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
167+
#endif
168+
169+
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
170+
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
171+
*/
172+
#ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
173+
#define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
174+
#endif
175+
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
176+
#ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
177+
#define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
178+
#endif
179+
180+
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
181+
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
182+
*/
183+
#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
184+
#define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (16 * 1024)
185+
#endif
186+
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
187+
#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
188+
#define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
189+
#endif
190+
191+
#define CONFIG_USBHOST_BLUETOOTH_HCI_H4
192+
// #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
193+
194+
#ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
195+
#define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
196+
#endif
197+
#ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
198+
#define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
199+
#endif
200+
201+
/* ================ USB Device Port Configuration ================*/
202+
203+
#ifndef CONFIG_USBDEV_MAX_BUS
204+
#define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip
205+
#endif
206+
207+
#ifndef CONFIG_USBDEV_EP_NUM
208+
#define CONFIG_USBDEV_EP_NUM 6
209+
#endif
210+
211+
/* ---------------- FSDEV Configuration ---------------- */
212+
//#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
213+
214+
/* ---------------- DWC2 Configuration ---------------- */
215+
/* (5 * number of control endpoints + 8) + ((largest USB packet used / 4) + 1 for
216+
* status information) + (2 * number of OUT endpoints) + 1 for Global NAK
217+
*/
218+
#define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (2048 / 4)
219+
/* IN Endpoints Max packet Size / 4 */
220+
#define CONFIG_USB_DWC2_TX0_FIFO_SIZE (1024 / 4)
221+
#define CONFIG_USB_DWC2_TX1_FIFO_SIZE (1024 / 4)
222+
#define CONFIG_USB_DWC2_TX2_FIFO_SIZE (1024 / 4)
223+
#define CONFIG_USB_DWC2_TX3_FIFO_SIZE (1024 / 4)
224+
#define CONFIG_USB_DWC2_TX4_FIFO_SIZE (1024 / 4)
225+
#define CONFIG_USB_DWC2_TX5_FIFO_SIZE (1024 / 4)
226+
// #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
227+
// #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
228+
// #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
229+
230+
// #define CONFIG_USB_DWC2_DMA_ENABLE
231+
232+
/* ---------------- MUSB Configuration ---------------- */
233+
// #define CONFIG_USB_MUSB_SUNXI
234+
235+
/* ================ USB Host Port Configuration ==================*/
236+
#ifndef CONFIG_USBHOST_MAX_BUS
237+
#define CONFIG_USBHOST_MAX_BUS 2
238+
#endif
239+
240+
#ifndef CONFIG_USBHOST_PIPE_NUM
241+
#define CONFIG_USBHOST_PIPE_NUM 6
242+
#endif
243+
244+
/* ---------------- EHCI Configuration ---------------- */
245+
246+
#define CONFIG_USB_EHCI_HCCR_OFFSET (0x0)
247+
#define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
248+
#define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
249+
#define CONFIG_USB_EHCI_QTD_NUM 3
250+
#define CONFIG_USB_EHCI_ITD_NUM 20
251+
// #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
252+
// #define CONFIG_USB_EHCI_CONFIGFLAG
253+
// #define CONFIG_USB_EHCI_ISO
254+
// #define CONFIG_USB_EHCI_WITH_OHCI
255+
256+
/* ---------------- OHCI Configuration ---------------- */
257+
#define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
258+
259+
/* ---------------- XHCI Configuration ---------------- */
260+
#define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
261+
262+
/* ---------------- DWC2 Configuration ---------------- */
263+
/* largest non-periodic USB packet used / 4 */
264+
#define CONFIG_USB_DWC2_NPTX_FIFO_SIZE (2048 / 4)
265+
/* largest periodic USB packet used / 4 */
266+
#define CONFIG_USB_DWC2_PTX_FIFO_SIZE (2048 / 4)
267+
/*
268+
* (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
269+
* 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
270+
*/
271+
#define CONFIG_USB_DWC2_RX_FIFO_SIZE (2048 / 4)
272+
273+
/* ---------------- MUSB Configuration ---------------- */
274+
// #define CONFIG_USB_MUSB_SUNXI
275+
276+
#endif

0 commit comments

Comments
 (0)