Skip to content

Commit a68160a

Browse files
committed
[bsp][nxp] add cherryusb config for mcxa156 and update cdc_acm demo
1 parent 2fffae7 commit a68160a

File tree

8 files changed

+349
-9
lines changed

8 files changed

+349
-9
lines changed

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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
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+
23+
INIT_COMPONENT_EXPORT(rt_hw_stm32_cherryusb_cdc_init);
24+
static int cherry_usb_cdc_send(int argc, char *argv[])
25+
{
26+
char str[100];
27+
if (argc == 2)
28+
{
29+
rt_strncpy(str, argv[1], 100);
30+
rt_kprintf("%s",str);
31+
extern void cdc_acm_data_send(char *format, ...);
32+
cdc_acm_data_send("%s\r\n",str);
33+
}
34+
}
35+
MSH_CMD_EXPORT(cherry_usb_cdc_send, send the cdc data for test)
36+
#endif
37+
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/demo/cdc_acm_template.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
#include "usbd_core.h"
77
#include "usbd_cdc_acm.h"
8+
#include <rtthread.h>
9+
#include "string.h"
810

911
/*!< endpoint address */
1012
#define CDC_IN_EP 0x81
@@ -140,10 +142,10 @@ static void usbd_event_handler(uint8_t busid, uint8_t event)
140142
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
141143
{
142144
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
143-
// for (int i = 0; i < 100; i++) {
144-
// printf("%02x ", read_buffer[i]);
145-
// }
146-
// printf("\r\n");
145+
for (int i = 0; i < nbytes; i++) {
146+
printf("%c", read_buffer[i]);
147+
}
148+
printf("\r\n");
147149
/* setup next out ep read transfer */
148150
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
149151
}
@@ -208,4 +210,20 @@ void cdc_acm_data_send_with_dtr_test(uint8_t busid)
208210
while (ep_tx_busy_flag) {
209211
}
210212
}
213+
}
214+
215+
void cdc_acm_data_send(char *format, ...)
216+
{
217+
uint8_t str[4096];
218+
uint32_t str_len;
219+
va_list arg;
220+
va_start(arg, format);
221+
vsprintf(str, format, arg);
222+
va_end(arg);
223+
str_len=strlen(str);
224+
ep_tx_busy_flag = true;
225+
memcpy(write_buffer,str,str_len);
226+
usbd_ep_start_write(0, CDC_IN_EP, write_buffer, str_len);
227+
while (ep_tx_busy_flag) {
228+
}
211229
}

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

0 commit comments

Comments
 (0)