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
114
115
116
117
121
122
123
124
125
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
192
193
194
205
206
207
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
245
246
247
248
249
250
251
252
259
260
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
283
287
288
289
290
291
292
296
300
304
308
309
316
317
318
319
324
328
329
330
331
332
333
334
335
336
337
343
344
345
346
353
354
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
376
385
386
392
401
402
409
410
411
412
413
414
415
418
419
420
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
445
446
447
448
449
450
451
452
453
457
461
462
463
464
465
466
467
468
469
470
474
478
482
486
487
488
489
490
491
492
493
494
495
496
497
498
499
506
507
511
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
539
540
541
542
543
549
550
551
552
553
554
555
556
557
561
565
566
567
568
569
570
571
572
573
574
578
582
586
590
591
595
599
604
605
606
607
608
609
610
611
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
639
643
644
645
646
647
648
649
650
651
652
656
660
664
668
669
670
671
672
673
674
675
676
677
678
679
680
681
688
689
693
698
699
704
705
706
707
708
709
710
711
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
737
738
739
740
741
742
743
744
745
746
750
754
758
762
763
764
765
766
767
768
769
770
771
772
773
774
775
781
782
786
791
792
797
798
799
800
801
802
803
804
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
837
841
842
843
844
845
846
847
848
849
850
854
858
862
866
867
868
869
870
871
872
873
874
875
876
877
878
879
886
887
891
896
897
908
909
910
911
912
913
914
915
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
946
947
948
949
950
951
952
953
954
955
959
963
967
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
992
993
994
995
996
1002
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1023
1027
1028
1029
1030
1031
1032
1033
1034
1035
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1075
1079
1083
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1125
1126
1127
1128
1129
1130
1131
1132
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1172
1176
1180
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1216
1217
1218
1219
1220
1221
1222
1223
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1249
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1266
1270
1274
1278
1279
1280
1285
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1331
1332
1333
1349
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1390
1395
1396
1397
1398
1399
1400
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1449
1450
1451
1452
1453
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1483
1484
1485
1486
1487
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1512
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1553
1554
1555
1556
1557
1558
1559
1563
1564
1568
1569
1570
1571
1572
1573
1577
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1598
1599
1600
1601
1602
1608
1612
1613
1618
1619
1620
1621
1622
1623
1626
1627
1630
1631
1634
1635
1636
1637
1640
1641
/* ... */
#include "stm32f4xx_hal.h"
#if defined(FMC_Bank1) || defined(FSMC_Bank1)
/* ... */
#ifdef HAL_NOR_MODULE_ENABLED
/* ... */
/* ... */
#define NOR_CMD_ADDRESS_FIRST_BYTE (uint16_t)0x0AAA
#define NOR_CMD_ADDRESS_FIRST_CFI_BYTE (uint16_t)0x00AA
#define NOR_CMD_ADDRESS_SECOND_BYTE (uint16_t)0x0555
#define NOR_CMD_ADDRESS_THIRD_BYTE (uint16_t)0x0AAA
#define NOR_CMD_ADDRESS_FIRST (uint16_t)0x0555
#define NOR_CMD_ADDRESS_FIRST_CFI (uint16_t)0x0055
#define NOR_CMD_ADDRESS_SECOND (uint16_t)0x02AA
#define NOR_CMD_ADDRESS_THIRD (uint16_t)0x0555
#define NOR_CMD_ADDRESS_FOURTH (uint16_t)0x0555
#define NOR_CMD_ADDRESS_FIFTH (uint16_t)0x02AA
#define NOR_CMD_ADDRESS_SIXTH (uint16_t)0x0555
#define NOR_CMD_DATA_READ_RESET (uint16_t)0x00F0
#define NOR_CMD_DATA_FIRST (uint16_t)0x00AA
#define NOR_CMD_DATA_SECOND (uint16_t)0x0055
#define NOR_CMD_DATA_AUTO_SELECT (uint16_t)0x0090
#define NOR_CMD_DATA_PROGRAM (uint16_t)0x00A0
#define NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD (uint16_t)0x0080
#define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH (uint16_t)0x00AA
#define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH (uint16_t)0x0055
#define NOR_CMD_DATA_CHIP_ERASE (uint16_t)0x0010
#define NOR_CMD_DATA_CFI (uint16_t)0x0098
#define NOR_CMD_DATA_BUFFER_AND_PROG (uint8_t)0x25
#define NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM (uint8_t)0x29
#define NOR_CMD_DATA_BLOCK_ERASE (uint8_t)0x30
#define NOR_CMD_READ_ARRAY (uint16_t)0x00FF
#define NOR_CMD_WORD_PROGRAM (uint16_t)0x0040
#define NOR_CMD_BUFFERED_PROGRAM (uint16_t)0x00E8
#define NOR_CMD_CONFIRM (uint16_t)0x00D0
#define NOR_CMD_BLOCK_ERASE (uint16_t)0x0020
#define NOR_CMD_BLOCK_UNLOCK (uint16_t)0x0060
#define NOR_CMD_READ_STATUS_REG (uint16_t)0x0070
#define NOR_CMD_CLEAR_STATUS_REG (uint16_t)0x0050
#define NOR_MASK_STATUS_DQ4 (uint16_t)0x0010
#define NOR_MASK_STATUS_DQ5 (uint16_t)0x0020
#define NOR_MASK_STATUS_DQ6 (uint16_t)0x0040
#define NOR_MASK_STATUS_DQ7 (uint16_t)0x0080
#define NOR_ADDRESS_COMMAND_SET (uint16_t)0x0013
#define NOR_INTEL_SHARP_EXT_COMMAND_SET (uint16_t)0x0001
#define NOR_AMD_FUJITSU_COMMAND_SET (uint16_t)0x0002
#define NOR_INTEL_STANDARD_COMMAND_SET (uint16_t)0x0003
#define NOR_AMD_FUJITSU_EXT_COMMAND_SET (uint16_t)0x0004
#define NOR_WINDBOND_STANDARD_COMMAND_SET (uint16_t)0x0006
#define NOR_MITSUBISHI_STANDARD_COMMAND_SET (uint16_t)0x0100
#define NOR_MITSUBISHI_EXT_COMMAND_SET (uint16_t)0x0101
#define NOR_PAGE_WRITE_COMMAND_SET (uint16_t)0x0102
#define NOR_INTEL_PERFORMANCE_COMMAND_SET (uint16_t)0x0200
#define NOR_INTEL_DATA_COMMAND_SET (uint16_t)0x0210
47 defines
/* ... */
Private define
/* ... */
static uint32_t uwNORMemoryDataWidth = NOR_MEMORY_8B;
/* ... */
Private variables
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing,
FMC_NORSRAM_TimingTypeDef *ExtTiming)
{
uint32_t deviceaddress;
HAL_StatusTypeDef status = HAL_OK;
if (hnor == NULL)
{
return HAL_ERROR;
}if (hnor == NULL) { ... }
if (hnor->State == HAL_NOR_STATE_RESET)
{
hnor->Lock = HAL_UNLOCKED;
#if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
if (hnor->MspInitCallback == NULL)
{
hnor->MspInitCallback = HAL_NOR_MspInit;
}if (hnor->MspInitCallback == NULL) { ... }
hnor->MspInitCallback(hnor);/* ... */
#else
HAL_NOR_MspInit(hnor);/* ... */
#endif
}if (hnor->State == HAL_NOR_STATE_RESET) { ... }
(void)FMC_NORSRAM_Init(hnor->Instance, &(hnor->Init));
(void)FMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank);
(void)FMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming,
hnor->Init.NSBank, hnor->Init.ExtendedMode);
__FMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank);
if (hnor->Init.MemoryDataWidth == FMC_NORSRAM_MEM_BUS_WIDTH_8)
{
uwNORMemoryDataWidth = NOR_MEMORY_8B;
}if (hnor->Init.MemoryDataWidth == FMC_NORSRAM_MEM_BUS_WIDTH_8) { ... }
else
{
uwNORMemoryDataWidth = NOR_MEMORY_16B;
}else { ... }
hnor->State = HAL_NOR_STATE_READY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (hnor->Init.WriteOperation == FMC_WRITE_OPERATION_DISABLE)
{
(void)FMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank);
hnor->State = HAL_NOR_STATE_PROTECTED;
}if (hnor->Init.WriteOperation == FMC_WRITE_OPERATION_DISABLE) { ... }
else
{
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI_BYTE),
NOR_CMD_DATA_CFI);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
}else { ... }
hnor->CommandSet = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_ADDRESS_COMMAND_SET);
status = HAL_NOR_ReturnToReadMode(hnor);
}else { ... }
return status;
}HAL_NOR_Init (NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor)
{
#if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
if (hnor->MspDeInitCallback == NULL)
{
hnor->MspDeInitCallback = HAL_NOR_MspDeInit;
}if (hnor->MspDeInitCallback == NULL) { ... }
hnor->MspDeInitCallback(hnor);/* ... */
#else
HAL_NOR_MspDeInit(hnor);/* ... */
#endif
(void)FMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank);
hnor->State = HAL_NOR_STATE_RESET;
__HAL_UNLOCK(hnor);
return HAL_OK;
}HAL_NOR_DeInit (NOR_HandleTypeDef *hnor) { ... }
/* ... */
__weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor)
{
UNUSED(hnor);
/* ... */
}HAL_NOR_MspInit (NOR_HandleTypeDef *hnor) { ... }
/* ... */
__weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor)
{
UNUSED(hnor);
/* ... */
}HAL_NOR_MspDeInit (NOR_HandleTypeDef *hnor) { ... }
/* ... */
__weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
{
UNUSED(hnor);
UNUSED(Timeout);
/* ... */
}HAL_NOR_MspWait (NOR_HandleTypeDef *hnor, uint32_t Timeout) { ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID)
{
uint32_t deviceaddress;
HAL_NOR_StateTypeDef state;
HAL_StatusTypeDef status = HAL_OK;
state = hnor->State;
if (state == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (state == HAL_NOR_STATE_BUSY) { ... }
else if (state == HAL_NOR_STATE_PROTECTED)
{
return HAL_ERROR;
}else if (state == HAL_NOR_STATE_PROTECTED) { ... }
else if (state == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
NOR_CMD_DATA_AUTO_SELECT);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
NOR_CMD_DATA_AUTO_SELECT);
}else { ... }
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
NOR_WRITE(deviceaddress, NOR_CMD_DATA_AUTO_SELECT);
}else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) { ... }
else
{
status = HAL_ERROR;
}else { ... }
if (status != HAL_ERROR)
{
pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, MC_ADDRESS);
pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
DEVICE_CODE1_ADDR);
pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
DEVICE_CODE2_ADDR);
pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
DEVICE_CODE3_ADDR);
}if (status != HAL_ERROR) { ... }
hnor->State = state;
__HAL_UNLOCK(hnor);
}else if (state == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_Read_ID (NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor)
{
uint32_t deviceaddress;
HAL_NOR_StateTypeDef state;
HAL_StatusTypeDef status = HAL_OK;
state = hnor->State;
if (state == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (state == HAL_NOR_STATE_BUSY) { ... }
else if (state == HAL_NOR_STATE_PROTECTED)
{
return HAL_ERROR;
}else if (state == HAL_NOR_STATE_PROTECTED) { ... }
else if (state == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
NOR_WRITE(deviceaddress, NOR_CMD_DATA_READ_RESET);
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
NOR_WRITE(deviceaddress, NOR_CMD_READ_ARRAY);
}else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) { ... }
else
{
status = HAL_ERROR;
}else { ... }
hnor->State = state;
__HAL_UNLOCK(hnor);
}else if (state == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_ReturnToReadMode (NOR_HandleTypeDef *hnor) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
{
uint32_t deviceaddress;
HAL_NOR_StateTypeDef state;
HAL_StatusTypeDef status = HAL_OK;
state = hnor->State;
if (state == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (state == HAL_NOR_STATE_BUSY) { ... }
else if (state == HAL_NOR_STATE_PROTECTED)
{
return HAL_ERROR;
}else if (state == HAL_NOR_STATE_PROTECTED) { ... }
else if (state == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
NOR_CMD_DATA_READ_RESET);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
NOR_CMD_DATA_READ_RESET);
}else { ... }
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
NOR_WRITE(pAddress, NOR_CMD_READ_ARRAY);
}else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) { ... }
else
{
status = HAL_ERROR;
}else { ... }
if (status != HAL_ERROR)
{
*pData = (uint16_t)(*(__IO uint32_t *)pAddress);
}if (status != HAL_ERROR) { ... }
hnor->State = state;
__HAL_UNLOCK(hnor);
}else if (state == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_Read (NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
{
uint32_t deviceaddress;
HAL_StatusTypeDef status = HAL_OK;
if (hnor->State == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (hnor->State == HAL_NOR_STATE_BUSY) { ... }
else if (hnor->State == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
NOR_CMD_DATA_PROGRAM);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM);
}else { ... }
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
NOR_WRITE(pAddress, NOR_CMD_WORD_PROGRAM);
}else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) { ... }
else
{
status = HAL_ERROR;
}else { ... }
if (status != HAL_ERROR)
{
NOR_WRITE(pAddress, *pData);
}if (status != HAL_ERROR) { ... }
hnor->State = HAL_NOR_STATE_READY;
__HAL_UNLOCK(hnor);
}else if (hnor->State == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_Program (NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData,
uint32_t uwBufferSize)
{
uint32_t deviceaddress;
uint32_t size = uwBufferSize;
uint32_t address = uwAddress;
uint16_t *data = pData;
HAL_NOR_StateTypeDef state;
HAL_StatusTypeDef status = HAL_OK;
state = hnor->State;
if (state == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (state == HAL_NOR_STATE_BUSY) { ... }
else if (state == HAL_NOR_STATE_PROTECTED)
{
return HAL_ERROR;
}else if (state == HAL_NOR_STATE_PROTECTED) { ... }
else if (state == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
NOR_CMD_DATA_READ_RESET);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
NOR_CMD_DATA_READ_RESET);
}else { ... }
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
NOR_WRITE(deviceaddress, NOR_CMD_READ_ARRAY);
}else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) { ... }
else
{
status = HAL_ERROR;
}else { ... }
if (status != HAL_ERROR)
{
while (size > 0U)
{
*data = *(__IO uint16_t *)address;
data++;
address += 2U;
size--;
}while (size > 0U) { ... }
}if (status != HAL_ERROR) { ... }
hnor->State = state;
__HAL_UNLOCK(hnor);
}else if (state == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_ReadBuffer (NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData,
uint32_t uwBufferSize)
{
uint16_t *p_currentaddress;
const uint16_t *p_endaddress;
uint16_t *data = pData;
uint32_t deviceaddress;
HAL_StatusTypeDef status = HAL_OK;
if (hnor->State == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (hnor->State == HAL_NOR_STATE_BUSY) { ... }
else if (hnor->State == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
p_currentaddress = (uint16_t *)(deviceaddress + uwAddress);
p_endaddress = (uint16_t *)(deviceaddress + uwAddress + (2U * (uwBufferSize - 1U)));
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
NOR_CMD_DATA_SECOND);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
}else { ... }
NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG);
NOR_WRITE((deviceaddress + uwAddress), (uint16_t)(uwBufferSize - 1U));
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_BUFFERED_PROGRAM);
NOR_WRITE((deviceaddress + uwAddress), (uint16_t)(uwBufferSize - 1U));
}else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) { ... }
else
{
status = HAL_ERROR;
}else { ... }
if (status != HAL_ERROR)
{
while (p_currentaddress <= p_endaddress)
{
NOR_WRITE(p_currentaddress, *data);
data++;
p_currentaddress ++;
}while (p_currentaddress <= p_endaddress) { ... }
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM);
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else
{
NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_CONFIRM);
}else { ... }
}if (status != HAL_ERROR) { ... }
hnor->State = HAL_NOR_STATE_READY;
__HAL_UNLOCK(hnor);
}else if (hnor->State == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_ProgramBuffer (NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address)
{
uint32_t deviceaddress;
HAL_StatusTypeDef status = HAL_OK;
if (hnor->State == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (hnor->State == HAL_NOR_STATE_BUSY) { ... }
else if (hnor->State == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH),
NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH),
NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
}else { ... }
NOR_WRITE((uint32_t)(BlockAddress + Address), NOR_CMD_DATA_BLOCK_ERASE);
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
NOR_WRITE((BlockAddress + Address), NOR_CMD_BLOCK_UNLOCK);
NOR_WRITE((BlockAddress + Address), NOR_CMD_CONFIRM);
NOR_WRITE((BlockAddress + Address), NOR_CMD_BLOCK_ERASE);
NOR_WRITE((BlockAddress + Address), NOR_CMD_CONFIRM);
}else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) { ... }
else
{
status = HAL_ERROR;
}else { ... }
hnor->State = HAL_NOR_STATE_READY;
__HAL_UNLOCK(hnor);
}else if (hnor->State == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_Erase_Block (NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address)
{
uint32_t deviceaddress;
HAL_StatusTypeDef status = HAL_OK;
UNUSED(Address);
if (hnor->State == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (hnor->State == HAL_NOR_STATE_BUSY) { ... }
else if (hnor->State == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH),
NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH),
NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SIXTH),
NOR_CMD_DATA_CHIP_ERASE);
}else { ... }
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else
{
status = HAL_ERROR;
}else { ... }
hnor->State = HAL_NOR_STATE_READY;
__HAL_UNLOCK(hnor);
}else if (hnor->State == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_Erase_Chip (NOR_HandleTypeDef *hnor, uint32_t Address) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI)
{
uint32_t deviceaddress;
HAL_NOR_StateTypeDef state;
state = hnor->State;
if (state == HAL_NOR_STATE_BUSY)
{
return HAL_BUSY;
}if (state == HAL_NOR_STATE_BUSY) { ... }
else if (state == HAL_NOR_STATE_PROTECTED)
{
return HAL_ERROR;
}else if (state == HAL_NOR_STATE_PROTECTED) { ... }
else if (state == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
{
deviceaddress = NOR_MEMORY_ADRESS1;
}if (hnor->Init.NSBank == FMC_NORSRAM_BANK1) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
{
deviceaddress = NOR_MEMORY_ADRESS2;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2) { ... }
else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
{
deviceaddress = NOR_MEMORY_ADRESS3;
}else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3) { ... }
else
{
deviceaddress = NOR_MEMORY_ADRESS4;
}else { ... }
if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI_BYTE),
NOR_CMD_DATA_CFI);
}if (uwNORMemoryDataWidth == NOR_MEMORY_8B) { ... }
else
{
NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
}else { ... }
pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI1_ADDRESS);
pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI2_ADDRESS);
pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI3_ADDRESS);
pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI4_ADDRESS);
hnor->State = state;
__HAL_UNLOCK(hnor);
}else if (state == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return HAL_OK;
}HAL_NOR_Read_CFI (NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI) { ... }
#if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
/* ... */
HAL_StatusTypeDef HAL_NOR_RegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId,
pNOR_CallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
HAL_NOR_StateTypeDef state;
if (pCallback == NULL)
{
return HAL_ERROR;
}if (pCallback == NULL) { ... }
state = hnor->State;
if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED))
{
switch (CallbackId)
{
case HAL_NOR_MSP_INIT_CB_ID :
hnor->MspInitCallback = pCallback;
break;case HAL_NOR_MSP_INIT_CB_ID :
case HAL_NOR_MSP_DEINIT_CB_ID :
hnor->MspDeInitCallback = pCallback;
break;case HAL_NOR_MSP_DEINIT_CB_ID :
default :
status = HAL_ERROR;
break;default
}switch (CallbackId) { ... }
}if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED)) { ... }
else
{
status = HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_RegisterCallback (NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId, pNOR_CallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_UnRegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId)
{
HAL_StatusTypeDef status = HAL_OK;
HAL_NOR_StateTypeDef state;
state = hnor->State;
if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED))
{
switch (CallbackId)
{
case HAL_NOR_MSP_INIT_CB_ID :
hnor->MspInitCallback = HAL_NOR_MspInit;
break;case HAL_NOR_MSP_INIT_CB_ID :
case HAL_NOR_MSP_DEINIT_CB_ID :
hnor->MspDeInitCallback = HAL_NOR_MspDeInit;
break;case HAL_NOR_MSP_DEINIT_CB_ID :
default :
status = HAL_ERROR;
break;default
}switch (CallbackId) { ... }
}if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED)) { ... }
else
{
status = HAL_ERROR;
}else { ... }
return status;
}HAL_NOR_UnRegisterCallback (NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor)
{
if (hnor->State == HAL_NOR_STATE_PROTECTED)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
(void)FMC_NORSRAM_WriteOperation_Enable(hnor->Instance, hnor->Init.NSBank);
hnor->State = HAL_NOR_STATE_READY;
__HAL_UNLOCK(hnor);
}if (hnor->State == HAL_NOR_STATE_PROTECTED) { ... }
else
{
return HAL_ERROR;
}else { ... }
return HAL_OK;
}HAL_NOR_WriteOperation_Enable (NOR_HandleTypeDef *hnor) { ... }
/* ... */
HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor)
{
if (hnor->State == HAL_NOR_STATE_READY)
{
__HAL_LOCK(hnor);
hnor->State = HAL_NOR_STATE_BUSY;
(void)FMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank);
hnor->State = HAL_NOR_STATE_PROTECTED;
__HAL_UNLOCK(hnor);
}if (hnor->State == HAL_NOR_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
return HAL_OK;
}HAL_NOR_WriteOperation_Disable (NOR_HandleTypeDef *hnor) { ... }
/* ... */
/* ... */
/* ... */
HAL_NOR_StateTypeDef HAL_NOR_GetState(const NOR_HandleTypeDef *hnor)
{
return hnor->State;
}HAL_NOR_GetState (const NOR_HandleTypeDef *hnor) { ... }
/* ... */
HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout)
{
HAL_NOR_StatusTypeDef status = HAL_NOR_STATUS_ONGOING;
uint16_t tmpsr1;
uint16_t tmpsr2;
uint32_t tickstart;
HAL_NOR_MspWait(hnor, Timeout);
Poll on NOR memory Ready/Busy signal
tickstart = HAL_GetTick();
if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
{
while ((status != HAL_NOR_STATUS_SUCCESS) && (status != HAL_NOR_STATUS_TIMEOUT))
{
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
status = HAL_NOR_STATUS_TIMEOUT;
}if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
tmpsr1 = *(__IO uint16_t *)Address;
tmpsr2 = *(__IO uint16_t *)Address;
if ((tmpsr1 & NOR_MASK_STATUS_DQ6) == (tmpsr2 & NOR_MASK_STATUS_DQ6))
{
return HAL_NOR_STATUS_SUCCESS ;
}if ((tmpsr1 & NOR_MASK_STATUS_DQ6) == (tmpsr2 & NOR_MASK_STATUS_DQ6)) { ... }
if ((tmpsr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
{
status = HAL_NOR_STATUS_ONGOING;
}if ((tmpsr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5) { ... }
tmpsr1 = *(__IO uint16_t *)Address;
tmpsr2 = *(__IO uint16_t *)Address;
if ((tmpsr1 & NOR_MASK_STATUS_DQ6) == (tmpsr2 & NOR_MASK_STATUS_DQ6))
{
return HAL_NOR_STATUS_SUCCESS;
}if ((tmpsr1 & NOR_MASK_STATUS_DQ6) == (tmpsr2 & NOR_MASK_STATUS_DQ6)) { ... }
if ((tmpsr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
{
return HAL_NOR_STATUS_ERROR;
}if ((tmpsr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5) { ... }
}while ((status != HAL_NOR_STATUS_SUCCESS) && (status != HAL_NOR_STATUS_TIMEOUT)) { ... }
}if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET) { ... }
else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
{
do
{
NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG);
tmpsr2 = *(__IO uint16_t *)(Address);
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
return HAL_NOR_STATUS_TIMEOUT;
}if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
...} while ((tmpsr2 & NOR_MASK_STATUS_DQ7) == 0U);
NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG);
tmpsr1 = *(__IO uint16_t *)(Address);
if ((tmpsr1 & (NOR_MASK_STATUS_DQ5 | NOR_MASK_STATUS_DQ4)) != 0U)
{
NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG);
status = HAL_NOR_STATUS_ERROR;
}if ((tmpsr1 & (NOR_MASK_STATUS_DQ5 | NOR_MASK_STATUS_DQ4)) != 0U) { ... }
else
{
status = HAL_NOR_STATUS_SUCCESS;
}else { ... }
}else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET) { ... }
else
{
status = HAL_NOR_STATUS_ERROR;
}else { ... }
return status;
}HAL_NOR_GetStatus (NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout) { ... }
/* ... */
/* ... */
/* ... */
/* ... */
#endif
/* ... */
/* ... */
#endif