diff options
Diffstat (limited to 'examples/boot/application')
| -rw-r--r-- | examples/boot/application/stm32wb-dfu/src/main.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/examples/boot/application/stm32wb-dfu/src/main.rs b/examples/boot/application/stm32wb-dfu/src/main.rs index dda2b795b..68e9bc3f6 100644 --- a/examples/boot/application/stm32wb-dfu/src/main.rs +++ b/examples/boot/application/stm32wb-dfu/src/main.rs | |||
| @@ -13,7 +13,7 @@ use embassy_stm32::usb::{self, Driver}; | |||
| 13 | use embassy_stm32::{bind_interrupts, peripherals}; | 13 | use embassy_stm32::{bind_interrupts, peripherals}; |
| 14 | use embassy_sync::blocking_mutex::Mutex; | 14 | use embassy_sync::blocking_mutex::Mutex; |
| 15 | use embassy_time::Duration; | 15 | use embassy_time::Duration; |
| 16 | use embassy_usb::Builder; | 16 | use embassy_usb::{msos, Builder}; |
| 17 | use embassy_usb_dfu::consts::DfuAttributes; | 17 | use embassy_usb_dfu::consts::DfuAttributes; |
| 18 | use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; | 18 | use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; |
| 19 | use panic_reset as _; | 19 | use panic_reset as _; |
| @@ -22,6 +22,9 @@ bind_interrupts!(struct Irqs { | |||
| 22 | USB_LP => usb::InterruptHandler<peripherals::USB>; | 22 | USB_LP => usb::InterruptHandler<peripherals::USB>; |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | // This is a randomly generated GUID to allow clients on Windows to find our device | ||
| 26 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; | ||
| 27 | |||
| 25 | #[embassy_executor::main] | 28 | #[embassy_executor::main] |
| 26 | async fn main(_spawner: Spawner) { | 29 | async fn main(_spawner: Spawner) { |
| 27 | let mut config = embassy_stm32::Config::default(); | 30 | let mut config = embassy_stm32::Config::default(); |
| @@ -54,7 +57,26 @@ async fn main(_spawner: Spawner) { | |||
| 54 | &mut control_buf, | 57 | &mut control_buf, |
| 55 | ); | 58 | ); |
| 56 | 59 | ||
| 57 | usb_dfu(&mut builder, &mut state, Duration::from_millis(2500)); | 60 | // We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows. |
| 61 | // Otherwise users need to do this manually using a tool like Zadig. | ||
| 62 | builder.msos_descriptor(msos::windows_version::WIN8_1, 2); | ||
| 63 | |||
| 64 | // In the case of non-composite devices, it seems that feature headers need to be on the device level. | ||
| 65 | // (As is implemented here) | ||
| 66 | // | ||
| 67 | // For composite devices however, they should be on the function level instead. | ||
| 68 | // (This is achieved by passing a GUID to the "usb_dfu" function) | ||
| 69 | builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 70 | builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 71 | "DeviceInterfaceGUIDs", | ||
| 72 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 73 | )); | ||
| 74 | |||
| 75 | // For non-composite devices: | ||
| 76 | usb_dfu(&mut builder, &mut state, Duration::from_millis(2500), None); | ||
| 77 | |||
| 78 | // Or for composite devices: | ||
| 79 | // usb_dfu(&mut builder, &mut state, Duration::from_millis(2500), Some(DEVICE_INTERFACE_GUIDS)); | ||
| 58 | 80 | ||
| 59 | let mut dev = builder.build(); | 81 | let mut dev = builder.build(); |
| 60 | dev.run().await | 82 | dev.run().await |
