Skip to content

Commit cecf166

Browse files
committed
[bsp][frdm-mcxa366] add CherryUSB support files
1 parent ecf2409 commit cecf166

5 files changed

Lines changed: 313 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
# add the general drivers.
5+
src = Glob('*.c')
6+
CPPPATH = [cwd]
7+
8+
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
9+
10+
list = os.listdir(cwd)
11+
for item in list:
12+
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
13+
group = group + SConscript(os.path.join(item, 'SConscript'))
14+
15+
Return('group')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from building import *
2+
import os
3+
4+
cwd = GetCurrentDir()
5+
group = []
6+
src = Glob('*.c')
7+
CPPPATH = [cwd]
8+
9+
list = os.listdir(cwd)
10+
for d in list:
11+
path = os.path.join(cwd, d)
12+
if os.path.isfile(os.path.join(path, 'SConscript')):
13+
group = group + SConscript(os.path.join(d, 'SConscript'))
14+
15+
group = group + DefineGroup('cherryusb-port', src, depend = ['RT_CHERRYUSB_DEVICE'], CPPPATH = CPPPATH)
16+
Return('group')
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
* 2025-02-25 hydevcode
10+
* 2026-05-09 CoreBoxer add HID mouse example
11+
*/
12+
#include <rtthread.h>
13+
#include <board.h>
14+
#ifdef RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM
15+
/* Register the EMAC device */
16+
static int rt_hw_stm32_cherryusb_cdc_init(void)
17+
{
18+
extern void cdc_acm_init(uint8_t busid, uintptr_t reg_base);
19+
cdc_acm_init(0, 0x400A4000u);
20+
return 0;
21+
}
22+
INIT_COMPONENT_EXPORT(rt_hw_stm32_cherryusb_cdc_init);
23+
#endif
24+
25+
#ifdef RT_CHERRYUSB_DEVICE_TEMPLATE_HID_MOUSE
26+
extern void hid_mouse_init(uint8_t busid, uintptr_t reg_base);
27+
extern void hid_mouse_test(uint8_t busid);
28+
static int rt_hw_mcxa156_cherryusb_hid_init(void)
29+
{
30+
hid_mouse_init(0, 0x400A4000u);
31+
return 0;
32+
}
33+
INIT_COMPONENT_EXPORT(rt_hw_mcxa156_cherryusb_hid_init);
34+
static int hid_example(int argc, char **argv)
35+
{
36+
hid_mouse_test(0);
37+
return 0;
38+
}
39+
MSH_CMD_EXPORT(hid_example, USB hid example);
40+
#endif
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
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+
#include <rtthread.h>
14+
15+
/* ================ USB common Configuration ================ */
16+
17+
#define CONFIG_USB_PRINTF(...) printf(__VA_ARGS__)
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+
/* data align size when use dma */
27+
#ifndef CONFIG_USB_ALIGN_SIZE
28+
#define CONFIG_USB_ALIGN_SIZE 4
29+
#endif
30+
31+
/* attribute data into no cache ram */
32+
#define USB_NOCACHE_RAM_SECTION __attribute__((section(".NonCacheable")))
33+
34+
/* ================= USB Device Stack Configuration ================ */
35+
36+
/* Ep0 in and out transfer buffer */
37+
#ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
38+
#define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
39+
#endif
40+
41+
/* Setup packet log for debug */
42+
// #define CONFIG_USBDEV_SETUP_LOG_PRINT
43+
44+
/* Check if the input descriptor is correct */
45+
// #define CONFIG_USBDEV_DESC_CHECK
46+
47+
/* Enable test mode */
48+
// #define CONFIG_USBDEV_TEST_MODE
49+
50+
#ifndef CONFIG_USBDEV_MSC_MAX_LUN
51+
#define CONFIG_USBDEV_MSC_MAX_LUN 1
52+
#endif
53+
54+
#ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
55+
#define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
56+
#endif
57+
58+
#ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
59+
#define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
60+
#endif
61+
62+
#ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
63+
#define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
64+
#endif
65+
66+
#ifndef CONFIG_USBDEV_MSC_VERSION_STRING
67+
#define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
68+
#endif
69+
70+
// #define CONFIG_USBDEV_MSC_THREAD
71+
72+
#ifndef CONFIG_USBDEV_MSC_PRIO
73+
#define CONFIG_USBDEV_MSC_PRIO 4
74+
#endif
75+
76+
#ifndef CONFIG_USBDEV_MSC_STACKSIZE
77+
#define CONFIG_USBDEV_MSC_STACKSIZE 2048
78+
#endif
79+
80+
#ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
81+
#define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
82+
#endif
83+
84+
#ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
85+
#define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
86+
#endif
87+
88+
#ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
89+
#define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
90+
#endif
91+
92+
#ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
93+
#define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
94+
#endif
95+
96+
#define CONFIG_USBDEV_RNDIS_USING_LWIP
97+
98+
/* ================ USB HOST Stack Configuration ================== */
99+
100+
#define CONFIG_USBHOST_MAX_RHPORTS 1
101+
#define CONFIG_USBHOST_MAX_EXTHUBS 1
102+
#define CONFIG_USBHOST_MAX_EHPORTS 4
103+
#define CONFIG_USBHOST_MAX_INTERFACES 8
104+
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
105+
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
106+
107+
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
108+
#define CONFIG_USBHOST_MAX_HID_CLASS 4
109+
#define CONFIG_USBHOST_MAX_MSC_CLASS 2
110+
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
111+
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
112+
113+
#define CONFIG_USBHOST_DEV_NAMELEN 16
114+
115+
#ifndef CONFIG_USBHOST_PSC_PRIO
116+
#define CONFIG_USBHOST_PSC_PRIO 0
117+
#endif
118+
#ifndef CONFIG_USBHOST_PSC_STACKSIZE
119+
#define CONFIG_USBHOST_PSC_STACKSIZE 2048
120+
#endif
121+
122+
//#define CONFIG_USBHOST_GET_STRING_DESC
123+
124+
// #define CONFIG_USBHOST_MSOS_ENABLE
125+
#ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
126+
#define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
127+
#endif
128+
129+
/* Ep0 max transfer buffer */
130+
#ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
131+
#define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
132+
#endif
133+
134+
#ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
135+
#define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
136+
#endif
137+
138+
#ifndef CONFIG_USBHOST_MSC_TIMEOUT
139+
#define CONFIG_USBHOST_MSC_TIMEOUT 5000
140+
#endif
141+
142+
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
143+
* you can change with 2K,4K,8K,16K,default is 2K to get one TCP_MSS
144+
*/
145+
#ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
146+
#define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
147+
#endif
148+
#ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
149+
#define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
150+
#endif
151+
152+
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
153+
* you can change with 2K,4K,8K,16K,default is 2K to get one TCP_MSS
154+
*/
155+
#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
156+
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
157+
#endif
158+
#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
159+
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
160+
#endif
161+
162+
#define CONFIG_USBHOST_BLUETOOTH_HCI_H4
163+
// #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
164+
165+
#ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
166+
#define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
167+
#endif
168+
#ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
169+
#define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
170+
#endif
171+
172+
/* ================ USB Device Port Configuration ================*/
173+
174+
#ifndef CONFIG_USBDEV_MAX_BUS
175+
#define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip
176+
#endif
177+
178+
#ifndef CONFIG_USBDEV_EP_NUM
179+
#define CONFIG_USBDEV_EP_NUM 4
180+
#endif
181+
182+
/* ---------------- FSDEV Configuration ---------------- */
183+
//#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
184+
185+
/* ---------------- DWC2 Configuration ---------------- */
186+
// #define CONFIG_USB_DWC2_RXALL_FIFO_SIZE (1024 / 4)
187+
#define CONFIG_USB_DWC2_TX0_FIFO_SIZE (64 / 4)
188+
#define CONFIG_USB_DWC2_TX1_FIFO_SIZE (64 / 4)
189+
#define CONFIG_USB_DWC2_TX2_FIFO_SIZE (64 / 4)
190+
#define CONFIG_USB_DWC2_TX3_FIFO_SIZE (64 / 4)
191+
// #define CONFIG_USB_DWC2_TX4_FIFO_SIZE (0 / 4)
192+
// #define CONFIG_USB_DWC2_TX5_FIFO_SIZE (0 / 4)
193+
// #define CONFIG_USB_DWC2_TX6_FIFO_SIZE (0 / 4)
194+
// #define CONFIG_USB_DWC2_TX7_FIFO_SIZE (0 / 4)
195+
// #define CONFIG_USB_DWC2_TX8_FIFO_SIZE (0 / 4)
196+
197+
/* ---------------- MUSB Configuration ---------------- */
198+
// #define CONFIG_USB_MUSB_SUNXI
199+
200+
/* ================ USB Host Port Configuration ==================*/
201+
#ifndef CONFIG_USBHOST_MAX_BUS
202+
#define CONFIG_USBHOST_MAX_BUS 1
203+
#endif
204+
205+
#ifndef CONFIG_USBHOST_PIPE_NUM
206+
#define CONFIG_USBHOST_PIPE_NUM 10
207+
#endif
208+
209+
/* ---------------- EHCI Configuration ---------------- */
210+
211+
#define CONFIG_USB_EHCI_HCCR_OFFSET (0x0)
212+
#define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
213+
#define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
214+
#define CONFIG_USB_EHCI_QTD_NUM 3
215+
#define CONFIG_USB_EHCI_ITD_NUM 20
216+
// #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
217+
// #define CONFIG_USB_EHCI_CONFIGFLAG
218+
// #define CONFIG_USB_EHCI_ISO
219+
// #define CONFIG_USB_EHCI_WITH_OHCI
220+
221+
/* ---------------- OHCI Configuration ---------------- */
222+
#define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
223+
224+
/* ---------------- XHCI Configuration ---------------- */
225+
#define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
226+
227+
/* ---------------- DWC2 Configuration ---------------- */
228+
/* largest non-periodic USB packet used / 4 */
229+
// #define CONFIG_USB_DWC2_NPTX_FIFO_SIZE (512 / 4)
230+
/* largest periodic USB packet used / 4 */
231+
// #define CONFIG_USB_DWC2_PTX_FIFO_SIZE (1024 / 4)
232+
/*
233+
* (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
234+
* 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
235+
*/
236+
// #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
237+
238+
/* ---------------- MUSB Configuration ---------------- */
239+
// #define CONFIG_USB_MUSB_SUNXI
240+
241+
#endif

components/drivers/usb/cherryusb/port/kinetis/usb_glue_mcx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void USB_ClockInit(void)
3232
CLOCK_EnableClock(kCLOCK_Usb0Fs);
3333
CLOCK_EnableUsbfsClock();
3434
}
35-
#elif defined(MCXA156_H_)
35+
#elif defined(MCXA156_H_) || defined(MCXA366_H_)
3636
#define USBD_IRQ USB0_IRQHandler
3737
void USB_ClockInit(void)
3838
{

0 commit comments

Comments
 (0)