Merge pull request #93 from zyp/master
[fw/stlink] / example / stm32f4 / STM32_USB_Device_Library / Class / dfu / inc / usbd_dfu_core.h
1 /**
2   ******************************************************************************
3   * @file    usbd_dfu_core.h
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @date    22-July-2011
7   * @brief   header file for the usbd_dfu_core.c file.
8   ******************************************************************************
9   * @attention
10   *
11   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17   *
18   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19   ******************************************************************************
20   */ 
21
22 /* Includes ------------------------------------------------------------------*/
23
24 #ifndef __USB_DFU_CORE_H_
25 #define __USB_DFU_CORE_H_
26
27 #include  "usbd_ioreq.h"
28 #include  "usbd_dfu_mal.h"
29
30 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
31   * @{
32   */
33   
34 /** @defgroup usbd_dfu
35   * @brief This file is the Header file for USBD_dfu.c
36   * @{
37   */ 
38
39
40 /** @defgroup usbd_dfu_Exported_Defines
41   * @{
42   */ 
43 #define USB_DFU_CONFIG_DESC_SIZ       (18 + (9 * USBD_ITF_MAX_NUM))
44 #define USB_DFU_DESC_SIZ              9
45
46 #define DFU_DESCRIPTOR_TYPE           0x21
47
48
49 /*---------------------------------------------------------------------*/
50 /*  DFU definitions                                                    */
51 /*---------------------------------------------------------------------*/
52
53
54
55 /**************************************************/
56 /* DFU Requests  DFU states                       */
57 /**************************************************/
58
59
60 #define STATE_appIDLE                 0
61 #define STATE_appDETACH               1
62 #define STATE_dfuIDLE                 2
63 #define STATE_dfuDNLOAD_SYNC          3
64 #define STATE_dfuDNBUSY               4
65 #define STATE_dfuDNLOAD_IDLE          5
66 #define STATE_dfuMANIFEST_SYNC        6
67 #define STATE_dfuMANIFEST             7
68 #define STATE_dfuMANIFEST_WAIT_RESET  8
69 #define STATE_dfuUPLOAD_IDLE          9
70 #define STATE_dfuERROR                10
71
72 /**************************************************/
73 /* DFU Requests  DFU status                       */
74 /**************************************************/
75
76 #define STATUS_OK                   0x00
77 #define STATUS_ERRTARGET            0x01
78 #define STATUS_ERRFILE              0x02
79 #define STATUS_ERRWRITE             0x03
80 #define STATUS_ERRERASE             0x04
81 #define STATUS_ERRCHECK_ERASED      0x05
82 #define STATUS_ERRPROG              0x06
83 #define STATUS_ERRVERIFY            0x07
84 #define STATUS_ERRADDRESS           0x08
85 #define STATUS_ERRNOTDONE           0x09
86 #define STATUS_ERRFIRMWARE          0x0A
87 #define STATUS_ERRVENDOR            0x0B
88 #define STATUS_ERRUSBR              0x0C
89 #define STATUS_ERRPOR               0x0D
90 #define STATUS_ERRUNKNOWN           0x0E
91 #define STATUS_ERRSTALLEDPKT        0x0F
92
93 /**************************************************/
94 /* DFU Requests  DFU states Manifestation State   */
95 /**************************************************/
96
97 #define Manifest_complete           0x00
98 #define Manifest_In_Progress        0x01
99
100
101 /**************************************************/
102 /* Special Commands  with Download Request        */
103 /**************************************************/
104
105 #define CMD_GETCOMMANDS              0x00
106 #define CMD_SETADDRESSPOINTER        0x21
107 #define CMD_ERASE                    0x41
108
109 /**************************************************/
110 /* Other defines                                  */
111 /**************************************************/
112 /* Bit Detach capable = bit 3 in bmAttributes field */
113 #define DFU_DETACH_MASK              (uint8_t)(1 << 4) 
114 /**
115   * @}
116   */ 
117
118
119 /** @defgroup USBD_CORE_Exported_TypesDefinitions
120   * @{
121   */
122 /**************************************************/
123 /* DFU Requests                                   */
124 /**************************************************/
125
126 typedef enum _DFU_REQUESTS {
127   DFU_DETACH = 0,
128   DFU_DNLOAD = 1,
129   DFU_UPLOAD,
130   DFU_GETSTATUS,
131   DFU_CLRSTATUS,
132   DFU_GETSTATE,
133   DFU_ABORT
134 } DFU_REQUESTS;
135
136 typedef  void (*pFunction)(void);
137 /**
138   * @}
139   */ 
140
141
142
143 /** @defgroup USBD_CORE_Exported_Macros
144   * @{
145   */ 
146 /**********  Descriptor of DFU interface 0 Alternate setting n ****************/  
147 #define USBD_DFU_IF_DESC(n)   0x09,   /* bLength: Interface Descriptor size */ \
148                               USB_INTERFACE_DESCRIPTOR_TYPE,   /* bDescriptorType */ \
149                               0x00,   /* bInterfaceNumber: Number of Interface */ \
150                               (n),      /* bAlternateSetting: Alternate setting */ \
151                               0x00,   /* bNumEndpoints*/ \
152                               0xFE,   /* bInterfaceClass: Application Specific Class Code */ \
153                               0x01,   /* bInterfaceSubClass : Device Firmware Upgrade Code */ \
154                               0x02,   /* nInterfaceProtocol: DFU mode protocol */ \
155                               USBD_IDX_INTERFACE_STR + (n) + 1 /* iInterface: Index of string descriptor */ \
156                               /* 18 */
157   
158 /**
159   * @}
160   */ 
161
162 /** @defgroup USBD_CORE_Exported_Variables
163   * @{
164   */ 
165
166 extern USBD_Class_cb_TypeDef  DFU_cb;
167 /**
168   * @}
169   */ 
170
171 /** @defgroup USB_CORE_Exported_Functions
172   * @{
173   */
174 /**
175   * @}
176   */ 
177
178 #endif  // __USB_DFU_CORE_H_
179 /**
180   * @}
181   */ 
182
183 /**
184   * @}
185   */ 
186   
187 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/