Skip to content

Commit

Permalink
stm32wb-dfu: add MSOS headers
Browse files Browse the repository at this point in the history
The USB DFU example now shows how to automatically get the WinUSB driver assigned.
  • Loading branch information
Gerharddc committed Dec 10, 2024
1 parent 0b9cdd8 commit 5963a10
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion examples/boot/bootloader/stm32wb-dfu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ 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};

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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5963a10

Please sign in to comment.