Skip to content

Commit d707ea5

Browse files
authored
Merge pull request #2639 from Rbb666/rtthread
[osal]add usb host script of RT-Thread to USB HOST.
2 parents 3e2ea77 + 4cecb75 commit d707ea5

File tree

3 files changed

+108
-20
lines changed

3 files changed

+108
-20
lines changed

lib/rt-thread/SConscript

+32-20
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,44 @@ cwd = GetCurrentDir()
55
src = Split("""
66
../../src/tusb.c
77
../../src/common/tusb_fifo.c
8-
../../src/device/usbd.c
9-
../../src/device/usbd_control.c
108
./tusb_rt_thread_port.c
119
""")
1210
path = [cwd, cwd + "/../../src"]
1311

14-
# BSP
15-
if GetDepend(["SOC_FAMILY_STM32"]):
16-
src += ["../../src/portable/synopsys/dwc2/dcd_dwc2.c",
17-
"../../src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c"]
18-
19-
if GetDepend(["SOC_NRF52840"]):
20-
src += ["../../src/portable/nordic/nrf5x/dcd_nrf5x.c"]
21-
22-
if GetDepend(["SOC_FAMILY_RENESAS"]):
23-
src += ["../../src/portable/renesas/rusb2/dcd_rusb2.c",
24-
"../../src/portable/renesas/rusb2/rusb2_common.c"]
25-
26-
# Device class
27-
if GetDepend(["PKG_TINYUSB_DEVICE_CDC"]):
28-
src += ["../../src/class/cdc/cdc_device.c"]
12+
LOCAL_CFLAGS = ''
2913

30-
if GetDepend(["PKG_TINYUSB_DEVICE_MSC"]):
31-
src += ["../../src/class/msc/msc_device.c", "port/msc_device_port.c"]
14+
# for device stack
15+
if GetDepend(["PKG_TINYUSB_DEVICE_ENABLE"]):
16+
src += ["../../src/device/usbd.c",
17+
"../../src/device/usbd_control.c"]
18+
# BSP
19+
if GetDepend(["SOC_FAMILY_STM32"]):
20+
src += ["../../src/portable/synopsys/dwc2/dcd_dwc2.c",
21+
"../../src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c"]
22+
23+
if GetDepend(["SOC_NRF52840"]):
24+
src += ["../../src/portable/nordic/nrf5x/dcd_nrf5x.c"]
25+
26+
if GetDepend(["SOC_FAMILY_RENESAS"]):
27+
src += ["../../src/portable/renesas/rusb2/dcd_rusb2.c",
28+
"../../src/portable/renesas/rusb2/rusb2_common.c"]
29+
30+
# Device class
31+
if GetDepend(["PKG_TINYUSB_DEVICE_UVC"]):
32+
src += ["../../src/class/video/video_device.c"]
33+
if GetDepend(["PKG_TINYUSB_DEVICE_CDC"]):
34+
src += ["../../src/class/cdc/cdc_device.c"]
35+
if GetDepend(["PKG_TINYUSB_DEVICE_MSC"]):
36+
src += ["../../src/class/msc/msc_device.c", "port/msc_device_port.c"]
37+
38+
# for host stack
39+
if GetDepend(["PKG_TINYUSB_HOST_ENABLE"]):
40+
src += ["../../src/host/usbh.c", "../../src/host/hub.c"]
41+
42+
if GetDepend(["SOC_FAMILY_RENESAS"]):
43+
src += ["../../src/portable/renesas/rusb2/hcd_rusb2.c",
44+
"../../src/portable/renesas/rusb2/rusb2_common.c"]
3245

33-
LOCAL_CFLAGS = ''
3446

3547
if rtconfig.PLATFORM == 'gcc' or rtconfig.PLATFORM == 'armclang': # GCC or Keil AC6
3648
LOCAL_CFLAGS += ' -std=c99'

lib/rt-thread/tusb_config.h

