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
75
76
79
80
84
85
88
91
92
95
98
99
102
105
106
109
110
111
112
113
116
117
120
123
124
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
153
154
155
156
160
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
189
190
191
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
227
228
229
230
231
232
233
237
238
239
244
245
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
289
290
291
292
293
294
295
296
297
298
302
303
304
305
306
307
317
318
319
320
321
322
323
324
325
327
328
329
330
331
332
333
337
338
339
340
341
342
346
347
357
358
359
360
361
362
363
364
365
366
367
368
369
370
374
375
376
377
378
379
380
381
382
383
387
388
389
390
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
431
432
435
438
439
442
443
446
447
450
451
/* ... */
#include "stm32469i_discovery_eeprom.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
__IO uint16_t EEPROMAddress = 0;
__IO uint32_t EEPROMTimeout = EEPROM_READ_TIMEOUT;
__IO uint16_t EEPROMDataRead;
__IO uint8_t EEPROMDataWrite;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint32_t BSP_EEPROM_Init(void)
{
EEPROM_IO_Init();
EEPROMAddress = EEPROM_I2C_ADDRESS_A01;
if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
{
EEPROMAddress = EEPROM_I2C_ADDRESS_A02;
if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
{
return EEPROM_FAIL;
}if (EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK) { ... }
}if (EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK) { ... }
return EEPROM_OK;
}{ ... }
/* ... */
uint8_t BSP_EEPROM_DeInit(void)
{
return EEPROM_OK;
}{ ... }
/* ... */
uint32_t BSP_EEPROM_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
{
uint32_t buffersize = *NumByteToRead;
/* ... */
EEPROMDataRead = *NumByteToRead;
if(EEPROM_IO_ReadData(EEPROMAddress, ReadAddr, pBuffer, buffersize) != HAL_OK)
{
BSP_EEPROM_TIMEOUT_UserCallback();
return EEPROM_FAIL;
}if (EEPROM_IO_ReadData(EEPROMAddress, ReadAddr, pBuffer, buffersize) != HAL_OK) { ... }
return EEPROM_OK;
}{ ... }
/* ... */
uint32_t BSP_EEPROM_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
{
uint32_t buffersize = *NumByteToWrite;
uint32_t status = EEPROM_OK;
/* ... */
EEPROMDataWrite = *NumByteToWrite;
if(EEPROM_IO_WriteData(EEPROMAddress, WriteAddr, pBuffer, buffersize) != HAL_OK)
{
BSP_EEPROM_TIMEOUT_UserCallback();
status = EEPROM_FAIL;
}if (EEPROM_IO_WriteData(EEPROMAddress, WriteAddr, pBuffer, buffersize) != HAL_OK) { ... }
if(BSP_EEPROM_WaitEepromStandbyState() != EEPROM_OK)
{
return EEPROM_FAIL;
}if (BSP_EEPROM_WaitEepromStandbyState() != EEPROM_OK) { ... }
return status;
}{ ... }
/* ... */
uint32_t BSP_EEPROM_WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
{
uint16_t numofpage = 0, numofsingle = 0, count = 0;
uint16_t addr = 0;
uint8_t dataindex = 0;
uint32_t status = EEPROM_OK;
addr = WriteAddr % EEPROM_PAGESIZE;
count = EEPROM_PAGESIZE - addr;
numofpage = NumByteToWrite / EEPROM_PAGESIZE;
numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
if(addr == 0)
{
if(numofpage == 0)
{
dataindex = numofsingle;
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
}if (numofpage == 0) { ... }
else
{
while(numofpage--)
{
dataindex = EEPROM_PAGESIZE;
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
WriteAddr += EEPROM_PAGESIZE;
pBuffer += EEPROM_PAGESIZE;
}while (numofpage--) { ... }
if(numofsingle!=0)
{
dataindex = numofsingle;
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
}if (numofsingle!=0) { ... }
}else { ... }
}if (addr == 0) { ... }
else
{
if(numofpage== 0)
{
/* ... */
if(NumByteToWrite > count)
{
dataindex = count;
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
dataindex = (NumByteToWrite - count);
status = BSP_EEPROM_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
}if (NumByteToWrite > count) { ... }
else
{
dataindex = numofsingle;
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
}else { ... }
}if (numofpage== 0) { ... }
else
{
NumByteToWrite -= count;
numofpage = NumByteToWrite / EEPROM_PAGESIZE;
numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
if(count != 0)
{
dataindex = count;
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
WriteAddr += count;
pBuffer += count;
}if (count != 0) { ... }
while(numofpage--)
{
dataindex = EEPROM_PAGESIZE;
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
WriteAddr += EEPROM_PAGESIZE;
pBuffer += EEPROM_PAGESIZE;
}while (numofpage--) { ... }
if(numofsingle != 0)
{
dataindex = numofsingle;
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
if(status != EEPROM_OK)
{
return status;
}if (status != EEPROM_OK) { ... }
}if (numofsingle != 0) { ... }
}else { ... }
}else { ... }
return EEPROM_OK;
}{ ... }
/* ... */
uint32_t BSP_EEPROM_WaitEepromStandbyState(void)
{
if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
{
BSP_EEPROM_TIMEOUT_UserCallback();
return EEPROM_TIMEOUT;
}if (EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK) { ... }
return EEPROM_OK;
}{ ... }
/* ... */
__weak void BSP_EEPROM_TIMEOUT_UserCallback(void)
{
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */