64
64
#define QSPIF_BASIC_PARAM_ERASE_TYPE_4_SIZE_BYTE 34
65
65
#define QSPIF_BASIC_PARAM_4K_ERASE_TYPE_BYTE 1
66
66
67
-
68
67
// Erase Types Per Region BitMask
69
68
#define ERASE_BITMASK_TYPE4 0x08
70
- #define ERASE_BITMASK_TYPE3 0x04
71
- #define ERASE_BITMASK_TYPE2 0x02
72
69
#define ERASE_BITMASK_TYPE1 0x01
73
- #define ERASE_BITMASK_NONE 0x00
74
70
#define ERASE_BITMASK_ALL 0x0F
75
71
76
72
#define IS_MEM_READY_MAX_RETRIES 1000
77
73
78
- // Debug Printouts
79
- #define QSPIF_DEBUG_ERROR 1
80
- #define QSPIF_DEBUG_WARNING 2
81
- #define QSPIF_DEBUG_INFO 3
82
- #define QSPIF_DEBUG_DEBUG 4
83
- #define QSPIF_DEBUG_TRACE 5
84
-
85
74
namespace mbed {
86
75
87
76
enum qspif_default_instructions {
@@ -104,7 +93,6 @@ static int local_math_power(int base, int exp);
104
93
105
94
/* ******** Public API Functions *********/
106
95
/* ***************************************/
107
-
108
96
QSPIFBlockDevice::QSPIFBlockDevice (PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName csel,
109
97
qspif_polarity_mode clock_mode, int freq)
110
98
: _qspi(io0, io1, io2, io3, sclk, csel, clock_mode), _device_size_bytes(0 )
@@ -126,7 +114,6 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
126
114
}
127
115
}
128
116
129
-
130
117
int QSPIFBlockDevice::init ()
131
118
{
132
119
@@ -241,7 +228,6 @@ int QSPIFBlockDevice::deinit()
241
228
return result;
242
229
}
243
230
244
-
245
231
int QSPIFBlockDevice::read (void *buffer, bd_addr_t addr, bd_size_t size)
246
232
{
247
233
@@ -270,15 +256,14 @@ int QSPIFBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
270
256
271
257
}
272
258
273
-
274
259
int QSPIFBlockDevice::program (const void *buffer, bd_addr_t addr, bd_size_t size)
275
260
{
276
261
qspi_status_t result = QSPI_STATUS_OK;
277
262
bool program_failed = false ;
278
263
int status = QSPIF_BD_ERROR_OK;
279
264
uint32_t offset = 0 ;
280
265
uint32_t chunk = 0 ;
281
- bd_size_t writtenBytes = 0 ;
266
+ bd_size_t written_bytes = 0 ;
282
267
283
268
tr_debug (" DEBUG: program - Buff: 0x%x, addr: %llu, size: %llu" , buffer, addr, size);
284
269
@@ -287,7 +272,7 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
287
272
// Write on _page_size_bytes boundaries (Default 256 bytes a page)
288
273
offset = addr % _page_size_bytes;
289
274
chunk = (offset + size < _page_size_bytes) ? size : (_page_size_bytes - offset);
290
- writtenBytes = chunk;
275
+ written_bytes = chunk;
291
276
292
277
_mutex.lock ();
293
278
@@ -299,8 +284,8 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
299
284
goto exit_point;
300
285
}
301
286
302
- result = _qspi_send_program_command (_prog_instruction, buffer, addr, &writtenBytes );
303
- if ( (result != QSPI_STATUS_OK) || (chunk != writtenBytes ) ) {
287
+ result = _qspi_send_program_command (_prog_instruction, buffer, addr, &written_bytes );
288
+ if ( (result != QSPI_STATUS_OK) || (chunk != written_bytes ) ) {
304
289
tr_error (" ERROR: Write failed" );
305
290
program_failed = true ;
306
291
status = QSPIF_BD_ERROR_DEVICE_ERROR;
@@ -318,8 +303,6 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
318
303
goto exit_point;
319
304
}
320
305
_mutex.unlock ();
321
-
322
-
323
306
}
324
307
325
308
exit_point:
@@ -330,10 +313,8 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
330
313
return status;
331
314
}
332
315
333
-
334
- int QSPIFBlockDevice::erase (bd_addr_t addr, bd_size_t inSize)
316
+ int QSPIFBlockDevice::erase (bd_addr_t addr, bd_size_t in_size)
335
317
{
336
-
337
318
int type = 0 ;
338
319
uint32_t chunk = 4096 ;
339
320
unsigned int cur_erase_inst = _erase_instruction;
@@ -345,7 +326,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t inSize)
345
326
// Erase Types of selected region
346
327
uint8_t bitfield = _region_erase_types_bitfield[region];
347
328
348
- tr_debug (" DEBUG: erase - addr: %llu, inSize: %llu" , addr, inSize );
329
+ tr_debug (" DEBUG: erase - addr: %llu, inSize: %llu" , addr, in_size );
349
330
350
331
// For each iteration erase the largest section supported by current region
351
332
while (size > 0 ) {
@@ -404,8 +385,6 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t inSize)
404
385
return status;
405
386
}
406
387
407
-
408
-
409
388
bd_size_t QSPIFBlockDevice::get_read_size () const
410
389
{
411
390
// Assuming all devices support 1byte read granularity
@@ -424,7 +403,6 @@ bd_size_t QSPIFBlockDevice::get_erase_size() const
424
403
return _min_common_erase_size;
425
404
}
426
405
427
-
428
406
// Find minimal erase size supported by the region to which the address belongs to
429
407
bd_size_t QSPIFBlockDevice::get_erase_size (bd_addr_t addr)
430
408
{
@@ -455,19 +433,16 @@ bd_size_t QSPIFBlockDevice::get_erase_size(bd_addr_t addr)
455
433
}
456
434
457
435
return (bd_size_t )min_region_erase_size;
458
-
459
436
}
460
437
461
438
bd_size_t QSPIFBlockDevice::size () const
462
439
{
463
440
return _device_size_bytes;
464
441
}
465
442
466
-
467
443
/* ********************************************************/
468
444
/* ********* SFDP Parsing and Detection Functions *********/
469
445
/* ********************************************************/
470
-
471
446
int QSPIFBlockDevice::_sfdp_parse_sector_map_table (uint32_t sector_map_table_addr, size_t sector_map_table_size)
472
447
{
473
448
uint8_t sector_map_table[SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES]; /* Up To 16 DWORDS = 64 Bytes */
@@ -527,7 +502,6 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
527
502
return 0 ;
528
503
}
529
504
530
-
531
505
int QSPIFBlockDevice::_sfdp_parse_basic_param_table (uint32_t basic_table_addr, size_t basic_table_size)
532
506
{
533
507
uint8_t param_table[SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES]; /* Up To 16 DWORDS = 64 Bytes */
@@ -654,8 +628,6 @@ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t& basic_table_addr, size_
654
628
return 0 ;
655
629
}
656
630
657
-
658
-
659
631
int QSPIFBlockDevice::_sfdp_set_qpi_enabled (uint8_t *basic_param_table_ptr)
660
632
{
661
633
uint8_t config_reg[1 ];
@@ -803,11 +775,9 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
803
775
return -1 ;
804
776
}
805
777
806
-
807
778
return 0 ;
808
779
}
809
780
810
-
811
781
int QSPIFBlockDevice::_sfdp_detect_page_size (uint8_t *basic_param_table_ptr)
812
782
{
813
783
// Page Size is specified by 4 Bits (N), calculated by 2^N
@@ -817,8 +787,6 @@ int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr)
817
787
return page_size;
818
788
}
819
789
820
-
821
-
822
790
int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size (uint8_t *basic_param_table_ptr, unsigned int & erase4k_inst,
823
791
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr)
824
792
{
@@ -869,7 +837,6 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
869
837
return 0 ;
870
838
}
871
839
872
-
873
840
int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode (uint8_t *basic_param_table_ptr, bool & set_quad_enable,
874
841
bool & is_qpi_mode,
875
842
unsigned int & read_inst)
@@ -957,7 +924,6 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
957
924
return 0 ;
958
925
}
959
926
960
-
961
927
int QSPIFBlockDevice::_reset_flash_mem ()
962
928
{
963
929
// Perform Soft Reset of the Device prior to initialization
@@ -1001,7 +967,6 @@ int QSPIFBlockDevice::_reset_flash_mem()
1001
967
return status;
1002
968
}
1003
969
1004
-
1005
970
bool QSPIFBlockDevice::_is_mem_ready ()
1006
971
{
1007
972
// Check Status Register Busy Bit to Verify the Device isn't Busy
@@ -1026,7 +991,6 @@ bool QSPIFBlockDevice::_is_mem_ready()
1026
991
return mem_ready;
1027
992
}
1028
993
1029
-
1030
994
int QSPIFBlockDevice::_set_write_enable ()
1031
995
{
1032
996
// Check Status Register Busy Bit to Verify the Device isn't Busy
@@ -1060,8 +1024,6 @@ int QSPIFBlockDevice::_set_write_enable()
1060
1024
return status;
1061
1025
}
1062
1026
1063
-
1064
-
1065
1027
/* ********************************************/
1066
1028
/* ************ Utility Functions *************/
1067
1029
/* ********************************************/
@@ -1086,7 +1048,6 @@ int QSPIFBlockDevice::_utils_find_addr_region(bd_size_t offset)
1086
1048
1087
1049
}
1088
1050
1089
-
1090
1051
int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type (uint8_t & bitfield, int size, int offset, int boundry)
1091
1052
{
1092
1053
// Iterate on all supported Erase Types of the Region to which the offset belong to.
@@ -1114,17 +1075,14 @@ int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t& bitfield,
1114
1075
1115
1076
}
1116
1077
1117
-
1118
1078
/* **************************************************/
1119
1079
/* ********** QSPI Driver API Functions *************/
1120
1080
/* **************************************************/
1121
-
1122
1081
qspi_status_t QSPIFBlockDevice::_qsp_set_frequency (int freq)
1123
1082
{
1124
1083
return _qspi.set_frequency (freq);
1125
1084
}
1126
1085
1127
-
1128
1086
qspi_status_t QSPIFBlockDevice::_qspi_send_read_command (unsigned int read_inst, void *buffer, bd_addr_t addr,
1129
1087
bd_size_t size)
1130
1088
{
@@ -1140,7 +1098,6 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst,
1140
1098
1141
1099
}
1142
1100
1143
-
1144
1101
qspi_status_t QSPIFBlockDevice::_qspi_send_program_command (unsigned int progInst, const void *buffer, bd_addr_t addr,
1145
1102
bd_size_t *size)
1146
1103
{
@@ -1155,15 +1112,14 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_program_command(unsigned int progInst
1155
1112
return result;
1156
1113
}
1157
1114
1158
-
1159
- qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command (unsigned int eraseInst, bd_addr_t addr, bd_size_t size)
1115
+ qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command (unsigned int erase_inst, bd_addr_t addr, bd_size_t size)
1160
1116
{
1161
1117
// Send Erase Instruction command to driver
1162
1118
qspi_status_t result = QSPI_STATUS_OK;
1163
1119
1164
- tr_info (" INFO: Inst: 0x%xh, addr: %llu, size: %llu" , eraseInst , addr, size);
1120
+ tr_info (" INFO: Inst: 0x%xh, addr: %llu, size: %llu" , erase_inst , addr, size);
1165
1121
1166
- result = _qspi.command_transfer (eraseInst , // command to send
1122
+ result = _qspi.command_transfer (erase_inst , // command to send
1167
1123
(((int )addr) & 0x00FFF000 ), // Align addr to 4096
1168
1124
NULL , // do not transmit
1169
1125
0 , // do not transmit
@@ -1178,7 +1134,6 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_erase_command(unsigned int eraseInst,
1178
1134
1179
1135
}
1180
1136
1181
-
1182
1137
qspi_status_t QSPIFBlockDevice::_qspi_send_general_command (unsigned int instruction, bd_addr_t addr,
1183
1138
const char *tx_buffer,
1184
1139
size_t tx_length, const char *rx_buffer, size_t rx_length)
@@ -1193,7 +1148,6 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(unsigned int instruct
1193
1148
return status;
1194
1149
}
1195
1150
1196
-
1197
1151
qspi_status_t QSPIFBlockDevice::_qspi_configure_format (qspi_bus_width_t inst_width, qspi_bus_width_t address_width,
1198
1152
qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width,
1199
1153
int dummy_cycles)
@@ -1205,7 +1159,6 @@ qspi_status_t QSPIFBlockDevice::_qspi_configure_format(qspi_bus_width_t inst_wid
1205
1159
return status;
1206
1160
}
1207
1161
1208
-
1209
1162
/* ********************************************/
1210
1163
/* ************* Local Functions **************/
1211
1164
/* ********************************************/
0 commit comments