Merge pull request #4188 from Gerharddc/dfu-msos
[embassy-usb-dfu] support function level WinUSB GUIDs
This commit is contained in:
commit
f915903f0e
@ -2,7 +2,7 @@ use embassy_boot::BlockingFirmwareState;
|
|||||||
use embassy_time::{Duration, Instant};
|
use embassy_time::{Duration, Instant};
|
||||||
use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType};
|
use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType};
|
||||||
use embassy_usb::driver::Driver;
|
use embassy_usb::driver::Driver;
|
||||||
use embassy_usb::{Builder, Handler};
|
use embassy_usb::{Builder, FunctionBuilder, Handler};
|
||||||
use embedded_storage::nor_flash::NorFlash;
|
use embedded_storage::nor_flash::NorFlash;
|
||||||
|
|
||||||
use crate::consts::{
|
use crate::consts::{
|
||||||
@ -130,8 +130,14 @@ pub fn usb_dfu<'d, D: Driver<'d>, MARK: DfuMarker, RST: Reset>(
|
|||||||
builder: &mut Builder<'d, D>,
|
builder: &mut Builder<'d, D>,
|
||||||
handler: &'d mut Control<MARK, RST>,
|
handler: &'d mut Control<MARK, RST>,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
|
func_modifier: impl Fn(&mut FunctionBuilder<'_, 'd, D>),
|
||||||
) {
|
) {
|
||||||
let mut func = builder.function(0x00, 0x00, 0x00);
|
let mut func = builder.function(0x00, 0x00, 0x00);
|
||||||
|
|
||||||
|
// Here we give users the opportunity to add their own function level MSOS headers for instance.
|
||||||
|
// This is useful when DFU functionality is part of a composite USB device.
|
||||||
|
func_modifier(&mut func);
|
||||||
|
|
||||||
let mut iface = func.interface();
|
let mut iface = func.interface();
|
||||||
let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_RT, None);
|
let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_RT, None);
|
||||||
let timeout = timeout.as_millis() as u16;
|
let timeout = timeout.as_millis() as u16;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterError};
|
use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterError};
|
||||||
use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType};
|
use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType};
|
||||||
use embassy_usb::driver::Driver;
|
use embassy_usb::driver::Driver;
|
||||||
use embassy_usb::{Builder, Handler};
|
use embassy_usb::{Builder, FunctionBuilder, Handler};
|
||||||
use embedded_storage::nor_flash::{NorFlash, NorFlashErrorKind};
|
use embedded_storage::nor_flash::{NorFlash, NorFlashErrorKind};
|
||||||
|
|
||||||
use crate::consts::{
|
use crate::consts::{
|
||||||
@ -186,8 +186,14 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Ha
|
|||||||
pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize>(
|
pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize>(
|
||||||
builder: &mut Builder<'d, D>,
|
builder: &mut Builder<'d, D>,
|
||||||
handler: &'d mut Control<'d, DFU, STATE, RST, BLOCK_SIZE>,
|
handler: &'d mut Control<'d, DFU, STATE, RST, BLOCK_SIZE>,
|
||||||
|
func_modifier: impl Fn(&mut FunctionBuilder<'_, 'd, D>),
|
||||||
) {
|
) {
|
||||||
let mut func = builder.function(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU);
|
let mut func = builder.function(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU);
|
||||||
|
|
||||||
|
// Here we give users the opportunity to add their own function level MSOS headers for instance.
|
||||||
|
// This is useful when DFU functionality is part of a composite USB device.
|
||||||
|
func_modifier(&mut func);
|
||||||
|
|
||||||
let mut iface = func.interface();
|
let mut iface = func.interface();
|
||||||
let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, None);
|
let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, None);
|
||||||
alt.descriptor(
|
alt.descriptor(
|
||||||
|
|||||||
@ -13,7 +13,7 @@ use embassy_stm32::usb::{self, Driver};
|
|||||||
use embassy_stm32::{bind_interrupts, peripherals};
|
use embassy_stm32::{bind_interrupts, peripherals};
|
||||||
use embassy_sync::blocking_mutex::Mutex;
|
use embassy_sync::blocking_mutex::Mutex;
|
||||||
use embassy_time::Duration;
|
use embassy_time::Duration;
|
||||||
use embassy_usb::Builder;
|
use embassy_usb::{msos, Builder};
|
||||||
use embassy_usb_dfu::consts::DfuAttributes;
|
use embassy_usb_dfu::consts::DfuAttributes;
|
||||||
use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate};
|
use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate};
|
||||||
use panic_reset as _;
|
use panic_reset as _;
|
||||||
@ -22,6 +22,11 @@ bind_interrupts!(struct Irqs {
|
|||||||
USB_LP => usb::InterruptHandler<peripherals::USB>;
|
USB_LP => usb::InterruptHandler<peripherals::USB>;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// This is a randomly generated GUID to allow clients on Windows to find your device.
|
||||||
|
//
|
||||||
|
// N.B. update to a custom GUID for your own device!
|
||||||
|
const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"];
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = embassy_stm32::Config::default();
|
let mut config = embassy_stm32::Config::default();
|
||||||
@ -54,7 +59,28 @@ async fn main(_spawner: Spawner) {
|
|||||||
&mut control_buf,
|
&mut control_buf,
|
||||||
);
|
);
|
||||||
|
|
||||||
usb_dfu(&mut builder, &mut state, Duration::from_millis(2500));
|
// 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 these always need to be at added at the device level for this to work and for
|
||||||
|
// composite devices they also need to be added on the function level (as shown later).
|
||||||
|
//
|
||||||
|
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(&mut builder, &mut state, Duration::from_millis(2500), |func| {
|
||||||
|
// You likely don't have to add these function level headers if your USB device is not composite
|
||||||
|
// (i.e. if your device does not expose another interface in addition to DFU)
|
||||||
|
func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
|
||||||
|
func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
|
||||||
|
"DeviceInterfaceGUIDs",
|
||||||
|
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
let mut dev = builder.build();
|
let mut dev = builder.build();
|
||||||
dev.run().await
|
dev.run().await
|
||||||
|
|||||||
@ -20,7 +20,9 @@ bind_interrupts!(struct Irqs {
|
|||||||
USB_LP => usb::InterruptHandler<peripherals::USB>;
|
USB_LP => usb::InterruptHandler<peripherals::USB>;
|
||||||
});
|
});
|
||||||
|
|
||||||
// This is a randomly generated GUID to allow clients on Windows to find our device
|
// This is a randomly generated GUID to allow clients on Windows to find your device.
|
||||||
|
//
|
||||||
|
// N.B. update to a custom GUID for your own device!
|
||||||
const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"];
|
const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"];
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
@ -68,7 +70,8 @@ fn main() -> ! {
|
|||||||
// We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows.
|
// 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.
|
// 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.
|
// It seems these always need to be at added at the device level for this to work and for
|
||||||
|
// composite devices they also need to be added on the function level (as shown later).
|
||||||
//
|
//
|
||||||
builder.msos_descriptor(msos::windows_version::WIN8_1, 2);
|
builder.msos_descriptor(msos::windows_version::WIN8_1, 2);
|
||||||
builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
|
builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
|
||||||
@ -77,7 +80,15 @@ fn main() -> ! {
|
|||||||
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
|
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
|
||||||
));
|
));
|
||||||
|
|
||||||
usb_dfu::<_, _, _, _, 4096>(&mut builder, &mut state);
|
usb_dfu::<_, _, _, _, 4096>(&mut builder, &mut state, |func| {
|
||||||
|
// You likely don't have to add these function level headers if your USB device is not composite
|
||||||
|
// (i.e. if your device does not expose another interface in addition to DFU)
|
||||||
|
func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
|
||||||
|
func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
|
||||||
|
"DeviceInterfaceGUIDs",
|
||||||
|
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
let mut dev = builder.build();
|
let mut dev = builder.build();
|
||||||
embassy_futures::block_on(dev.run());
|
embassy_futures::block_on(dev.run());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user