stm32wb-dfu: add MSOS headers

The USB DFU example now shows how to automatically get the WinUSB driver assigned.
This commit is contained in:
Gerhard de Clercq 2024-12-10 09:31:47 +01:00
parent 0b9cdd86ab
commit 5963a10d4d

View File

@ -12,7 +12,7 @@ use embassy_stm32::rcc::WPAN_DEFAULT;
use embassy_stm32::usb::Driver;
use embassy_stm32::{bind_interrupts, peripherals, usb};
use embassy_sync::blocking_mutex::Mutex;
use embassy_usb::Builder;
use embassy_usb::{msos, Builder};
use embassy_usb_dfu::consts::DfuAttributes;
use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate};
@ -20,6 +20,9 @@ bind_interrupts!(struct Irqs {
USB_LP => usb::InterruptHandler<peripherals::USB>;
});
// This is a randomly generated GUID to allow clients on Windows to find our device
const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"];
#[entry]
fn main() -> ! {
let mut config = embassy_stm32::Config::default();
@ -62,6 +65,18 @@ fn main() -> ! {
&mut control_buf,
);
// We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows.
// Otherwise users need to do this manually using a tool like Zadig.
//
// It seems it is important for the DFU class that these headers be on the Device level.
//
builder.msos_descriptor(msos::windows_version::WIN8_1, 2);
builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
"DeviceInterfaceGUIDs",
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
));
usb_dfu::<_, _, _, ResetImmediate, 4096>(&mut builder, &mut state);
let mut dev = builder.build();