aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/bootloader/stm32wb-dfu/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/boot/bootloader/stm32wb-dfu/src/main.rs')
-rw-r--r--examples/boot/bootloader/stm32wb-dfu/src/main.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/examples/boot/bootloader/stm32wb-dfu/src/main.rs b/examples/boot/bootloader/stm32wb-dfu/src/main.rs
index 28216806e..107f243fd 100644
--- a/examples/boot/bootloader/stm32wb-dfu/src/main.rs
+++ b/examples/boot/bootloader/stm32wb-dfu/src/main.rs
@@ -20,9 +20,17 @@ bind_interrupts!(struct Irqs {
20 USB_LP => usb::InterruptHandler<peripherals::USB>; 20 USB_LP => usb::InterruptHandler<peripherals::USB>;
21}); 21});
22 22
23// This is a randomly generated GUID to allow clients on Windows to find our device 23// This is a randomly generated GUID to allow clients on Windows to find your device.
24//
25// N.B. update to a custom GUID for your own device!
24const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; 26const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"];
25 27
28// This is a randomly generated example key.
29//
30// N.B. Please replace with your own!
31#[cfg(feature = "verify")]
32static PUBLIC_SIGNING_KEY: &[u8; 32] = include_bytes!("../secrets/key.pub.short");
33
26#[entry] 34#[entry]
27fn main() -> ! { 35fn main() -> ! {
28 let mut config = embassy_stm32::Config::default(); 36 let mut config = embassy_stm32::Config::default();
@@ -55,7 +63,13 @@ fn main() -> ! {
55 let mut config_descriptor = [0; 256]; 63 let mut config_descriptor = [0; 256];
56 let mut bos_descriptor = [0; 256]; 64 let mut bos_descriptor = [0; 256];
57 let mut control_buf = [0; 4096]; 65 let mut control_buf = [0; 4096];
66
67 #[cfg(not(feature = "verify"))]
58 let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate); 68 let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate);
69
70 #[cfg(feature = "verify")]
71 let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate, PUBLIC_SIGNING_KEY);
72
59 let mut builder = Builder::new( 73 let mut builder = Builder::new(
60 driver, 74 driver,
61 config, 75 config,
@@ -68,7 +82,8 @@ fn main() -> ! {
68 // We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows. 82 // We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows.
69 // Otherwise users need to do this manually using a tool like Zadig. 83 // Otherwise users need to do this manually using a tool like Zadig.
70 // 84 //
71 // It seems it is important for the DFU class that these headers be on the Device level. 85 // It seems these always need to be at added at the device level for this to work and for
86 // composite devices they also need to be added on the function level (as shown later).
72 // 87 //
73 builder.msos_descriptor(msos::windows_version::WIN8_1, 2); 88 builder.msos_descriptor(msos::windows_version::WIN8_1, 2);
74 builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); 89 builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
@@ -77,7 +92,15 @@ fn main() -> ! {
77 msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), 92 msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
78 )); 93 ));
79 94
80 usb_dfu::<_, _, _, _, 4096>(&mut builder, &mut state); 95 usb_dfu::<_, _, _, _, 4096>(&mut builder, &mut state, |func| {
96 // You likely don't have to add these function level headers if your USB device is not composite
97 // (i.e. if your device does not expose another interface in addition to DFU)
98 func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
99 func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
100 "DeviceInterfaceGUIDs",
101 msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
102 ));
103 });
81 104
82 let mut dev = builder.build(); 105 let mut dev = builder.build();
83 embassy_futures::block_on(dev.run()); 106 embassy_futures::block_on(dev.run());