diff options
| author | Ulf Lilleengen <[email protected]> | 2024-12-10 10:12:34 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-12-10 10:12:34 +0000 |
| commit | e47bc1ca5c37f31c4560abe2f9b19dd24e8f10df (patch) | |
| tree | aa75bae80aa9e5c8b1342f27995c7fb8818d0a51 | |
| parent | 54b6fe6d8459790e20702a06828c4f306bc0eead (diff) | |
| parent | 5963a10d4d541ef93e42ccfe339aa9aa343f2914 (diff) | |
Merge pull request #3630 from Gerharddc/main
Improve USB DFU support
| -rw-r--r-- | embassy-usb-dfu/src/dfu.rs | 2 | ||||
| -rw-r--r-- | examples/boot/bootloader/stm32wb-dfu/src/main.rs | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/embassy-usb-dfu/src/dfu.rs b/embassy-usb-dfu/src/dfu.rs index abd929a9e..c23286cf5 100644 --- a/embassy-usb-dfu/src/dfu.rs +++ b/embassy-usb-dfu/src/dfu.rs | |||
| @@ -189,7 +189,7 @@ pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, RST: Reset, co | |||
| 189 | builder: &mut Builder<'d, D>, | 189 | builder: &mut Builder<'d, D>, |
| 190 | handler: &'d mut Control<'d, DFU, STATE, RST, BLOCK_SIZE>, | 190 | handler: &'d mut Control<'d, DFU, STATE, RST, BLOCK_SIZE>, |
| 191 | ) { | 191 | ) { |
| 192 | let mut func = builder.function(0x00, 0x00, 0x00); | 192 | let mut func = builder.function(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU); |
| 193 | let mut iface = func.interface(); | 193 | let mut iface = func.interface(); |
| 194 | let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, None); | 194 | let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, None); |
| 195 | alt.descriptor( | 195 | alt.descriptor( |
diff --git a/examples/boot/bootloader/stm32wb-dfu/src/main.rs b/examples/boot/bootloader/stm32wb-dfu/src/main.rs index 093b39f9d..b09d53cf0 100644 --- a/examples/boot/bootloader/stm32wb-dfu/src/main.rs +++ b/examples/boot/bootloader/stm32wb-dfu/src/main.rs | |||
| @@ -12,7 +12,7 @@ use embassy_stm32::rcc::WPAN_DEFAULT; | |||
| 12 | use embassy_stm32::usb::Driver; | 12 | use embassy_stm32::usb::Driver; |
| 13 | use embassy_stm32::{bind_interrupts, peripherals, usb}; | 13 | use embassy_stm32::{bind_interrupts, peripherals, usb}; |
| 14 | use embassy_sync::blocking_mutex::Mutex; | 14 | use embassy_sync::blocking_mutex::Mutex; |
| 15 | use embassy_usb::Builder; | 15 | use embassy_usb::{msos, Builder}; |
| 16 | use embassy_usb_dfu::consts::DfuAttributes; | 16 | use embassy_usb_dfu::consts::DfuAttributes; |
| 17 | use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; | 17 | use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; |
| 18 | 18 | ||
| @@ -20,6 +20,9 @@ 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 | ||
| 24 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; | ||
| 25 | |||
| 23 | #[entry] | 26 | #[entry] |
| 24 | fn main() -> ! { | 27 | fn main() -> ! { |
| 25 | let mut config = embassy_stm32::Config::default(); | 28 | let mut config = embassy_stm32::Config::default(); |
| @@ -62,6 +65,18 @@ fn main() -> ! { | |||
| 62 | &mut control_buf, | 65 | &mut control_buf, |
| 63 | ); | 66 | ); |
| 64 | 67 | ||
| 68 | // 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. | ||
| 70 | // | ||
| 71 | // It seems it is important for the DFU class that these headers be on the Device level. | ||
| 72 | // | ||
| 73 | builder.msos_descriptor(msos::windows_version::WIN8_1, 2); | ||
| 74 | builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 75 | builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 76 | "DeviceInterfaceGUIDs", | ||
| 77 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 78 | )); | ||
| 79 | |||
| 65 | usb_dfu::<_, _, _, ResetImmediate, 4096>(&mut builder, &mut state); | 80 | usb_dfu::<_, _, _, ResetImmediate, 4096>(&mut builder, &mut state); |
| 66 | 81 | ||
| 67 | let mut dev = builder.build(); | 82 | let mut dev = builder.build(); |
