Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "stm32469i_eval_nor.h"
Private typedef
Private define
Private macro
Private variables
NorHandle
Timing
BSP_NOR_Init()
BSP_NOR_DeInit()
BSP_NOR_ReadData(uint32_t, uint16_t *, uint32_t)
BSP_NOR_ReturnToReadMode()
BSP_NOR_WriteData(uint32_t, uint16_t *, uint32_t)
BSP_NOR_ProgramData(uint32_t, uint16_t *, uint32_t)
BSP_NOR_Erase_Block(uint32_t)
BSP_NOR_Erase_Chip()
BSP_NOR_Read_ID(NOR_IDTypeDef *)
BSP_NOR_MspInit(NOR_HandleTypeDef *, void *)
BSP_NOR_MspDeInit(NOR_HandleTypeDef *, void *)
HAL_NOR_MspWait(NOR_HandleTypeDef *, uint32_t)
Files
loading...
CodeScopeSTM32 Libraries and SamplesSTM32469I_EVALstm32469i_eval_nor.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file stm32469i_eval_nor.c * @author MCD Application Team * @brief This file includes a standard driver for the M29W256GL70ZA6E NOR flash memory * device mounted on STM32469I-EVAL evaluation board. ****************************************************************************** * @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. * ****************************************************************************** *//* ... */ /* File Info : ----------------------------------------------------------------- User NOTES 1. How To use this driver: -------------------------- - This driver is used to drive the M29W128GL NOR flash external memory mounted on STM32469I-EVAL evaluation board. - This driver does not need a specific component driver for the NOR device to be included with. 2. Driver description: --------------------- + Initialization steps: o Initialize the NOR external memory using the BSP_NOR_Init() function. This function includes the MSP layer hardware resources initialization and the FMC controller configuration to interface with the external NOR memory. + NOR flash operations o NOR external memory can be accessed with read/write operations once it is initialized. Read/write operation can be performed with AHB access using the functions BSP_NOR_ReadData()/BSP_NOR_WriteData(). The BSP_NOR_WriteData() performs write operation of an amount of data by unit (halfword). You can also perform a program data operation of an amount of data using the function BSP_NOR_ProgramData(). o The function BSP_NOR_Read_ID() returns the chip IDs stored in the structure "NOR_IDTypeDef". (see the NOR IDs in the memory data sheet) o Perform erase block operation using the function BSP_NOR_Erase_Block() and by specifying the block address. You can perform an erase operation of the whole chip by calling the function BSP_NOR_Erase_Chip(). o After other operations, the function BSP_NOR_ReturnToReadMode() allows the NOR flash to return to read mode to perform read operations on it. ------------------------------------------------------------------------------*//* ... */ /* Includes ------------------------------------------------------------------*/ #include "stm32469i_eval_nor.h" /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup STM32469I_EVAL * @{ *//* ... */ /** @defgroup STM32469I-EVAL_NOR STM32469I EVAL NOR * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /** @defgroup STM32469I-EVAL_NOR_Private_Types_Definitions STM32469I EVAL NOR Private Types Definitions * @{ *//* ... */ /** * @} *//* ... */ Private typedef /* Private define ------------------------------------------------------------*/ /** @defgroup STM32469I-EVAL_NOR_Private_Defines STM32469I EVAL NOR Private Defines * @{ *//* ... */ /** * @} *//* ... */ Private define/* Private macro -------------------------------------------------------------*/ /** @defgroup STM32469I-EVAL_NOR_Private_Macros STM32469I EVAL NOR Private Macros * @{ *//* ... */ /** * @} *//* ... */ Private macro /* Private variables ---------------------------------------------------------*/ /** @defgroup STM32469I-EVAL_NOR_Private_Variables STM32469I EVAL NOR Private Variables * @{ *//* ... */ NOR_HandleTypeDef NorHandle; static FMC_NORSRAM_TimingTypeDef Timing; /** * @} *//* ... */ Private variables /* Private function prototypes -----------------------------------------------*/ /** @defgroup STM32469I-EVAL_NOR_Private_Function_Prototypes STM32469I EVAL NOR Private Function Prototypes * @{ *//* ... */ /** * @} *//* ... */ /** * @brief Initializes the NOR device. * @retval NOR memory status *//* ... */ uint8_t BSP_NOR_Init(void) { NorHandle.Instance = FMC_NORSRAM_DEVICE; NorHandle.Extended = FMC_NORSRAM_EXTENDED_DEVICE; /* NOR device configuration */ 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; /* NOR controller initialization */ 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 { ... } }{ ... } /** * @brief DeInitializes the NOR device. * @retval NOR memory status *//* ... */ uint8_t BSP_NOR_DeInit(void) { /* NOR controller initialization */ 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 { ... } }{ ... } /** * @brief Reads an amount of data from the NOR device. * @param uwStartAddress: Read start address * @param pData: Pointer to data to be read * @param uwDataSize: Size of data to read * @retval NOR memory status *//* ... */ 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 { ... } }{ ... } /** * @brief Returns the NOR memory to read mode. *//* ... */ void BSP_NOR_ReturnToReadMode(void) { HAL_NOR_ReturnToReadMode(&NorHandle); }{ ... } /** * @brief Writes an amount of data to the NOR device. * @param uwStartAddress: Write start address * @param pData: Pointer to data to be written * @param uwDataSize: Size of data to write * @retval NOR memory status *//* ... */ uint8_t BSP_NOR_WriteData(uint32_t uwStartAddress, uint16_t* pData, uint32_t uwDataSize) { uint32_t index = uwDataSize; while(index > 0) { /* Write data to NOR */ HAL_NOR_Program(&NorHandle, (uint32_t *)(NOR_DEVICE_ADDR + uwStartAddress), pData); /* Read NOR device status */ 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) { ... } /* Update the counters */ index--; uwStartAddress += 2; pData++; }while (index > 0) { ... } return NOR_STATUS_OK; }{ ... } /** * @brief Programs an amount of data to the NOR device. * @param uwStartAddress: Write start address * @param pData: Pointer to data to be written * @param uwDataSize: Size of data to write * @retval NOR memory status *//* ... */ uint8_t BSP_NOR_ProgramData(uint32_t uwStartAddress, uint16_t* pData, uint32_t uwDataSize) { /* Send NOR program buffer operation */ HAL_NOR_ProgramBuffer(&NorHandle, uwStartAddress, pData, uwDataSize); /* Return the NOR memory status */ 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 { ... } }{ ... } /** * @brief Erases the specified block of the NOR device. * @param BlockAddress: Block address to erase * @retval NOR memory status *//* ... */ uint8_t BSP_NOR_Erase_Block(uint32_t BlockAddress) { /* Send NOR erase block operation */ HAL_NOR_Erase_Block(&NorHandle, BlockAddress, NOR_DEVICE_ADDR); /* Return the NOR memory status */ 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 { ... } }{ ... } /** * @brief Erases the entire NOR chip. * @retval NOR memory status *//* ... */ uint8_t BSP_NOR_Erase_Chip(void) { /* Send NOR Erase chip operation */ HAL_NOR_Erase_Chip(&NorHandle, NOR_DEVICE_ADDR); /* Return the NOR memory status */ 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 { ... } }{ ... } /** * @brief Reads NOR flash IDs. * @param pNOR_ID : Pointer to NOR ID structure * @retval NOR memory status *//* ... */ 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 { ... } }{ ... } /** * @brief Initializes the NOR MSP. * @param hnor: pointer to nor structure * @param Params : pointer on additional configuration parameters, can be NULL. *//* ... */ __weak void BSP_NOR_MspInit(NOR_HandleTypeDef *hnor, void *Params) { GPIO_InitTypeDef gpio_init_structure; /* Enable FMC clock */ __HAL_RCC_FMC_CLK_ENABLE(); /* Enable GPIOs clock */ __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); /* Common GPIO configuration */ 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; /* GPIOD configuration */ 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); /* GPIOE configuration */ 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); /* GPIOF configuration */ 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); /* GPIOG configuration */ 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); }{ ... } /** * @brief DeInitializes the NOR MSP. * @param hnor pointer to NOR structure * @param Params : pointer on additional configuration parameters, can be NULL. * @retval status *//* ... */ __weak uint8_t BSP_NOR_MspDeInit(NOR_HandleTypeDef *hnor, void *Params) { /* FMC won't be disabled because common to other functionalities */ /* Disable only NOR specific GPIOs */ HAL_GPIO_DeInit(GPIOD, (GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7)); return HAL_OK; }{ ... } /** * @brief NOR BSP Wait for Ready/Busy signal. * @param hnor: Pointer to NOR handle * @param Timeout: Timeout duration *//* ... */ void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout) { uint32_t timeout = Timeout; /* Polling on Ready/Busy signal */ 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; /* Polling on Ready/Busy signal */ 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)) { ... } }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */