Skip to content

Commit 30a426c

Browse files
committed
[bsp][frdm-mcxa366] add CherryUSB support files
1 parent 3f6a21d commit 30a426c

6 files changed

Lines changed: 336 additions & 1 deletion

File tree

bsp/nxp/mcx/mcxa/frdm-mcxa366/.ci/attachconfig/ci.attachconfig.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ component.can:
88
- CONFIG_BSP_USING_CAN=y
99
- CONFIG_BSP_USING_CAN0=y
1010

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