Skip to content

Commit b152645

Browse files
committed
WIP TinyUSB
1 parent f73d077 commit b152645

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

examples/generic/usb/main.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ int main()
4141
Board::initializeUsbFs();
4242
// DISCO-F746NG also has a HS port:
4343
// Board::initializeUsbHs();
44-
tusb_init();
44+
static constexpr tusb_rhport_init_t dev_init = {
45+
.role = TUSB_ROLE_DEVICE,
46+
.speed = TUSB_SPEED_FULL
47+
// .speed = TUSB_SPEED_HIGH
48+
};
49+
tusb_init(0, &dev_init);
50+
// tusb_init(1, &dev_init);
4551

4652
while (true)
4753
{

examples/generic/usb/project.xml

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<library>
2-
<extends>modm:blue-pill-f103</extends>
2+
<!-- <extends>modm:blue-pill-f103</extends> -->
33
<!-- <extends>modm:black-pill-f401</extends> -->
4-
<!-- <extends>modm:black-pill-f411</extends> -->
4+
<extends>modm:black-pill-f411</extends>
55
<!-- <extends>modm:disco-f072rb</extends> -->
66
<!-- <extends>modm:disco-f303vc</extends> -->
77
<!-- <extends>modm:disco-f407vg</extends> -->
@@ -20,12 +20,6 @@
2020
<option name="modm:build:build.path">../../../build/generic/usb</option>
2121
<option name="modm:tinyusb:config">device.cdc,device.msc</option>
2222
<!-- <option name="modm:tinyusb:config">device.cdc,device.midi</option> -->
23-
24-
<!-- Required for modm:disco-f429zi -->
25-
<!-- <option name="modm:tinyusb:device:port">hs</option> -->
26-
27-
<!-- Required for modm:nucleo-h723zg, modm:disco-f429zi -->
28-
<!-- <option name="modm:tinyusb:max-speed">full</option> -->
2923
</options>
3024
<modules>
3125
<module>modm:build:scons</module>
@@ -35,6 +29,6 @@
3529
</modules>
3630
<collectors>
3731
<!-- <collect name="modm:build:cppdefines">CFG_TUSB_DEBUG=3</collect> -->
38-
<collect name="modm:build:openocd.source">interface/stlink.cfg</collect>
32+
<!-- <collect name="modm:build:openocd.source">interface/stlink.cfg</collect> -->
3933
</collectors>
4034
</library>

ext/hathach/module.lb

+8-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def prepare(module, options):
6262
# Generate the host and device modules
6363
module.add_submodule(TinyUsbDeviceModule(ports))
6464
module.add_submodule(TinyUsbHostModule(ports))
65-
module.depends(":cmsis:device", ":architecture:atomic", ":architecture:interrupt", ":platform:usb")
65+
module.depends(":cmsis:device", ":architecture:atomic", ":architecture:delay",
66+
":architecture:interrupt", ":platform:usb")
6667
return True
6768

6869

@@ -126,6 +127,10 @@ def build(env):
126127
tusb_config["TUD_OPT_RP2040_USB_DEVICE_UFRAME_FIX"] = "0"
127128
env.copy("tinyusb/src/portable/raspberrypi/rp2040/", "portable/raspberrypi/rp2040/")
128129

130+
if env.get(":platform:cortex-m:enable_dcache"):
131+
tusb_config["CFG_TUD_MEM_DCACHE_ENABLE"] = 1
132+
tusb_config["CFG_TUH_MEM_DCACHE_ENABLE"] = 1
133+
129134
# TinyUSB has a OS abstraction layer for FreeRTOS, but it is causes problems with modm
130135
# if env.has_module(":freertos"):
131136
# tusb_config["CFG_TUSB_OS"] = "OPT_OS_FREERTOS"
@@ -146,11 +151,10 @@ def build(env):
146151
for mode in ["device", "host"]:
147152
if env.has_module(f":tinyusb:{mode}"):
148153
port = env.get(f":tinyusb:{mode}:port", default_port)
154+
tusb_config[f"CFG_TU{mode[0].upper()}_ENABLED"] = 1
149155
ports[port] = mode[0]
150-
mode = f"OPT_MODE_{mode.upper()}"
151156
if port == 1 and (speed := env.get("max-speed")) is not None:
152-
mode = f"({mode} | OPT_MODE_{speed.upper()}_SPEED)"
153-
tusb_config[f"CFG_TUSB_RHPORT{port}_MODE"] = mode
157+
tusb_config[f"CFG_TU{mode[0].upper()}_MAX_SPEED"] = f"OPT_MODE_{speed.upper()}_SPEED"
154158

155159
itf_config = env["config"]
156160
# Enumerate the configurations

ext/hathach/tusb_port.cpp.in

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
// ----------------------------------------------------------------------------
1212

1313
#include <modm/platform/device.hpp>
14-
#include <modm/architecture/interface/interrupt.hpp>
1514
#include <modm/architecture/interface/atomic_lock.hpp>
15+
#include <modm/architecture/interface/delay.hpp>
16+
#include <modm/architecture/interface/interrupt.hpp>
1617
#include "tusb.h"
1718

18-
%% for irq, port, mode in irqs | sort
19+
%% for irq, port, _ in irqs | sort
1920
MODM_ISR({{irq}})
2021
{
21-
tu{{mode}}_int_handler({{port}});
22+
tusb_int_handler({{port}}, true);
2223
}
2324
%% endfor
2425

@@ -99,6 +100,12 @@ tusb_get_device_serial(uint16_t *serial_str)
99100
return sizeof(raw_id) * 2;
100101
}
101102

103+
extern "C" void
104+
tusb_time_delay_ms_api(uint32_t ms)
105+
{
106+
modm::delay_ms(ms);
107+
}
108+
102109
%% if with_debug
103110
#ifdef CFG_TUSB_DEBUG
104111
#include <modm/debug.hpp>

0 commit comments

Comments
 (0)