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
68
78
96
97
98
101
102
103
104
107
108
109
110
113
114
115
116
119
120
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
160
164
165
166
170
171
172
173
174
175
179
183
184
185
192
203
204
207
211
212
219
220
221
222
223
224
225
226
227
228
229
233
234
235
236
237
238
239
240
241
242
243
250
251
252
253
254
255
256
260
264
265
266
271
272
273
274
275
276
277
281
285
286
287
291
292
293
294
295
296
297
301
305
306
307
312
323
324
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
377
378
379
380
381
382
383
384
385
386
387
388
393
394
395
396
397
398
402
403
404
405
406
410
411
412
415
416
419
420
/* ... */
/* ... */
#include "stm32469i_eval_nor.h"
/* ... */
/* ... */
/* ... */
Includes
/* ... */
/* ... */
Private typedef
/* ... */
/* ... */
Private define
/* ... */
/* ... */
Private macro
/* ... */
NOR_HandleTypeDef NorHandle;
static FMC_NORSRAM_TimingTypeDef Timing;
/* ... */
Private variables
/* ... */
/* ... */
/* ... */
uint8_t BSP_NOR_Init(void)
{
NorHandle.Instance = FMC_NORSRAM_DEVICE;
NorHandle.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
Timing.AddressSetupTime = 8;
Timing.AddressHoldTime = 3;
Timing.DataSetupTime = 9;
Timing.BusTurnAroundDuration = 0;
Timing.CLKDivision = 2;
Timing.DataLatency = 2;
Timing.AccessMode = FMC_ACCESS_MODE_A;
NorHandle.Init.NSBank = FMC_NORSRAM_BANK1;
NorHandle.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
NorHandle.Init.MemoryType = FMC_MEMORY_TYPE_NOR;
NorHandle.Init.MemoryDataWidth = NOR_MEMORY_WIDTH;
NorHandle.Init.BurstAccessMode = NOR_BURSTACCESS;
NorHandle.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
NorHandle.Init.WrapMode = FMC_WRAP_MODE_DISABLE;
NorHandle.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
NorHandle.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
NorHandle.Init.WaitSignal = FMC_WAIT_SIGNAL_ENABLE;
NorHandle.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
NorHandle.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_ENABLE;
NorHandle.Init.WriteBurst = NOR_WRITEBURST;
NorHandle.Init.ContinuousClock = CONTINUOUSCLOCK_FEATURE;
BSP_NOR_MspInit(&NorHandle, NULL);
if(HAL_NOR_Init(&NorHandle, &Timing, &Timing) != HAL_OK)
{
return NOR_STATUS_ERROR;
}if (HAL_NOR_Init(&NorHandle, &Timing, &Timing) != HAL_OK) { ... }
else
{
return NOR_STATUS_OK;
}else { ... }
}{ ... }
/* ... */
uint8_t BSP_NOR_DeInit(void)
{
BSP_NOR_MspDeInit(&NorHandle, NULL);
if(HAL_NOR_DeInit(&NorHandle) != HAL_OK)
{
return NOR_STATUS_ERROR;
}if (HAL_NOR_DeInit(&NorHandle) != HAL_OK) { ... }
else
{
return NOR_STATUS_OK;
}else { ... }
}{ ... }
/* ... */
uint8_t BSP_NOR_ReadData(uint32_t uwStartAddress, uint16_t* pData, uint32_t uwDataSize)
{
if(HAL_NOR_ReadBuffer(&NorHandle, NOR_DEVICE_ADDR + uwStartAddress, pData, uwDataSize) != HAL_OK)
{
return NOR_STATUS_ERROR;
}if (HAL_NOR_ReadBuffer(&NorHandle, NOR_DEVICE_ADDR + uwStartAddress, pData, uwDataSize) != HAL_OK) { ... }
else
{
return NOR_STATUS_OK;
}else { ... }
}{ ... }
/* ... */
void BSP_NOR_ReturnToReadMode(void)
{
HAL_NOR_ReturnToReadMode(&NorHandle);
}{ ... }
/* ... */
uint8_t BSP_NOR_WriteData(uint32_t uwStartAddress, uint16_t* pData, uint32_t uwDataSize)
{
uint32_t index = uwDataSize;
while(index > 0)
{
HAL_NOR_Program(&NorHandle, (uint32_t *)(NOR_DEVICE_ADDR + uwStartAddress), pData);
if(HAL_NOR_GetStatus(&NorHandle, NOR_DEVICE_ADDR, PROGRAM_TIMEOUT) != HAL_NOR_STATUS_SUCCESS)
{
return NOR_STATUS_ERROR;
}if (HAL_NOR_GetStatus(&NorHandle, NOR_DEVICE_ADDR, PROGRAM_TIMEOUT) != HAL_NOR_STATUS_SUCCESS) { ... }
index--;
uwStartAddress += 2;
pData++;
}while (index > 0) { ... }
return NOR_STATUS_OK;
}{ ... }
/* ... */
uint8_t BSP_NOR_ProgramData(uint32_t uwStartAddress, uint16_t* pData, uint32_t uwDataSize)
{
HAL_NOR_ProgramBuffer(&NorHandle, uwStartAddress, pData, uwDataSize);
if(HAL_NOR_GetStatus(&NorHandle, NOR_DEVICE_ADDR, PROGRAM_TIMEOUT) != HAL_NOR_STATUS_SUCCESS)
{
return NOR_STATUS_ERROR;
}if (HAL_NOR_GetStatus(&NorHandle, NOR_DEVICE_ADDR, PROGRAM_TIMEOUT) != HAL_NOR_STATUS_SUCCESS) { ... }
else
{
return NOR_STATUS_OK;
}else { ... }
}{ ... }
/* ... */
uint8_t BSP_NOR_Erase_Block(uint32_t BlockAddress)
{
HAL_NOR_Erase_Block(&NorHandle, BlockAddress, NOR_DEVICE_ADDR);
if(HAL_NOR_GetStatus(&NorHandle, NOR_DEVICE_ADDR, BLOCKERASE_TIMEOUT) != HAL_NOR_STATUS_SUCCESS)
{
return NOR_STATUS_ERROR;
}if (HAL_NOR_GetStatus(&NorHandle, NOR_DEVICE_ADDR, BLOCKERASE_TIMEOUT) != HAL_NOR_STATUS_SUCCESS) { ... }
else
{
return NOR_STATUS_OK;
}else { ... }
}{ ... }
/* ... */
uint8_t BSP_NOR_Erase_Chip(void)
{
HAL_NOR_Erase_Chip(&NorHandle, NOR_DEVICE_ADDR);
if(HAL_NOR_GetStatus(&NorHandle, NOR_DEVICE_ADDR, CHIPERASE_TIMEOUT) != HAL_NOR_STATUS_SUCCESS)
{
return NOR_STATUS_ERROR;
}if (HAL_NOR_GetStatus(&NorHandle, NOR_DEVICE_ADDR, CHIPERASE_TIMEOUT) != HAL_NOR_STATUS_SUCCESS) { ... }
else
{
return NOR_STATUS_OK;
}else { ... }
}{ ... }
/* ... */
uint8_t BSP_NOR_Read_ID(NOR_IDTypeDef *pNOR_ID)
{
if(HAL_NOR_Read_ID(&NorHandle, pNOR_ID) != HAL_OK)
{
return NOR_STATUS_ERROR;
}if (HAL_NOR_Read_ID(&NorHandle, pNOR_ID) != HAL_OK) { ... }
else
{
return NOR_STATUS_OK;
}else { ... }
}{ ... }
/* ... */
__weak void BSP_NOR_MspInit(NOR_HandleTypeDef *hnor, void *Params)
{
GPIO_InitTypeDef gpio_init_structure;
__HAL_RCC_FMC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
gpio_init_structure.Alternate = GPIO_AF12_FMC;
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |\
GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |\
GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
gpio_init_structure.Pin = GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |\
GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |\
GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOE, &gpio_init_structure);
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOF, &gpio_init_structure);
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5;
HAL_GPIO_Init(GPIOG, &gpio_init_structure);
}{ ... }
/* ... */
__weak uint8_t BSP_NOR_MspDeInit(NOR_HandleTypeDef *hnor, void *Params)
{
HAL_GPIO_DeInit(GPIOD, (GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7));
return HAL_OK;
}{ ... }
/* ... */
void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
{
uint32_t timeout = Timeout;
while((HAL_GPIO_ReadPin(NOR_READY_BUSY_GPIO, NOR_READY_BUSY_PIN) != NOR_BUSY_STATE) && (timeout > 0))
{
timeout--;
}while ((HAL_GPIO_ReadPin(NOR_READY_BUSY_GPIO, NOR_READY_BUSY_PIN) != NOR_BUSY_STATE) && (timeout > 0)) { ... }
timeout = Timeout;
while((HAL_GPIO_ReadPin(NOR_READY_BUSY_GPIO, NOR_READY_BUSY_PIN) != NOR_READY_STATE) && (timeout > 0))
{
timeout--;
}while ((HAL_GPIO_ReadPin(NOR_READY_BUSY_GPIO, NOR_READY_BUSY_PIN) != NOR_READY_STATE) && (timeout > 0)) { ... }
}{ ... }
/* ... */
/* ... */
/* ... */