@@ -97,32 +97,21 @@ using namespace mbed;
97
97
98
98
#define IS_MEM_READY_MAX_RETRIES 10000
99
99
100
- enum qspif_default_instructions {
101
- QSPIF_NOP = 0x00 , // No operation
102
- QSPIF_PP = 0x02 , // Page Program data
103
- QSPIF_READ = 0x03 , // Read data
104
- QSPIF_SE = 0x20 , // 4KB Sector Erase
105
- QSPIF_SFDP = 0x5a , // Read SFDP
106
- QSPIF_WRSR = 0x01 , // Write Status/Configuration Register
107
- QSPIF_WRDI = 0x04 , // Write Disable
108
- QSPIF_RDSR = 0x05 , // Read Status Register
109
- QSPIF_WREN = 0x06 , // Write Enable
110
- QSPIF_RSTEN = 0x66 , // Reset Enable
111
- QSPIF_RST = 0x99 , // Reset
112
- QSPIF_RDID = 0x9f , // Read Manufacturer and JDEC Device ID
113
- QSPIF_ULBPR = 0x98 , // Clears all write-protection bits in the Block-Protection register
114
- };
115
100
116
101
// General QSPI instructions
117
102
#define QSPIF_INST_WSR1 0x01 // Write status register 1
103
+ #define QSPIF_INST_PROG 0x02 // Page program
104
+ #define QSPIF_INST_WRDI 0x04 // Write disable
118
105
#define QSPIF_INST_RSR1 0x05 // Read status register 1
106
+ #define QSPIF_INST_WREN 0x06 // Write enable
119
107
#define QSPIF_INST_RSFDP 0x5A // Read SFDP
120
108
#define QSPIF_INST_RDID 0x9F // Read Manufacturer and JDEC Device ID
121
109
122
110
// Device-specific instructions
123
111
#define QSPIF_INST_ULBPR 0x98 // Clear all write-protection bits in the Block-Protection register
124
112
125
- // Default legacy erase instruction
113
+ // Default read/legacy erase instructions
114
+ #define QSPIF_INST_READ_DEFAULT 0x03
126
115
#define QSPIF_INST_LEGACY_ERASE_DEFAULT QSPI_NO_INST
127
116
128
117
// Default status register 2 read/write instructions
@@ -163,7 +152,21 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
163
152
tr_error (" Too many different QSPIFBlockDevice devices - max allowed: %d" , QSPIF_MAX_ACTIVE_FLASH_DEVICES);
164
153
}
165
154
166
- // Set default erase instructions
155
+ // Initialize parameters
156
+ _min_common_erase_size = 0 ;
157
+ _regions_count = 1 ;
158
+ _region_erase_types_bitfield[0 ] = ERASE_BITMASK_NONE;
159
+
160
+ // Default Bus Setup 1_1_1 with 0 dummy and mode cycles
161
+ _inst_width = QSPI_CFG_BUS_SINGLE;
162
+ _address_width = QSPI_CFG_BUS_SINGLE;
163
+ _address_size = QSPI_CFG_ADDR_SIZE_24;
164
+ _alt_size = 0 ;
165
+ _dummy_cycles = 0 ;
166
+ _data_width = QSPI_CFG_BUS_SINGLE;
167
+
168
+ // Set default read/erase instructions
169
+ _read_instruction = QSPIF_INST_READ_DEFAULT;
167
170
_legacy_erase_instruction = QSPIF_INST_LEGACY_ERASE_DEFAULT;
168
171
169
172
// Set default status register 2 write/read instructions
@@ -212,18 +215,8 @@ int QSPIFBlockDevice::init()
212
215
goto exit_point;
213
216
}
214
217
215
- // Initialize parameters
216
- _min_common_erase_size = 0 ;
217
- _regions_count = 1 ;
218
- _region_erase_types_bitfield[0 ] = ERASE_BITMASK_NONE;
219
-
220
- // Default Bus Setup 1_1_1 with 0 dummy and mode cycles
221
- _inst_width = QSPI_CFG_BUS_SINGLE;
222
- _address_width = QSPI_CFG_BUS_SINGLE;
223
- _address_size = QSPI_CFG_ADDR_SIZE_24;
224
218
_alt_size = 0 ;
225
219
_dummy_cycles = 0 ;
226
- _data_width = QSPI_CFG_BUS_SINGLE;
227
220
if (QSPI_STATUS_OK != _qspi_set_frequency (_freq)) {
228
221
tr_error (" QSPI Set Frequency Failed" );
229
222
status = QSPIF_BD_ERROR_DEVICE_ERROR;
@@ -300,7 +293,7 @@ int QSPIFBlockDevice::deinit()
300
293
}
301
294
302
295
// Disable Device for Writing
303
- qspi_status_t status = _qspi_send_general_command (QSPIF_WRDI , QSPI_NO_ADDRESS_COMMAND, NULL , 0 , NULL , 0 );
296
+ qspi_status_t status = _qspi_send_general_command (QSPIF_INST_WRDI , QSPI_NO_ADDRESS_COMMAND, NULL , 0 , NULL , 0 );
304
297
if (status != QSPI_STATUS_OK) {
305
298
tr_error (" Write Disable failed" );
306
299
result = QSPIF_BD_ERROR_DEVICE_ERROR;
@@ -362,7 +355,7 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
362
355
goto exit_point;
363
356
}
364
357
365
- result = _qspi_send_program_command (_prog_instruction , buffer, addr, &written_bytes);
358
+ result = _qspi_send_program_command (QSPIF_INST_PROG , buffer, addr, &written_bytes);
366
359
if ((result != QSPI_STATUS_OK) || (chunk != written_bytes)) {
367
360
tr_error (" Write failed" );
368
361
program_failed = true ;
@@ -708,9 +701,6 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
708
701
param_table[4 ]);
709
702
_device_size_bytes = (density_bits + 1 ) / 8 ;
710
703
711
- // Set Default read/program Instructions
712
- _read_instruction = QSPIF_READ;
713
- _prog_instruction = QSPIF_PP;
714
704
// Set Page Size (QSPI write must be done on Page limits)
715
705
_page_size_bytes = _sfdp_detect_page_size (param_table, basic_table_size);
716
706
@@ -729,7 +719,7 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
729
719
}
730
720
731
721
// Detect and Set fastest Bus mode (default 1-1-1)
732
- _sfdp_detect_best_bus_read_mode (param_table, basic_table_size, shouldSetQuadEnable, is_qpi_mode, _read_instruction );
722
+ _sfdp_detect_best_bus_read_mode (param_table, basic_table_size, shouldSetQuadEnable, is_qpi_mode);
733
723
if (true == shouldSetQuadEnable) {
734
724
// Set Quad Enable and QPI Bus modes if Supported
735
725
tr_debug (" Init - Setting Quad Enable" );
@@ -929,8 +919,7 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
929
919
}
930
920
931
921
int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode (uint8_t *basic_param_table_ptr, int basic_param_table_size,
932
- bool &set_quad_enable,
933
- bool &is_qpi_mode, qspi_inst_t &read_inst)
922
+ bool &set_quad_enable, bool &is_qpi_mode)
934
923
{
935
924
set_quad_enable = false ;
936
925
is_qpi_mode = false ;
@@ -943,14 +932,13 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
943
932
944
933
if (examined_byte & 0x10 ) {
945
934
// QPI 4-4-4 Supported
946
- read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_READ_INST_BYTE];
935
+ _read_instruction = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_READ_INST_BYTE];
947
936
set_quad_enable = true ;
948
937
is_qpi_mode = true ;
949
938
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_READ_INST_BYTE - 1 ] & 0x1F ;
950
939
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_READ_INST_BYTE - 1 ] >> 5 ;
951
940
_alt_size = mode_cycles * 4 ;
952
941
tr_debug (" Read Bus Mode set to 4-4-4, Instruction: 0x%xh" , _read_instruction);
953
- // _inst_width = QSPI_CFG_BUS_QUAD;
954
942
_address_width = QSPI_CFG_BUS_QUAD;
955
943
_data_width = QSPI_CFG_BUS_QUAD;
956
944
}
@@ -959,7 +947,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
959
947
examined_byte = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_FAST_READ_SUPPORT_BYTE];
960
948
if (examined_byte & 0x20 ) {
961
949
// Fast Read 1-4-4 Supported
962
- read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_144_READ_INST_BYTE];
950
+ _read_instruction = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_144_READ_INST_BYTE];
963
951
set_quad_enable = true ;
964
952
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_144_READ_INST_BYTE - 1 ] & 0x1F ;
965
953
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_144_READ_INST_BYTE - 1 ] >> 5 ;
@@ -972,7 +960,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
972
960
973
961
if (examined_byte & 0x40 ) {
974
962
// Fast Read 1-1-4 Supported
975
- read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_114_READ_INST_BYTE];
963
+ _read_instruction = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_114_READ_INST_BYTE];
976
964
set_quad_enable = true ;
977
965
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_114_READ_INST_BYTE - 1 ] & 0x1F ;
978
966
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_114_READ_INST_BYTE - 1 ] >> 5 ;
@@ -984,7 +972,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
984
972
examined_byte = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_QPI_READ_SUPPORT_BYTE];
985
973
if (examined_byte & 0x01 ) {
986
974
// Fast Read 2-2-2 Supported
987
- read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE];
975
+ _read_instruction = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE];
988
976
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE - 1 ] & 0x1F ;
989
977
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE - 1 ] >> 5 ;
990
978
_alt_size = mode_cycles * 2 ;
@@ -997,7 +985,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
997
985
examined_byte = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_FAST_READ_SUPPORT_BYTE];
998
986
if (examined_byte & 0x10 ) {
999
987
// Fast Read 1-2-2 Supported
1000
- read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE];
988
+ _read_instruction = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE];
1001
989
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE - 1 ] & 0x1F ;
1002
990
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE - 1 ] >> 5 ;
1003
991
_alt_size = mode_cycles * 2 ;
@@ -1008,14 +996,15 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
1008
996
}
1009
997
if (examined_byte & 0x01 ) {
1010
998
// Fast Read 1-1-2 Supported
1011
- read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE];
999
+ _read_instruction = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE];
1012
1000
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE - 1 ] & 0x1F ;
1013
1001
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE - 1 ] >> 5 ;
1014
1002
_alt_size = mode_cycles;
1015
1003
_data_width = QSPI_CFG_BUS_DUAL;
1016
1004
tr_debug (" Read Bus Mode set to 1-1-2, Instruction: 0x%xh" , _read_instruction);
1017
1005
break ;
1018
1006
}
1007
+ _read_instruction = QSPIF_INST_READ_DEFAULT;
1019
1008
tr_debug (" Read Bus Mode set to 1-1-1, Instruction: 0x%xh" , _read_instruction);
1020
1009
} while (false );
1021
1010
@@ -1258,7 +1247,7 @@ int QSPIFBlockDevice::_set_write_enable()
1258
1247
int status = -1 ;
1259
1248
1260
1249
do {
1261
- if (QSPI_STATUS_OK != _qspi_send_general_command (QSPIF_WREN , QSPI_NO_ADDRESS_COMMAND, NULL , 0 , NULL , 0 )) {
1250
+ if (QSPI_STATUS_OK != _qspi_send_general_command (QSPIF_INST_WREN , QSPI_NO_ADDRESS_COMMAND, NULL , 0 , NULL , 0 )) {
1262
1251
tr_error (" Sending WREN command FAILED" );
1263
1252
break ;
1264
1253
}
@@ -1295,10 +1284,11 @@ bool QSPIFBlockDevice::_is_mem_ready()
1295
1284
1296
1285
do {
1297
1286
rtos::ThisThread::sleep_for (1 );
1298
- retries- // Read the Status Register from device
1299
- memset (status_value, 0xFF , QSPI_MAX_STATUS_REGISTER_SIZE);
1300
- if (QSPI_STATUS_OK != _qspi_send_general_command (QSPIF_INST_RSR1, QSPI_NO_ADDRESS_COMMAND, NULL , 0 , (char *) &status_value,
1301
- 1 )) { // store received values in status_value
1287
+ retries++;
1288
+ // Read Status Register 1 from device
1289
+ if (QSPI_STATUS_OK != _qspi_send_general_command (QSPIF_INST_RSR1, QSPI_NO_ADDRESS_COMMAND,
1290
+ NULL , 0 ,
1291
+ (char *) &status_value, 1 )) { // store received value in status_value
1302
1292
tr_error (" Reading Status Register failed" );
1303
1293
}
1304
1294
} while ((status_value & QSPIF_STATUS_BIT_WIP) != 0 && retries < IS_MEM_READY_MAX_RETRIES);
0 commit comments