STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbd_dfu.h
Go to the documentation of this file.
1 
28 /* Define to prevent recursive inclusion -------------------------------------*/
29 #ifndef __USB_DFU_H
30 #define __USB_DFU_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------*/
37 #include "usbd_ioreq.h"
38 
53 #define USB_DFU_CONFIG_DESC_SIZ (18 + (9 * USBD_DFU_MAX_ITF_NUM))
54 #define USB_DFU_DESC_SIZ 9
55 
56 #define DFU_DESCRIPTOR_TYPE 0x21
57 
58 
59 /**************************************************/
60 /* DFU Requests DFU states */
61 /**************************************************/
62 #define APP_STATE_IDLE 0
63 #define APP_STATE_DETACH 1
64 #define DFU_STATE_IDLE 2
65 #define DFU_STATE_DNLOAD_SYNC 3
66 #define DFU_STATE_DNLOAD_BUSY 4
67 #define DFU_STATE_DNLOAD_IDLE 5
68 #define DFU_STATE_MANIFEST_SYNC 6
69 #define DFU_STATE_MANIFEST 7
70 #define DFU_STATE_MANIFEST_WAIT_RESET 8
71 #define DFU_STATE_UPLOAD_IDLE 9
72 #define DFU_STATE_ERROR 10
73 
74 /**************************************************/
75 /* DFU errors */
76 /**************************************************/
77 #define DFU_ERROR_NONE 0x00
78 #define DFU_ERROR_TARGET 0x01
79 #define DFU_ERROR_FILE 0x02
80 #define DFU_ERROR_WRITE 0x03
81 #define DFU_ERROR_ERASE 0x04
82 #define DFU_ERROR_CHECK_ERASED 0x05
83 #define DFU_ERROR_PROG 0x06
84 #define DFU_ERROR_VERIFY 0x07
85 #define DFU_ERROR_ADDRESS 0x08
86 #define DFU_ERROR_NOTDONE 0x09
87 #define DFU_ERROR_FIRMWARE 0x0A
88 #define DFU_ERROR_VENDOR 0x0B
89 #define DFU_ERROR_USB 0x0C
90 #define DFU_ERROR_POR 0x0D
91 #define DFU_ERROR_UNKNOWN 0x0E
92 #define DFU_ERROR_STALLEDPKT 0x0F
93 
94 /**************************************************/
95 /* DFU Manifestation State */
96 /**************************************************/
97 #define DFU_MANIFEST_COMPLETE 0x00
98 #define DFU_MANIFEST_IN_PROGRESS 0x01
99 
100 
101 /**************************************************/
102 /* Special Commands with Download Request */
103 /**************************************************/
104 #define DFU_CMD_GETCOMMANDS 0x00
105 #define DFU_CMD_SETADDRESSPOINTER 0x21
106 #define DFU_CMD_ERASE 0x41
107 
108 #define DFU_MEDIA_ERASE 0x00
109 #define DFU_MEDIA_PROGRAM 0x01
110 
111 /**************************************************/
112 /* Other defines */
113 /**************************************************/
114 /* Bit Detach capable = bit 3 in bmAttributes field */
115 #define DFU_DETACH_MASK (uint8_t)(1 << 4)
116 #define DFU_STATUS_DEPTH (6)
117 
118 typedef enum
119 {
128 
129 typedef void (*pFunction)(void);
130 
131 
132 /********** Descriptor of DFU interface 0 Alternate setting n ****************/
133 #define USBD_DFU_IF_DESC(n) 0x09, /* bLength: Interface Descriptor size */ \
134  USB_DESC_TYPE_INTERFACE, /* bDescriptorType */ \
135  0x00, /* bInterfaceNumber: Number of Interface */ \
136  (n), /* bAlternateSetting: Alternate setting */ \
137  0x00, /* bNumEndpoints*/ \
138  0xFE, /* bInterfaceClass: Application Specific Class Code */ \
139  0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ \
140  0x02, /* nInterfaceProtocol: DFU mode protocol */ \
141  USBD_IDX_INTERFACE_STR + (n) + 1 /* iInterface: Index of string descriptor */ \
142 
143 #define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\
144  ((uint8_t)(size >> 8)) /* XFERSIZEB1 */
145 
146 #define IS_PROTECTED_AREA(add) (uint8_t)(((add >= 0x08000000) && (add < (APP_DEFAULT_ADD)))? 1:0)
147 
157 typedef struct
158 {
159  union
160  {
161  uint32_t d32[USBD_DFU_XFER_SIZE/4];
162  uint8_t d8[USBD_DFU_XFER_SIZE];
163  }buffer;
164 
165  uint8_t dev_state;
166  uint8_t dev_status[DFU_STATUS_DEPTH];
167  uint8_t manif_state;
168 
169  uint32_t wblock_num;
170  uint32_t wlength;
171  uint32_t data_ptr;
172  __IO uint32_t alt_setting;
173 
174 }
176 
177 
178 typedef struct
179 {
180  const uint8_t* pStrDesc;
181  uint16_t (* Init) (void);
182  uint16_t (* DeInit) (void);
183  uint16_t (* Erase) (uint32_t Add);
184  uint16_t (* Write) (uint8_t *src, uint8_t *dest, uint32_t Len);
185  uint8_t* (* Read) (uint8_t *src, uint8_t *dest, uint32_t Len);
186  uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
187 }
208 #define USBD_DFU_CLASS &USBD_DFU
209 
217  USBD_DFU_MediaTypeDef *fops);
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif /* __USB_DFU_H */
227 
235 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__IO uint32_t alt_setting
Definition: usbd_dfu.h:172
#define __IO
Definition: core_cm0.h:213
Header file for the usbd_ioreq.c file.
void(* pFunction)(void)
Definition: usbd_dfu.h:129
#define DFU_STATUS_DEPTH
Definition: usbd_dfu.h:116
const uint8_t * pStrDesc
Definition: usbd_dfu.h:180
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev, USBD_DFU_MediaTypeDef *fops)
USBD_DFU_GetUsrStringDesc Manages the transfer of memory interfaces string descriptors.
Definition: usbd_dfu.c:674
USBD_ClassTypeDef USBD_DFU
Definition: usbd_dfu.c:167
DFU_RequestTypeDef
Definition: usbd_dfu.h:118