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
89
90
91
94
95
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
123
124
125
126
130
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
159
160
161
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
207
208
209
214
215
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
259
260
261
262
263
264
265
266
267
268
272
273
274
275
276
277
287
288
289
290
291
292
293
294
295
297
298
299
300
301
302
303
307
308
309
310
311
312
316
317
327
328
329
330
331
332
333
334
335
336
337
338
339
340
344
345
346
347
348
349
350
351
352
353
357
358
359
360
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
400
401
404
407
408
411
412
415
416
419
420
/* ... */
#include "stm32412g_discovery_eeprom.h"
/* ... */
/* ... */
/* ... */
/* ... */
__IO uint16_t EEPROMAddress = 0;
__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)
{
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */