BSP
Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
TestStatus
#define EEPROM_FEATURES_NUM
#define BUFFER_SIZE1
#define EEPROM_WRITE_ADDRESS1
#define EEPROM_READ_ADDRESS1
#define countof
Private variables
EEPROMFeature
EEPROMConnected
Tx1Buffer
Rx1Buffer
Tx2Buffer
Private function prototypes
EEPROM_demo()
EEPROM_SetHint()
EEPROM_Show_Feature(uint8_t)
BSP_EEPROM_TIMEOUT_UserCallback()
Buffercmp(uint8_t *, uint8_t *, uint16_t)
Files
loading...
CodeScopeSTM32 Libraries and SamplesBSPSrc/eeprom.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
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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file BSP/Src/eeprom.c * @author MCD Application Team * @brief This example code shows how to manage an I2C M24LR64 * EEPROM memory * =================================================================== * Notes: * - This driver is intended for STM32F4xx families devices only. * - The I2C EEPROM memory (M24LR64) is available on separate daughter * board ANT7-M24LR-A, which is not provided with the STM32F469I * DISCOVERY board. * To use this driver you have to connect the ANT7-M24LR-A to CN3 * connector of STM32F469I DISCOVERY board. * Switch EE_M24LR64 needs to be enabled in your project. * =================================================================== ****************************************************************************** * @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" /** @addtogroup STM32F4xx_HAL_Examples * @{ *//* ... */ /** @addtogroup BSP * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; /* Private define ------------------------------------------------------------*/ #define EEPROM_FEATURES_NUM 2 #define BUFFER_SIZE1 (countof(Tx1Buffer)-1 + 10) #define EEPROM_WRITE_ADDRESS1 0x49 #define EEPROM_READ_ADDRESS1 0x49 /* Private macro -------------------------------------------------------------*/ #define countof(a) (sizeof(a) / sizeof(*(a))) 5 defines/* Private variables ---------------------------------------------------------*/ static uint8_t EEPROMFeature = 0; uint8_t EEPROMConnected = 1; uint8_t Tx1Buffer[] = "STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex. - STM32469I-DISCOVERY EEPROM Ex."; uint8_t Rx1Buffer[BUFFER_SIZE1] = {0}; uint8_t Tx2Buffer[BUFFER_SIZE1] = {0};Private variables /* Private function prototypes -----------------------------------------------*/ static void EEPROM_SetHint(void); static void EEPROM_Show_Feature(uint8_t Feature); static TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); extern uint8_t NbLoop;Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief EEPROM Demo * @param None * @retval None *//* ... */ void EEPROM_demo (void) { EEPROM_SetHint(); EEPROMFeature = 0; EEPROM_Show_Feature (EEPROMFeature); while (1) { if(CheckForUserInput() > 0) { if(++EEPROMFeature < EEPROM_FEATURES_NUM) { EEPROM_Show_Feature (EEPROMFeature); }if (++EEPROMFeature < EEPROM_FEATURES_NUM) { ... } else { return; }else { ... } }if (CheckForUserInput() > 0) { ... } HAL_Delay(100); }while (1) { ... } }{ ... } /** * @brief Display EEPROM Demo Hint * @param None * @retval None *//* ... */ static void EEPROM_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Demo description */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 80); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"EEPROM", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"This example shows the different", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"EEPROM Features, use BUTTON", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"to start EEPROM data transfer", CENTER_MODE); /* Set the LCD Text Color */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DrawRect(10, 90, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize()- 100); BSP_LCD_DrawRect(11, 91, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize()- 102); }{ ... } /** * @brief Show EEPROM Features * @param Feature : feature index * @retval None *//* ... */ static void EEPROM_Show_Feature(uint8_t Feature) { __IO TestStatus TransferStatus1 = FAILED; __IO uint16_t NumDataRead = 0; BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillRect(12, 92, BSP_LCD_GetXSize() - 24, BSP_LCD_GetYSize()- 104); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); /* Initialize the I2C EEPROM driver ----------------------------------------*/ if(BSP_EEPROM_Init() != EEPROM_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Initialization problem", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 130, (uint8_t *)"Check if HW connected or", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 145, (uint8_t *)"HW version not supported", CENTER_MODE); return; }if (BSP_EEPROM_Init() != EEPROM_OK) { ... } EEPROMConnected = 1; /* Wait for EEPROM standby state */ BSP_EEPROM_WaitEepromStandbyState(); switch (Feature) { case 0: /* Read old parameter in EEPROM */ if(EEPROMConnected == 1) { /* Set the Number of data to be read */ NumDataRead = BUFFER_SIZE1; /* Read from I2C EEPROM from EEPROM_READ_ADDRESS1 */ if(BSP_EEPROM_ReadBuffer(Rx1Buffer, EEPROM_READ_ADDRESS1, (uint16_t *)(&NumDataRead)) != EEPROM_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Init issue at read old data", CENTER_MODE); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DisplayStringAt(0, 145, (uint8_t *)"Press again USER key", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 160, (uint8_t *)"To write new data", CENTER_MODE); return; }if (BSP_EEPROM_ReadBuffer(Rx1Buffer, EEPROM_READ_ADDRESS1, (uint16_t *)(&NumDataRead)) != EEPROM_OK) { ... } BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"PASSED String read", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 130, (uint8_t *)"in EEPROM:", CENTER_MODE); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAt(0, 160, Rx1Buffer, CENTER_MODE); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DisplayStringAt(0, 190, (uint8_t *)"Press USER key", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 205, (uint8_t *)"To write new data", CENTER_MODE); }if (EEPROMConnected == 1) { ... } else { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Problem to communicate", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 130, (uint8_t *)"with EEPROM", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 145, (uint8_t *)"Press again USER key", CENTER_MODE); }else { ... } break; case 0: case 1: /* Write new parameter in EEPROM */ if(EEPROMConnected == 1) { BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Writing...", CENTER_MODE); snprintf((char*)Tx2Buffer, BUFFER_SIZE1, "%s Test %d", Tx1Buffer, NbLoop); /* First write in the memory followed by a read of the written data --------*/ /* Write on I2C EEPROM to EEPROM_WRITE_ADDRESS1 */ if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Init issue at write 1", CENTER_MODE); return; }if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { ... } if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Init issue at write 2", CENTER_MODE); return; }if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { ... } if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Init issue at write 3", CENTER_MODE); return; }if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { ... } if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Init issue at write 4", CENTER_MODE); return; }if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { ... } if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Init issue at write 5", CENTER_MODE); return; }if (BSP_EEPROM_WriteBuffer(Tx2Buffer, EEPROM_WRITE_ADDRESS1, BUFFER_SIZE1) != EEPROM_OK) { ... } /* Wait for EEPROM standby state */ BSP_EEPROM_WaitEepromStandbyState(); /* Set the Number of data to be read */ NumDataRead = BUFFER_SIZE1; /* Read from I2C EEPROM from EEPROM_READ_ADDRESS1 */ if (BSP_EEPROM_ReadBuffer(Rx1Buffer, EEPROM_READ_ADDRESS1, (uint16_t *)(&NumDataRead)) != EEPROM_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Init issue at read", CENTER_MODE); return; }if (BSP_EEPROM_ReadBuffer(Rx1Buffer, EEPROM_READ_ADDRESS1, (uint16_t *)(&NumDataRead)) != EEPROM_OK) { ... } /* Check if the data written to the memory is read correctly */ TransferStatus1 = Buffercmp(Tx2Buffer, Rx1Buffer, BUFFER_SIZE1); if (TransferStatus1 != FAILED) { BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"PASSED String write", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 130, (uint8_t *)"in EEPROM:", CENTER_MODE); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAt(0, 160, Tx2Buffer, CENTER_MODE); }if (TransferStatus1 != FAILED) { ... } else { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"FAILED to write!", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 130, (uint8_t *)"Press USER key to end test", CENTER_MODE); }else { ... } }if (EEPROMConnected == 1) { ... } else { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, 115, (uint8_t *)"Problem to communicate", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 130, (uint8_t *)"again with EEPROM", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 130, (uint8_t *)"Press USER key to end test", CENTER_MODE); }else { ... } break;case 1: }switch (Feature) { ... } }{ ... } /** * @brief Basic management of the timeout situation. * @param None. * @retval 0. *//* ... */ void BSP_EEPROM_TIMEOUT_UserCallback(void) { EEPROMConnected = 0; }{ ... } /** * @brief Compares two buffers. * @param pBuffer1, pBuffer2: buffers to be compared. * @param BufferLength: buffer's length * @retval PASSED: pBuffer1 identical to pBuffer2 * FAILED: pBuffer1 differs from pBuffer2 *//* ... */ static TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) { while(BufferLength--) { if(*pBuffer1 != *pBuffer2) { return FAILED; }if (*pBuffer1 != *pBuffer2) { ... } pBuffer1++; pBuffer2++; }while (BufferLength--) { ... } return PASSED; }{ ... } /** * @} *//* ... */