update dfu demo and driver
This commit is contained in:
@@ -76,27 +76,62 @@
|
||||
#define DFU_STATE_DFU_UPLOAD_IDLE 9U
|
||||
#define DFU_STATE_DFU_ERROR 10U
|
||||
|
||||
/** DFU Manifestation State */
|
||||
#define DFU_MANIFEST_COMPLETE 0U
|
||||
#define DFU_MANIFEST_IN_PROGRESS 1U
|
||||
|
||||
/** Special Commands with Download Request */
|
||||
#define DFU_CMD_GETCOMMANDS 0U
|
||||
#define DFU_CMD_SETADDRESSPOINTER 0x21U
|
||||
#define DFU_CMD_ERASE 0x41U
|
||||
#define DFU_MEDIA_ERASE 0x00U
|
||||
#define DFU_MEDIA_PROGRAM 0x01U
|
||||
|
||||
/** Other defines */
|
||||
/* Bit Detach capable = bit 3 in bmAttributes field */
|
||||
#define DFU_DETACH_MASK (1U << 3)
|
||||
#define DFU_MANIFEST_MASK (1U << 2)
|
||||
|
||||
/** Run-Time Functional Descriptor */
|
||||
struct dfu_runtime_descriptor {
|
||||
uint8_t bLength; /**<\brief Descriptor length in bytes.*/
|
||||
uint8_t bDescriptorType; /**<\brief DFU functional descriptor type.*/
|
||||
uint8_t bmAttributes; /**<\brief USB DFU capabilities \ref USB_DFU_CAPAB*/
|
||||
uint16_t wDetachTimeout; /**<\brief USB DFU detach timeout in ms.*/
|
||||
uint16_t wTransferSize; /**<\brief USB DFU maximum transfer block size in bytes.*/
|
||||
uint16_t bcdDFUVersion; /**<\brief USB DFU version \ref VERSION_BCD utility macro.*/
|
||||
uint8_t bLength; /**<\brief Descriptor length in bytes.*/
|
||||
uint8_t bDescriptorType; /**<\brief DFU functional descriptor type.*/
|
||||
uint8_t bmAttributes; /**<\brief USB DFU capabilities \ref USB_DFU_CAPAB*/
|
||||
uint16_t wDetachTimeout; /**<\brief USB DFU detach timeout in ms.*/
|
||||
uint16_t wTransferSize; /**<\brief USB DFU maximum transfer block size in bytes.*/
|
||||
uint16_t bcdDFUVersion; /**<\brief USB DFU version \ref VERSION_BCD utility macro.*/
|
||||
} __PACKED;
|
||||
|
||||
/**\brief Payload packet to response in DFU_GETSTATUS request */
|
||||
struct dfu_info {
|
||||
uint8_t bStatus; /**<\brief An indication of the status resulting from the
|
||||
uint8_t bStatus; /**<\brief An indication of the status resulting from the
|
||||
* execution of the most recent request.*/
|
||||
uint8_t bPollTimeout; /**<\brief Minimum time (LSB) in ms, that the host should wait
|
||||
uint8_t bPollTimeout; /**<\brief Minimum time (LSB) in ms, that the host should wait
|
||||
* before sending a subsequent DFU_GETSTATUS request.*/
|
||||
uint16_t wPollTimeout; /**<\brief Minimum time (MSB) in ms, that the host should wait
|
||||
uint16_t wPollTimeout; /**<\brief Minimum time (MSB) in ms, that the host should wait
|
||||
* before sending a subsequent DFU_GETSTATUS request.*/
|
||||
uint8_t bState; /**<\brief An indication of the state that the device is going
|
||||
uint8_t bState; /**<\brief An indication of the state that the device is going
|
||||
* to enter immediately following transmission of this response.*/
|
||||
uint8_t iString; /**<\brief Index of the status string descriptor.*/
|
||||
uint8_t iString; /**<\brief Index of the status string descriptor.*/
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
#define DFU_DESCRIPTOR_INIT() \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
0x00, /* bInterfaceNumber */ \
|
||||
0x00, /* bAlternateSetting */ \
|
||||
0x00, /* bNumEndpoints Default Control Pipe only */ \
|
||||
USB_DEVICE_CLASS_APP_SPECIFIC, /* bInterfaceClass */ \
|
||||
0x01, /* bInterfaceSubClass Device Firmware Upgrade */ \
|
||||
0x02, /* bInterfaceProtocol DFU mode */ \
|
||||
0x04, /* iInterface */ /*!< Device Firmware Update Functional Descriptor */ \
|
||||
0x09, /* bLength */ \
|
||||
0x21, /* DFU Functional Descriptor */ \
|
||||
0x0B, /* bmAttributes */ \
|
||||
WBVAL(0x00ff), /* wDetachTimeOut */ \
|
||||
WBVAL(USBD_DFU_XFER_SIZE), /* wTransferSize */ \
|
||||
WBVAL(0x011a) /* bcdDFUVersion */
|
||||
// clang-format on
|
||||
|
||||
#endif /* USB_DFU_H */
|
||||
|
||||
Reference in New Issue
Block a user