Skip to content

Commit 6d8d888

Browse files
authored
[bsp][nxp] add cherryusb config for mcxa156 (#10041)
[bsp][nxp] add cherryusb config for mcxa156 and add ci.attachconfig
1 parent 7086f4c commit 6d8d888

File tree

8 files changed

+323
-5
lines changed

8 files changed

+323
-5
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
scons.args: &scons
2+
scons_arg:
3+
- '--strict'
4+
# ------ component CI ------
5+
component.cherryusb_cdc:
6+
kconfig:
7+
- CONFIG_RT_USING_CHERRYUSB=y
8+
- CONFIG_RT_CHERRYUSB_DEVICE=y
9+
- CONFIG_RT_CHERRYUSB_DEVICE_KINETIS_MCX=y
10+
- CONFIG_RT_CHERRYUSB_DEVICE_CDC_ACM=y
11+
- CONFIG_RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM=y

bsp/nxp/mcx/mcxa/frdm-mcxa156/board/SConscript

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ CPPDEFINES = ['DEBUG', 'CPU_MCXA156VLL']
1717

1818
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
1919

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

components/drivers/usb/cherryusb/port/kinetis/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Modify USB_NOCACHE_RAM_SECTION
1010
#define USB_NOCACHE_RAM_SECTION __attribute__((section(".NonCacheable")))
1111
```
1212

13-
- MCXC444/MCXA153 (device only)
13+
- MCXC444/MCXA153/MCXA156 (device only)
1414
- MCXN947
1515

1616
### MM32

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ void USB_ClockInit(void)
3232
CLOCK_EnableClock(kCLOCK_Usb0Fs);
3333
CLOCK_EnableUsbfsClock();
3434
}
35+
#elif defined(MCXA156_H_)
36+
#define USBD_IRQ USB0_IRQHandler
37+
void USB_ClockInit(void)
38+
{
39+
RESET_PeripheralReset(kUSB0_RST_SHIFT_RSTn);
40+
CLOCK_EnableUsbfsClock();
41+
}
3542
#else
3643
#error "Unsupported MCU with Kinetis IP"
3744
#endif
@@ -49,15 +56,14 @@ void usb_dc_low_level_init(uint8_t busid)
4956
uint8_t irqNumber;
5057

5158
uint8_t usbDeviceKhciIrq[] = USB_IRQS;
52-
irqNumber = usbDeviceKhciIrq[0];
59+
irqNumber = usbDeviceKhciIrq[0];
5360

5461
/* Install isr, set priority, and enable IRQ. */
5562
NVIC_SetPriority((IRQn_Type)irqNumber, 3);
5663
EnableIRQ((IRQn_Type)irqNumber);
5764

5865
USB_OTG_DEV->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
59-
while (USB_OTG_DEV->USBTRC0 & USB_USBTRC0_USBRESET_MASK)
60-
;
66+
while (USB_OTG_DEV->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
6167

6268
USB_OTG_DEV->USBTRC0 |= USB_USBTRC0_VREGIN_STS(1); /* software must set this bit to 1 */
6369
USB_OTG_DEV->USBCTRL = 0;
@@ -67,7 +73,11 @@ void usb_dc_low_level_init(uint8_t busid)
6773
void usb_dc_low_level_deinit(uint8_t busid)
6874
{
6975
USB_OTG_DEV->CONTROL &= ~USB_CONTROL_DPPULLUPNONOTG_MASK;
70-
DisableIRQ((IRQn_Type)USB0_FS_IRQn);
76+
#if defined(MCXN947_CM33_CORE0_H_)
77+
DisableIRQ((IRQn_Type)USB0_FS_IRQn);
78+
#else
79+
DisableIRQ((IRQn_Type)USB0_IRQn);
80+
#endif
7181
}
7282

7383
void usbd_kinetis_delay_ms(uint8_t ms)

0 commit comments

Comments
 (0)