Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
#define DEMO_INIT
#define DEMO_IAP
Private variables
UploadCondition
dir
fno
Demo_State
Private function prototypes
FW_UPGRADE_Process()
IAP_UploadTimeout()
Fail_Handler()
Erase_Fail_Handler()
FatFs_Fail_Handler()
USBH_USR_BufferSizeControl()
Files
loading...
CodeScopeSTM32 Libraries and SamplesFWupgrade_StandaloneSrc/iap_menu.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file USB_Host/FWupgrade_Standalone/Src/iap_menu.c * @author MCD Application Team * @brief COMMAND IAP Execute Application ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* State Machine for the DEMO State */ #define DEMO_INIT ((uint8_t)0x00) #define DEMO_IAP ((uint8_t)0x01) Private define /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ __IO uint32_t UploadCondition = 0x00; DIR dir; FILINFO fno; static uint8_t Demo_State = DEMO_INIT; extern char USBDISKPath[4]; Private variables /* Private function prototypes -----------------------------------------------*/ static void IAP_UploadTimeout(void); static void USBH_USR_BufferSizeControl(void); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Demo application for IAP through USB mass storage. * @param None * @retval None *//* ... */ void FW_UPGRADE_Process(void) { switch(Demo_State) { case DEMO_INIT: /* Register the file system object to the FatFs module */ if (FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0) { if (f_mount(&USBH_fatfs, "", 0) != FR_OK) { /* FatFs initialization fails */ /* Toggle LED3 and LED4 in infinite loop */ FatFs_Fail_Handler(); }if (f_mount(&USBH_fatfs, "", 0) != FR_OK) { ... } }if (FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0) { ... } /* Go to IAP menu */ Demo_State = DEMO_IAP; break; case DEMO_INIT: case DEMO_IAP: while(USBH_MSC_IsReady(&hUSBHost)) { /* Control BUFFER_SIZE value */ USBH_USR_BufferSizeControl(); /* Keep LED1 and LED3 Off when Device connected */ BSP_LED_Off(LED1); BSP_LED_Off(LED3); /* KEY Button pressed Delay */ IAP_UploadTimeout(); /* Writes Flash memory */ COMMAND_Download(); /* Check if KEY Button is already pressed */ if((UploadCondition == 0x01)) { /* Reads all flash memory */ COMMAND_Upload(); }if ((UploadCondition == 0x01)) { ... } else { /* Turn LED2 Off: Download Done */ BSP_LED_Off(LED2); /* Turn LED1 On: Waiting KEY button pressed */ BSP_LED_On(LED1); }else { ... } /* Waiting KEY Button Released */ while((BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY)) {}while ((BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY)) { ... } /* Waiting KEY Button Pressed */ while((BSP_PB_GetState(BUTTON_KEY) != GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY)) {}while ((BSP_PB_GetState(BUTTON_KEY) != GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY)) { ... } /* Waiting KEY Button Released */ while((BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY)) {}while ((BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY)) { ... } if(Appli_state == APPLICATION_READY) { /* Jump to user application code located in the internal Flash memory */ COMMAND_Jump(); }if (Appli_state == APPLICATION_READY) { ... } }while (USBH_MSC_IsReady(&hUSBHost)) { ... } break; case DEMO_IAP: default: break;default }switch (Demo_State) { ... } if(Appli_state == APPLICATION_DISCONNECT) { /* Toggle LED3: USB device disconnected */ BSP_LED_Toggle(LED3); HAL_Delay(100); }if (Appli_state == APPLICATION_DISCONNECT) { ... } }{ ... } /** * @brief Button state time control. * @param None * @retval None *//* ... */ static void IAP_UploadTimeout(void) { /* Check if KEY button is pressed */ if(BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { /* To execute the UPLOAD command the KEY button should be kept pressed 3s just after a board reset, at firmware startup *//* ... */ HAL_Delay (3000); if(BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { /* UPLOAD command will be executed immediately after completed execution of the DOWNLOAD command *//* ... */ UploadCondition = 0x01; /* Turn LED3 on : Upload condition Verified */ BSP_LED_On(LED3); }if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { ... } else { /* Only the DOWNLOAD command is executed */ UploadCondition = 0x00; }else { ... } }if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { ... } }{ ... } /** * @brief Handles the program fail. * @param None * @retval None *//* ... */ void Fail_Handler(void) { while(1) { /* Toggle LED3 */ BSP_LED_Toggle(LED3); HAL_Delay(100); }while (1) { ... } }{ ... } /** * @brief Handles the Flash Erase fail. * @param None * @retval None *//* ... */ void Erase_Fail_Handler(void) { while(1) { /* Toggle LED2 and LED3 */ BSP_LED_Toggle(LED2); BSP_LED_Toggle(LED3); HAL_Delay(100); }while (1) { ... } }{ ... } /** * @brief Handles the FatFs fail. * @param None * @retval None *//* ... */ void FatFs_Fail_Handler(void) { while(1) { /* Toggle LED3 and LED4 */ BSP_LED_Toggle(LED3); BSP_LED_Toggle(LED4); HAL_Delay(100); }while (1) { ... } }{ ... } /** * @brief Controls Buffer size value. * @param None * @retval None *//* ... */ static void USBH_USR_BufferSizeControl(void) { /* Control BUFFER_SIZE and limit this value to 32Kbyte maximum */ if((BUFFER_SIZE % 4 != 0x00) || (BUFFER_SIZE / 4 > 8192)) { while(1) { /* Toggle LED2, LED3 and LED4 */ BSP_LED_Toggle(LED2); BSP_LED_Toggle(LED3); BSP_LED_Toggle(LED4); HAL_Delay(100); }while (1) { ... } }if ((BUFFER_SIZE % 4 != 0x00) || (BUFFER_SIZE / 4 > 8192)) { ... } }{ ... }