aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src/bin/usb_raw.rs
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/src/bin/usb_raw.rs
parent584fc358fd533c3f3a832643bd6074bc00281e74 (diff)
Update stm32 usb_raw example to use MSOS descriptors for WinUSB
Diffstat (limited to 'examples/stm32f4/src/bin/usb_raw.rs')
-rw-r--r--examples/stm32f4/src/bin/usb_raw.rs21
1 files changed, 21 insertions, 0 deletions
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);