1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
24
25
26
27
33
37
38
39
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
63
64
65
66
67
68
69
73
77
81
82
83
87
91
95
96
97
101
105
109
110
111
112
127
128
129
133
137
138
142
146
147
151
155
156
157
172
173
174
178
182
183
187
191
192
196
200
201
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
239
240
241
242
243
244
245
246
247
248
249
250
251
252
254
255
256
257
258
259
260
261
262
267
268
269
274
283
284
285
304
305
/* ... */
#include "main.h"
/* ... */
Includes
uint16_t VirtAddVarTab[NB_OF_VAR] = {0x5555, 0x6666, 0x7777};
uint16_t VarDataTab[NB_OF_VAR] = {0, 0, 0};
uint16_t VarValue,VarDataTmp = 0;Private variables
static void SystemClock_Config(void);
static void Error_Handler(void);
Private function prototypes
/* ... */
int main(void)
{
HAL_Init();
SystemClock_Config();
HAL_FLASH_Unlock();
BSP_LED_Init(LED1);
if( EE_Init() != EE_OK)
{
Error_Handler();
}if (EE_Init() != EE_OK) { ... }
for (VarValue = 1; VarValue <= 0x1000; VarValue++)
{
if((EE_WriteVariable(VirtAddVarTab[0], VarValue)) != HAL_OK)
{
Error_Handler();
}if ((EE_WriteVariable(VirtAddVarTab[0], VarValue)) != HAL_OK) { ... }
if((EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0])) != HAL_OK)
{
Error_Handler();
}if ((EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0])) != HAL_OK) { ... }
if (VarValue != VarDataTab[0])
{
Error_Handler();
}if (VarValue != VarDataTab[0]) { ... }
if(EE_WriteVariable(VirtAddVarTab[1], ~VarValue) != HAL_OK)
{
Error_Handler();
}if (EE_WriteVariable(VirtAddVarTab[1], ~VarValue) != HAL_OK) { ... }
if(EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]) != HAL_OK) { ... }
if(((uint16_t)~VarValue) != VarDataTab[1])
{
Error_Handler();
}if (((uint16_t)~VarValue) != VarDataTab[1]) { ... }
if(EE_WriteVariable(VirtAddVarTab[2], VarValue << 1) != HAL_OK)
{
Error_Handler();
}if (EE_WriteVariable(VirtAddVarTab[2], VarValue << 1) != HAL_OK) { ... }
if(EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]) != HAL_OK) { ... }
if ((VarValue << 1) != VarDataTab[2])
{
Error_Handler();
}if ((VarValue << 1) != VarDataTab[2]) { ... }
}for (VarValue = 1; VarValue <= 0x1000; VarValue++) { ... }
for (VarValue = 1; VarValue <= 0x2000; VarValue++)
{
if(EE_WriteVariable(VirtAddVarTab[1], VarValue) != HAL_OK)
{
Error_Handler();
}if (EE_WriteVariable(VirtAddVarTab[1], VarValue) != HAL_OK) { ... }
if(EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]) != HAL_OK) { ... }
if(VarValue != VarDataTab[1])
{
Error_Handler();
}if (VarValue != VarDataTab[1]) { ... }
}for (VarValue = 1; VarValue <= 0x2000; VarValue++) { ... }
if(EE_ReadVariable(VirtAddVarTab[0], &VarDataTmp) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[0], &VarDataTmp) != HAL_OK) { ... }
if (VarDataTmp != VarDataTab[0])
{
Error_Handler();
}if (VarDataTmp != VarDataTab[0]) { ... }
if(EE_ReadVariable(VirtAddVarTab[1], &VarDataTmp) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[1], &VarDataTmp) != HAL_OK) { ... }
if (VarDataTmp != VarDataTab[1])
{
Error_Handler();
}if (VarDataTmp != VarDataTab[1]) { ... }
if(EE_ReadVariable(VirtAddVarTab[2], &VarDataTmp) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[2], &VarDataTmp) != HAL_OK) { ... }
if (VarDataTmp != VarDataTab[2])
{
Error_Handler();
}if (VarDataTmp != VarDataTab[2]) { ... }
for (VarValue = 1; VarValue <= 0x3000; VarValue++)
{
if(EE_WriteVariable(VirtAddVarTab[2], VarValue) != HAL_OK)
{
Error_Handler();
}if (EE_WriteVariable(VirtAddVarTab[2], VarValue) != HAL_OK) { ... }
if(EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]) != HAL_OK) { ... }
if(VarValue != VarDataTab[2])
{
Error_Handler();
}if (VarValue != VarDataTab[2]) { ... }
}for (VarValue = 1; VarValue <= 0x3000; VarValue++) { ... }
if(EE_ReadVariable(VirtAddVarTab[0], &VarDataTmp) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[0], &VarDataTmp) != HAL_OK) { ... }
if (VarDataTmp != VarDataTab[0])
{
Error_Handler();
}if (VarDataTmp != VarDataTab[0]) { ... }
if(EE_ReadVariable(VirtAddVarTab[1], &VarDataTmp) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[1], &VarDataTmp) != HAL_OK) { ... }
if (VarDataTmp != VarDataTab[1])
{
Error_Handler();
}if (VarDataTmp != VarDataTab[1]) { ... }
if(EE_ReadVariable(VirtAddVarTab[2], &VarDataTmp) != HAL_OK)
{
Error_Handler();
}if (EE_ReadVariable(VirtAddVarTab[2], &VarDataTmp) != HAL_OK) { ... }
if (VarDataTmp != VarDataTab[2])
{
Error_Handler();
}if (VarDataTmp != VarDataTab[2]) { ... }
while (1)
{
BSP_LED_On(LED1);
}while (1) { ... }
}{ ... }
/* ... */
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
__HAL_RCC_PWR_CLK_ENABLE();
/* ... */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/* ... */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
if (HAL_GetREVID() >= 0x1001)
{
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
}if (HAL_GetREVID() >= 0x1001) { ... }
}{ ... }
/* ... */
static void Error_Handler(void)
{
while(1)
{
BSP_LED_Toggle(LED1);
HAL_Delay(40);
}while (1) { ... }
}{ ... }
#ifdef USE_FULL_ASSERT
/* ... */
void assert_failed(uint8_t* file, uint32_t line)
{
/* ... */
while (1)
{
}while (1) { ... }
}assert_failed (uint8_t* file, uint32_t line) { ... }
/* ... */#endif
/* ... */