Skip to content

Commit d9947e5

Browse files
authored
[bsp/stm32f407-rt-spark/stm32l496zg-st-nucleo] add cherryusb support (#9929)
[bsp/stm32f407-rt-spark/l496zg] add cherryusb support
1 parent 5886e26 commit d9947e5

File tree

22 files changed

+1585
-447
lines changed

22 files changed

+1585
-447
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ ncscope.*
4343
tags
4444

4545
.idea
46+
**/.cache/
4647
.vscode
4748
*.code-workspace
4849
*.eide.*
@@ -57,4 +58,8 @@ vdso.lds
5758

5859
# cherryusb libraries
5960
!components/drivers/usb/cherryusb/port/pusb2/*.a
60-
!components/drivers/usb/cherryusb/port/xhci/phytium/*.a
61+
!components/drivers/usb/cherryusb/port/xhci/phytium/*.a
62+
63+
# stm32cubemx
64+
**/CubeMX_Config/Drivers/
65+
**/CubeMX_Config/MDK-ARM/

bsp/stm32/stm32f407-rt-spark/.ci/attachconfig/ci.attachconfig.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
scons.args: &scons
22
scons_arg:
33
- '--strict'
4+
# ------ nano CI ------
5+
nano:
6+
<<: *scons
7+
kconfig:
8+
- CONFIG_RT_USING_NANO=y
49
# ------ kernel CI ------
510
kernel.klibc-stdlib:
611
<<: *scons
@@ -182,8 +187,11 @@ peripheral.sram:
182187
peripheral.usb_mouse:
183188
kconfig:
184189
- CONFIG_BSP_USING_USB_MOUSE=y
185-
# ------ nano CI ------
186-
nano:
187-
<<: *scons
188-
kconfig:
189-
- CONFIG_RT_USING_NANO=y
190+
# ------ component CI ------
191+
component.cherryusb_cdc:
192+
kconfig:
193+
- CONFIG_RT_USING_CHERRYUSB=y
194+
- CONFIG_RT_CHERRYUSB_DEVICE=y
195+
- CONFIG_RT_CHERRYUSB_DEVICE_DWC2_ST=y
196+
- CONFIG_RT_CHERRYUSB_DEVICE_CDC_ACM=y
197+
- CONFIG_RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM=y
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
#include "board.h"
11+
#include "rtthread.h"
12+
#include "drv_config.h"
13+
14+
static PCD_HandleTypeDef hpcd_USB_OTG_FS;
15+
void usb_dc_low_level_init(uint8_t busid)
16+
{
17+
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
18+
HAL_PCD_MspInit(&hpcd_USB_OTG_FS);
19+
}
20+
21+
void usb_dc_low_level_deinit(uint8_t busid)
22+
{
23+
HAL_PCD_MspDeInit(&hpcd_USB_OTG_FS);
24+
}
25+
26+
#ifdef RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM
27+
/* Register the EMAC device */
28+
static int rt_hw_stm32_cherryusb_cdc_init(void)
29+
{
30+
extern void cdc_acm_init(uint8_t busid, uintptr_t reg_base);
31+
cdc_acm_init(0, USB_OTG_FS_PERIPH_BASE);
32+
33+
return 0;
34+
}
35+
INIT_COMPONENT_EXPORT(rt_hw_stm32_cherryusb_cdc_init);
36+
static int cherry_usb_cdc_send(int argc, char **argv)
37+
{
38+
extern void cdc_acm_data_send_with_dtr_test(uint8_t busid);
39+
cdc_acm_data_send_with_dtr_test(0);
40+
return 0;
41+
}
42+
MSH_CMD_EXPORT(cherry_usb_cdc_send, send the cdc data for test)
43+
#endif
44+
45+
#ifdef USBD_IRQ_HANDLER
46+
void USBD_IRQ_HANDLER(void)
47+
{
48+
extern void USBD_IRQHandler(uint8_t busid);
49+
USBD_IRQHandler(0);
50+
}
51+
#else
52+
#error USBD_IRQ_HANDLER need to USB IRQ like #define USBD_IRQ_HANDLER OTG_HS_IRQHandler
53+
#endif
54+
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 2048
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 12
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

bsp/stm32/stm32f407-rt-spark/rtconfig.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
PLATFORM = 'gcc'
2020
EXEC_PATH = r'C:\Users\XXYYZZ'
2121
elif CROSS_TOOL == 'keil':
22-
PLATFORM = 'armcc'
22+
PLATFORM = 'armclang' #KEIL AC6
23+
#PLATFORM = 'armcc' #KEIL AC5
2324
EXEC_PATH = r'C:/Keil_v5'
2425
elif CROSS_TOOL == 'iar':
2526
PLATFORM = 'iccarm'
@@ -28,7 +29,7 @@
2829
PLATFORM = 'llvm-arm'
2930
EXEC_PATH = r'D:\Progrem\LLVMEmbeddedToolchainForArm-17.0.1-Windows-x86_64\bin'
3031

31-
if os.getenv('RTT_EXEC_PATH'):
32+
if os.getenv('RTT_EXEC_PATH') and CROSS_TOOL == 'gcc':
3233
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
3334

3435
BUILD = 'debug'

0 commit comments

Comments
 (0)