diff options
| author | Adam Greig <[email protected]> | 2023-11-07 02:34:14 +0000 |
|---|---|---|
| committer | Adam Greig <[email protected]> | 2023-11-07 02:34:27 +0000 |
| commit | 326bc98bd225a8ec65093e5881e29c57e66fb1cd (patch) | |
| tree | a6160f790064a09b13e2a24162707716206a6ddc /examples/stm32f4/src | |
| parent | 584fc358fd533c3f3a832643bd6074bc00281e74 (diff) | |
Update stm32 usb_raw example to use MSOS descriptors for WinUSB
Diffstat (limited to 'examples/stm32f4/src')
| -rw-r--r-- | examples/stm32f4/src/bin/usb_ethernet.rs | 1 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/usb_raw.rs | 21 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/usb_serial.rs | 1 |
3 files changed, 23 insertions, 0 deletions
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; | |||
| 56 | use embassy_stm32::usb_otg::Driver; | 56 | use embassy_stm32::usb_otg::Driver; |
| 57 | use embassy_stm32::{bind_interrupts, peripherals, usb_otg, Config}; | 57 | use embassy_stm32::{bind_interrupts, peripherals, usb_otg, Config}; |
| 58 | use embassy_usb::control::{InResponse, OutResponse, Recipient, Request, RequestType}; | 58 | use embassy_usb::control::{InResponse, OutResponse, Recipient, Request, RequestType}; |
| 59 | use embassy_usb::msos::{self, windows_version}; | ||
| 59 | use embassy_usb::types::InterfaceNumber; | 60 | use embassy_usb::types::InterfaceNumber; |
| 60 | use embassy_usb::{Builder, Handler}; | 61 | use embassy_usb::{Builder, Handler}; |
| 61 | use {defmt_rtt as _, panic_probe as _}; | 62 | use {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. | ||
| 67 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{DAC2087C-63FA-458D-A55D-827C0762DEC7}"]; | ||
| 68 | |||
| 63 | bind_interrupts!(struct Irqs { | 69 | bind_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 | ||
