1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
22
23
28
29
36
40
41
42
47
48
49
50
51
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
89
96
97
98
100
101
102
104
105
106
108
109
114
115
116
117
119
120
126
127
128
133
134
135
136
137
138
140
141
142
143
144
146
147
148
149
150
151
152
157
158
159
160
165
174
175
180
190
191
196
206
207
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* ... */
#include "main.h"
Includes
#define DEMO_INIT ((uint8_t)0x00)
#define DEMO_IAP ((uint8_t)0x01)
Private define
__IO uint32_t UploadCondition = 0x00;
DIR dir;
FILINFO fno;
static uint8_t Demo_State = DEMO_INIT;
extern char USBDISKPath[4];
Private variables
static void IAP_UploadTimeout(void);
static void USBH_USR_BufferSizeControl(void);
Private function prototypes
/* ... */
void FW_UPGRADE_Process(void)
{
switch(Demo_State)
{
case DEMO_INIT:
if (FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0)
{
if (f_mount(&USBH_fatfs, "", 0) != FR_OK)
{
FatFs_Fail_Handler();
}if (f_mount(&USBH_fatfs, "", 0) != FR_OK) { ... }
}if (FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0) { ... }
Demo_State = DEMO_IAP;
break;
case DEMO_INIT:
case DEMO_IAP:
while(USBH_MSC_IsReady(&hUSBHost))
{
USBH_USR_BufferSizeControl();
BSP_LED_Off(LED1);
BSP_LED_Off(LED3);
IAP_UploadTimeout();
COMMAND_Download();
if((UploadCondition == 0x01))
{
COMMAND_Upload();
}if ((UploadCondition == 0x01)) { ... }
else
{
BSP_LED_Off(LED2);
BSP_LED_On(LED1);
}else { ... }
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)) { ... }
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)) { ... }
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)
{
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)
{
BSP_LED_Toggle(LED3);
HAL_Delay(100);
}if (Appli_state == APPLICATION_DISCONNECT) { ... }
}{ ... }
/* ... */
static void IAP_UploadTimeout(void)
{
if(BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET)
{
/* ... */
HAL_Delay (3000);
if(BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET)
{
/* ... */
UploadCondition = 0x01;
BSP_LED_On(LED3);
}if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { ... }
else
{
UploadCondition = 0x00;
}else { ... }
}if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { ... }
}{ ... }
/* ... */
void Fail_Handler(void)
{
while(1)
{
BSP_LED_Toggle(LED3);
HAL_Delay(100);
}while (1) { ... }
}{ ... }
/* ... */
void Erase_Fail_Handler(void)
{
while(1)
{
BSP_LED_Toggle(LED2);
BSP_LED_Toggle(LED3);
HAL_Delay(100);
}while (1) { ... }
}{ ... }
/* ... */
void FatFs_Fail_Handler(void)
{
while(1)
{
BSP_LED_Toggle(LED3);
BSP_LED_Toggle(LED4);
HAL_Delay(100);
}while (1) { ... }
}{ ... }
/* ... */
static void USBH_USR_BufferSizeControl(void)
{
if((BUFFER_SIZE % 4 != 0x00) || (BUFFER_SIZE / 4 > 8192))
{
while(1)
{
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)) { ... }
}{ ... }