dfu.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2020 Mesotic SAS
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
21 #include <stdint.h>
22 
23 #include "usb.h"
24 #include "usb/descriptor.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define USB_IF_DESCRIPTOR_DFU 0x21
31 #define USB_DFU_VERSION_BCD 0x0110
37 #ifndef USB_DFU_DETACH_TIMEOUT_MS
38 #define USB_DFU_DETACH_TIMEOUT_MS 255
39 #endif
46 #define USB_DFU_CAN_DOWNLOAD 0x01
47 #define USB_DFU_CAN_UPLOAD 0x02
48 #define USB_DFU_MANIFEST_TOLERANT 0x04
49 #define USB_DFU_WILL_DETACH 0x08
56 #define USB_DFU_INTERFACE 0xFE
64 #define USB_DFU_SUBCLASS_DFU 0x01
71 #define USB_DFU_PROTOCOL_RUNTIME_MODE 0x01
72 #define USB_DFU_PROTOCOL_DFU_MODE 0x02
79 #define DFU_DETACH 0x00
80 #define DFU_DOWNLOAD 0x01
81 #define DFU_UPLOAD 0x02
82 #define DFU_GET_STATUS 0x03
83 #define DFU_CLR_STATUS 0x04
84 #define DFU_GET_STATE 0x05
85 #define DFU_ABORT 0x06
91 typedef enum {
104 
108 typedef struct __attribute__((packed)) {
109  uint8_t length;
110  uint8_t type;
111  uint8_t attribute;
112  uint16_t detach_timeout;
113  uint16_t xfer_size;
114  uint16_t bcd_dfu;
116 
120 typedef struct __attribute__((packed)) {
121  uint8_t status;
122  uint32_t timeout : 24;
123  uint8_t state;
124  uint8_t string;
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
Definitions for USB protocol messages.
usb_dfu_state_t
USBUS DFU internal state.
Definition: dfu.h:91
@ USB_DFU_STATE_DFU_UP_IDLE
DFU upload idle.
Definition: dfu.h:101
@ USB_DFU_STATE_DFU_MANIFEST
DFU manifest mode.
Definition: dfu.h:99
@ USB_DFU_STATE_DFU_MANIFEST_WAIT_RST
DFU manifest wait for CPU reset.
Definition: dfu.h:100
@ USB_DFU_STATE_DFU_ERROR
DFU internal error.
Definition: dfu.h:102
@ USB_DFU_STATE_DFU_DL_BUSY
DFU download busy.
Definition: dfu.h:96
@ USB_DFU_STATE_DFU_MANIFEST_SYNC
DFU manifest synchronization.
Definition: dfu.h:98
@ USB_DFU_STATE_DFU_IDLE
DFU runtime mode idle.
Definition: dfu.h:94
@ USB_DFU_STATE_DFU_DL_IDLE
DFU download idle.
Definition: dfu.h:97
@ USB_DFU_STATE_DFU_DL_SYNC
DFU download synchronization.
Definition: dfu.h:95
@ USB_DFU_STATE_APP_IDLE
DFU application idle.
Definition: dfu.h:92
@ USB_DFU_STATE_APP_DETACH
DFU application detach (reboot to DFU mode)
Definition: dfu.h:93
USB DFU get_status control request packet.
Definition: dfu.h:120
uint8_t state
DFU internal state machine.
Definition: dfu.h:123
uint32_t timeout
DFU timeout (ms) response.
Definition: dfu.h:122
uint8_t string
DFU string.
Definition: dfu.h:124
uint8_t status
DFU status response.
Definition: dfu.h:121
USB DFU interface descriptor.
Definition: dfu.h:108
uint8_t length
Descriptor length.
Definition: dfu.h:109
uint16_t bcd_dfu
Descriptor bcd version.
Definition: dfu.h:114
uint16_t xfer_size
Descriptor transaction size.
Definition: dfu.h:113
uint16_t detach_timeout
Descriptor detach timeout (ms)
Definition: dfu.h:112
uint8_t attribute
Descriptor attributes flags.
Definition: dfu.h:111
uint8_t type
Descriptor type.
Definition: dfu.h:110
Definition of global compile time configuration options.