aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4
diff options
context:
space:
mode:
authorAdam Greig <[email protected]>2023-11-07 02:34:14 +0000
committerAdam Greig <[email protected]>2023-11-07 02:34:27 +0000
commit326bc98bd225a8ec65093e5881e29c57e66fb1cd (patch)
treea6160f790064a09b13e2a24162707716206a6ddc /examples/stm32f4
parent584fc358fd533c3f3a832643bd6074bc00281e74 (diff)
Update stm32 usb_raw example to use MSOS descriptors for WinUSB
Diffstat (limited to 'examples/stm32f4')
-rw-r--r--examples/stm32f4/Cargo.toml2
-rw-r--r--examples/stm32f4/src/bin/usb_ethernet.rs1
-rw-r--r--examples/stm32f4/src/bin/usb_raw.rs21
-rw-r--r--examples/stm32f4/src/bin/usb_serial.rs1
4 files changed, 24 insertions, 1 deletions
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index fca182036..bcf373712 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -10,7 +10,7 @@ embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["
10embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.3.1", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.3.1", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 12embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt", "msos-descriptor"] }
14embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } 14embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }
15 15
16defmt = "0.3" 16defmt = "0.3"
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs
index 7c0644aeb..45dcf56af 100644
--- a/examples/stm32f4/src/bin/usb_ethernet.rs
+++ b/examples/stm32f4/src/bin/usb_ethernet.rs
@@ -94,6 +94,7 @@ async fn main(spawner: Spawner) {
94 &mut make_static!([0; 256])[..], 94 &mut make_static!([0; 256])[..],
95 &mut make_static!([0; 256])[..], 95 &mut make_static!([0; 256])[..],
96 &mut make_static!([0; 256])[..], 96 &mut make_static!([0; 256])[..],
97 &mut [],
97 &mut make_static!([0; 128])[..], 98 &mut make_static!([0; 128])[..],
98 ); 99 );
99 100
diff --git a/examples/stm32f4/src/bin/usb_raw.rs b/examples/stm32f4/src/bin/usb_raw.rs
index 8d4e6c7d6..689aea4fc 100644
--- a/examples/stm32f4/src/bin/usb_raw.rs
+++ b/examples/stm32f4/src/bin/usb_raw.rs
@@ -56,10 +56,16 @@ use embassy_stm32::time::Hertz;
56use embassy_stm32::usb_otg::Driver; 56use embassy_stm32::usb_otg::Driver;
57use embassy_stm32::{bind_interrupts, peripherals, usb_otg, Config}; 57use embassy_stm32::{bind_interrupts, peripherals, usb_otg, Config};
58use embassy_usb::control::{InResponse, OutResponse, Recipient, Request, RequestType}; 58use embassy_usb::control::{InResponse, OutResponse, Recipient, Request, RequestType};
59use embassy_usb::msos::{self, windows_version};
59use embassy_usb::types::InterfaceNumber; 60use embassy_usb::types::InterfaceNumber;
60use embassy_usb::{Builder, Handler}; 61use embassy_usb::{Builder, Handler};
61use {defmt_rtt as _, panic_probe as _}; 62use {defmt_rtt as _, panic_probe as _};
62 63
64// Randomly generated UUID because Windows requires you provide one to use WinUSB.
65// In principle WinUSB-using software could find this device (or a specific interface
66// on it) by its GUID instead of using the VID/PID, but in practice that seems unhelpful.
67const DEVICE_INTERFACE_GUIDS: &[&str] = &["{DAC2087C-63FA-458D-A55D-827C0762DEC7}"];
68
63bind_interrupts!(struct Irqs { 69bind_interrupts!(struct Irqs {
64 OTG_FS => usb_otg::InterruptHandler<peripherals::USB_OTG_FS>; 70 OTG_FS => usb_otg::InterruptHandler<peripherals::USB_OTG_FS>;
65}); 71});
@@ -114,6 +120,7 @@ async fn main(_spawner: Spawner) {
114 let mut device_descriptor = [0; 256]; 120 let mut device_descriptor = [0; 256];
115 let mut config_descriptor = [0; 256]; 121 let mut config_descriptor = [0; 256];
116 let mut bos_descriptor = [0; 256]; 122 let mut bos_descriptor = [0; 256];
123 let mut msos_descriptor = [0; 256];
117 let mut control_buf = [0; 64]; 124 let mut control_buf = [0; 64];
118 125
119 let mut handler = ControlHandler { 126 let mut handler = ControlHandler {
@@ -126,9 +133,23 @@ async fn main(_spawner: Spawner) {
126 &mut device_descriptor, 133 &mut device_descriptor,
127 &mut config_descriptor, 134 &mut config_descriptor,
128 &mut bos_descriptor, 135 &mut bos_descriptor,
136 &mut msos_descriptor,
129 &mut control_buf, 137 &mut control_buf,
130 ); 138 );
131 139
140 // Add the Microsoft OS Descriptor (MSOS/MOD) descriptor.
141 // We tell Windows that this entire device is compatible with the "WINUSB" feature,
142 // which causes it to use the built-in WinUSB driver automatically, which in turn
143 // can be used by libusb/rusb software without needing a custom driver or INF file.
144 // In principle you might want to call msos_feature() just on a specific function,
145 // if your device also has other functions that still use standard class drivers.
146 builder.msos_descriptor(windows_version::WIN8_1, 0);
147 builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
148 builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
149 "DeviceInterfaceGUIDs",
150 msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
151 ));
152
132 // Add a vendor-specific function (class 0xFF), and corresponding interface, 153 // Add a vendor-specific function (class 0xFF), and corresponding interface,
133 // that uses our custom handler. 154 // that uses our custom handler.
134 let mut function = builder.function(0xFF, 0, 0); 155 let mut function = builder.function(0xFF, 0, 0);
diff --git a/examples/stm32f4/src/bin/usb_serial.rs b/examples/stm32f4/src/bin/usb_serial.rs
index 004ff038d..3ab9a6c56 100644
--- a/examples/stm32f4/src/bin/usb_serial.rs
+++ b/examples/stm32f4/src/bin/usb_serial.rs
@@ -77,6 +77,7 @@ async fn main(_spawner: Spawner) {
77 &mut device_descriptor, 77 &mut device_descriptor,
78 &mut config_descriptor, 78 &mut config_descriptor,
79 &mut bos_descriptor, 79 &mut bos_descriptor,
80 &mut [],
80 &mut control_buf, 81 &mut control_buf,
81 ); 82 );
82 83