+71
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ extern "C" {
113113
//--------------------------------------------------------------------
114114
// DEVICE CONFIGURATION
115115
//--------------------------------------------------------------------
116+
#if defined(PKG_TINYUSB_DEVICE_ENABLE)
117+
#define CFG_TUD_ENABLED (1)
118+
#else
119+
#define CFG_TUD_ENABLED (0)
120+
#endif
116121

117122
#ifndef CFG_TUD_ENDPOINT0_SIZE
118123
#define CFG_TUD_ENDPOINT0_SIZE PKG_TINYUSB_EDPT0_SIZE
@@ -138,6 +143,72 @@ extern "C" {
138143
#define PKG_TINYUSB_DEVICE_HID_STRING ""
139144
#endif
140145

146+
//--------------------------------------------------------------------
147+
// HOST CONFIGURATION
148+
//--------------------------------------------------------------------
149+
#if defined(PKG_TINYUSB_HOST_ENABLE)
150+
#define CFG_TUH_ENABLED (1)
151+
#else
152+
#define CFG_TUH_ENABLED (0)
153+
#endif
154+
155+
#if (PKG_TINYUSB_HOST_PORT == 0)
156+
#undef CFG_TUSB_RHPORT0_MODE
157+
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | PKG_TINYUSB_HOST_PORT_SPEED)
158+
#endif
159+
160+
#if (PKG_TINYUSB_HOST_PORT == 1)
161+
#undef CFG_TUSB_RHPORT1_MODE
162+
#define CFG_TUSB_RHPORT1_MODE (OPT_MODE_HOST | PKG_TINYUSB_HOST_PORT_SPEED)
163+
#endif
164+
165+
#define BOARD_TUH_RHPORT PKG_TINYUSB_HOST_PORT // FULL SPEED
166+
#define BOARD_TUH_MAX_SPEED PKG_TINYUSB_HOST_PORT_SPEED
167+
// Default is max speed that hardware controller could support with on-chip PHY
168+
#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
169+
170+
//------------------------- Board Specific --------------------------
171+
172+
// RHPort number used for host can be defined by board.mk, default to port 0
173+
#ifndef BOARD_TUH_RHPORT
174+
#define BOARD_TUH_RHPORT 0
175+
#endif
176+
177+
// RHPort max operational speed can defined by board.mk
178+
#ifndef BOARD_TUH_MAX_SPEED
179+
#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
180+
#endif
181+
182+
// Size of buffer to hold descriptors and other data used for enumeration
183+
#define CFG_TUH_ENUMERATION_BUFSIZE 256
184+
185+
#define CFG_TUH_HUB 2 // number of supported hubs
186+
#define CFG_TUH_CDC 0 // CDC ACM
187+
#define CFG_TUH_CDC_FTDI 0 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API
188+
#define CFG_TUH_CDC_CP210X 0 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API
189+
#define CFG_TUH_CDC_CH34X 0 // CH340 or CH341 Serial. CH34X is not part of CDC class, only to re-use CDC driver API
190+
#define CFG_TUH_HID 0 // typical keyboard + mouse device can have 3-4 HID interfaces
191+
#define CFG_TUH_MSC 0
192+
//#define CFG_TUH_VENDOR 3
193+
194+
// max device support (excluding hub device): 1 hub typically has 4 ports
195+
#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
196+
197+
//------------- HID -------------//
198+
#define CFG_TUH_HID_EPIN_BUFSIZE 64
199+
#define CFG_TUH_HID_EPOUT_BUFSIZE 64
200+
201+
//------------- CDC -------------//
202+
203+
// Set Line Control state on enumeration/mounted:
204+
// DTR ( bit 0), RTS (bit 1)
205+
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03
206+
207+
// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
208+
// bit rate = 115200, 1 stop bit, no parity, 8 bit data width
209+
#define CFG_TUH_CDC_LINE_CODING_ON_ENUM { 115200, CDC_LINE_CODING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }
210+
211+
141212

142213
#ifdef __cplusplus
143214
}

lib/rt-thread/tusb_rt_thread_port.c

+5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ static void tusb_thread_entry(void *parameter)
4444
(void) parameter;
4545
while (1)
4646
{
47+
#if CFG_TUH_ENABLED
48+
tuh_task();
49+
#endif
50+
#if CFG_TUD_ENABLED
4751
tud_task();
52+
#endif
4853
}
4954
}
5055

0 commit comments

Comments
 (0)