aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb-dfu
diff options
context:
space:
mode:
authorKrzysztof Królczyk <[email protected]>2025-02-10 17:32:16 +0100
committerKrzysztof Królczyk <[email protected]>2025-02-11 10:08:47 +0100
commite173db1151585702912b572c5195bd23fb4267fe (patch)
tree60e56a795bdd5658cefc36a792d458cb90f1c56a /embassy-usb-dfu
parent4b809af90538b83de42d60eb6ac5b8509feaeecf (diff)
doc: add docu strings for dfu
Signed-off-by: Krzysztof Królczyk <[email protected]>
Diffstat (limited to 'embassy-usb-dfu')
-rw-r--r--embassy-usb-dfu/src/consts.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/embassy-usb-dfu/src/consts.rs b/embassy-usb-dfu/src/consts.rs
index 190b5ad5a..8701dabc4 100644
--- a/embassy-usb-dfu/src/consts.rs
+++ b/embassy-usb-dfu/src/consts.rs
@@ -1,10 +1,16 @@
1//! USB DFU constants. 1//! USB DFU constants, taken from
2//! https://www.usb.org/sites/default/files/DFU_1.1.pdf
3/// Device Firmware Upgrade class, App specific
2pub(crate) const USB_CLASS_APPN_SPEC: u8 = 0xFE; 4pub(crate) const USB_CLASS_APPN_SPEC: u8 = 0xFE;
5/// Device Firmware Upgrade subclass, App specific
3pub(crate) const APPN_SPEC_SUBCLASS_DFU: u8 = 0x01; 6pub(crate) const APPN_SPEC_SUBCLASS_DFU: u8 = 0x01;
4#[allow(unused)] 7#[allow(unused)]
8/// USB interface alternative setting
5pub(crate) const DFU_PROTOCOL_DFU: u8 = 0x02; 9pub(crate) const DFU_PROTOCOL_DFU: u8 = 0x02;
6#[allow(unused)] 10#[allow(unused)]
11/// DFU runtime class
7pub(crate) const DFU_PROTOCOL_RT: u8 = 0x01; 12pub(crate) const DFU_PROTOCOL_RT: u8 = 0x01;
13/// DFU functional descriptor
8pub(crate) const DESC_DFU_FUNCTIONAL: u8 = 0x21; 14pub(crate) const DESC_DFU_FUNCTIONAL: u8 = 0x21;
9 15
10macro_rules! define_dfu_attributes { 16macro_rules! define_dfu_attributes {
@@ -34,51 +40,89 @@ define_dfu_attributes!(bitflags::bitflags);
34#[derive(Copy, Clone, PartialEq, Eq)] 40#[derive(Copy, Clone, PartialEq, Eq)]
35#[repr(u8)] 41#[repr(u8)]
36#[allow(unused)] 42#[allow(unused)]
43/// An indication of the state that the device is going to enter immediately following transmission of this response.
37pub(crate) enum State { 44pub(crate) enum State {
45 /// Device is running its normal application.
38 AppIdle = 0, 46 AppIdle = 0,
47 /// Device is running its normal application, has received the DFU_DETACH request, and is waiting for a USB reset.
39 AppDetach = 1, 48 AppDetach = 1,
49 /// Device is operating in the DFU mode and is waiting for requests.
40 DfuIdle = 2, 50 DfuIdle = 2,
51 /// Device has received a block and is waiting for the host to solicit the status via DFU_GETSTATUS.
41 DlSync = 3, 52 DlSync = 3,
53 /// Device is programming a control-write block into its nonvolatile memories.
42 DlBusy = 4, 54 DlBusy = 4,
55 /// Device is processing a download operation. Expecting DFU_DNLOAD requests.
43 Download = 5, 56 Download = 5,
57 /// Device has received the final block of firmware from the host, waits for DFU_GETSTATUS to start Manifestation phase or completed this phase
44 ManifestSync = 6, 58 ManifestSync = 6,
59 /// Device is in the Manifestation phase. Not all devices will be able to respond to DFU_GETSTATUS when in this state.
45 Manifest = 7, 60 Manifest = 7,
61 /// Device has programmed its memories and is waiting for a USB reset or a power on reset.
46 ManifestWaitReset = 8, 62 ManifestWaitReset = 8,
63 /// The device is processing an upload operation. Expecting DFU_UPLOAD requests.
47 UploadIdle = 9, 64 UploadIdle = 9,
65 /// An error has occurred. Awaiting the DFU_CLRSTATUS request.
48 Error = 10, 66 Error = 10,
49} 67}
50 68
51#[derive(Copy, Clone, PartialEq, Eq)] 69#[derive(Copy, Clone, PartialEq, Eq)]
52#[repr(u8)] 70#[repr(u8)]
53#[allow(unused)] 71#[allow(unused)]
72/// An indication of the status resulting from the execution of the most recent request.
54pub(crate) enum Status { 73pub(crate) enum Status {
74 /// No error
55 Ok = 0x00, 75 Ok = 0x00,
76 /// File is not targeted for use by this device
56 ErrTarget = 0x01, 77 ErrTarget = 0x01,
78 /// File is for this device but fails some vendor-specific verification test
57 ErrFile = 0x02, 79 ErrFile = 0x02,
80 /// Device is unable to write memory
58 ErrWrite = 0x03, 81 ErrWrite = 0x03,
82 /// Memory erase function failed
59 ErrErase = 0x04, 83 ErrErase = 0x04,
84 /// Memory erase check failed
60 ErrCheckErased = 0x05, 85 ErrCheckErased = 0x05,
86 /// Program memory function failed
61 ErrProg = 0x06, 87 ErrProg = 0x06,
88 /// Programmed memory failed verification
62 ErrVerify = 0x07, 89 ErrVerify = 0x07,
90 /// Cannot program memory due to received address that is out of range
63 ErrAddress = 0x08, 91 ErrAddress = 0x08,
92 /// Received DFU_DNLOAD with wLength = 0, but device does not think it has all of the data yet
64 ErrNotDone = 0x09, 93 ErrNotDone = 0x09,
94 /// Device’s firmware is corrupt. It cannot return to run-time (non-DFU) operations
65 ErrFirmware = 0x0A, 95 ErrFirmware = 0x0A,
96 /// iString indicates a vendor-specific error
66 ErrVendor = 0x0B, 97 ErrVendor = 0x0B,
98 /// Device detected unexpected USB reset signaling
67 ErrUsbr = 0x0C, 99 ErrUsbr = 0x0C,
100 /// Device detected unexpected power on reset
68 ErrPor = 0x0D, 101 ErrPor = 0x0D,
102 /// Something went wrong, but the device does not know what
69 ErrUnknown = 0x0E, 103 ErrUnknown = 0x0E,
104 /// Device stalled an unexpected request
70 ErrStalledPkt = 0x0F, 105 ErrStalledPkt = 0x0F,
71} 106}
72 107
73#[derive(Copy, Clone, PartialEq, Eq)] 108#[derive(Copy, Clone, PartialEq, Eq)]
74#[repr(u8)] 109#[repr(u8)]
110/// DFU requests
75pub(crate) enum Request { 111pub(crate) enum Request {
112 /// Host instructs the device to generate a detach-attach sequence
76 Detach = 0, 113 Detach = 0,
114 /// Host initiates control-write transfers with this request, and sends a DFU_DNLOAD request
115 /// with wLength = 0 to indicate that it has completed transferring the firmware image file
77 Dnload = 1, 116 Dnload = 1,
117 /// The DFU_UPLOAD request is employed by the host to solicit firmware from the device.
78 Upload = 2, 118 Upload = 2,
119 /// The host employs the DFU_GETSTATUS request to facilitate synchronization with the device.
79 GetStatus = 3, 120 GetStatus = 3,
121 /// Any time the device detects an error, it waits with transition until ClrStatus
80 ClrStatus = 4, 122 ClrStatus = 4,
123 /// Requests a report about a state of the device
81 GetState = 5, 124 GetState = 5,
125 /// Enables the host to exit from certain states and return to the DFU_IDLE state
82 Abort = 6, 126 Abort = 6,
83} 127}
84 128