@@ -169,8 +169,7 @@ int QSPIFBlockDevice::init()
169
169
_inst_width = QSPI_CFG_BUS_SINGLE;
170
170
_address_width = QSPI_CFG_BUS_SINGLE;
171
171
_address_size = QSPI_CFG_ADDR_SIZE_24;
172
- _alt_size = QSPI_CFG_ALT_SIZE_8;
173
- _alt_enabled = false ;
172
+ _alt_size = 0 ;
174
173
_dummy_cycles = 0 ;
175
174
_data_width = QSPI_CFG_BUS_SINGLE;
176
175
_write_register_inst = QSPIF_WRSR;
@@ -248,8 +247,11 @@ int QSPIFBlockDevice::init()
248
247
}
249
248
250
249
// Configure BUS Mode to 1_1_1 for all commands other than Read
251
- _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
252
- QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0 );
250
+ if (QSPI_STATUS_OK != _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
251
+ 0 , QSPI_CFG_BUS_SINGLE, 0 )) {
252
+ status = QSPIF_BD_ERROR_CONF_FORMAT_FAILED;
253
+ goto exit_point;
254
+ }
253
255
254
256
_is_initialized = true ;
255
257
@@ -304,17 +306,21 @@ int QSPIFBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
304
306
_mutex.lock ();
305
307
306
308
// Configure Bus for Reading
307
- _qspi_configure_format (_inst_width, _address_width, _address_size, _address_width, // Alt width == address width
308
- _alt_size, _data_width, _dummy_cycles);
309
+ if (QSPI_STATUS_OK != _qspi_configure_format (_inst_width, _address_width, _address_size, _address_width, // Alt width == address width
310
+ _alt_size, _data_width, _dummy_cycles)) {
311
+ return QSPIF_BD_ERROR_CONF_FORMAT_FAILED;
312
+ }
309
313
310
314
if (QSPI_STATUS_OK != _qspi_send_read_command (_read_instruction, buffer, addr, size)) {
311
- status = QSPIF_BD_ERROR_DEVICE_ERROR;
312
315
tr_error (" Read Command failed" );
316
+ return QSPIF_BD_ERROR_DEVICE_ERROR;
313
317
}
314
318
315
319
// All commands other than Read use default 1-1-1 Bus mode (Program/Erase are constrained by flash memory performance more than bus performance)
316
- _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
317
- QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0 );
320
+ if (QSPI_STATUS_OK != _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
321
+ 0 , QSPI_CFG_BUS_SINGLE, 0 )) {
322
+ return QSPIF_BD_ERROR_CONF_FORMAT_FAILED;
323
+ }
318
324
319
325
_mutex.unlock ();
320
326
return status;
@@ -719,8 +725,10 @@ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_
719
725
bd_addr_t addr = 0x0 ;
720
726
721
727
// Set 1-1-1 bus mode for SFDP header parsing
722
- _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
723
- QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 8 );
728
+ if (QSPI_STATUS_OK != _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
729
+ 0 , QSPI_CFG_BUS_SINGLE, 8 )) {
730
+ return -1 ;
731
+ }
724
732
725
733
qspi_status_t status = _qspi_send_read_command (QSPIF_SFDP, (char *)sfdp_header, addr /* address*/ , data_length);
726
734
if (status != QSPI_STATUS_OK) {
@@ -886,8 +894,10 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
886
894
}
887
895
888
896
// Configure BUS Mode to 1_1_1 for all commands other than Read
889
- _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
890
- QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0 );
897
+ if (QSPI_STATUS_OK != _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
898
+ 0 , QSPI_CFG_BUS_SINGLE, 0 )) {
899
+ return -1 ;
900
+ }
891
901
892
902
// Read Status Register
893
903
if (QSPI_STATUS_OK == _qspi_send_general_command (_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL , 0 ,
@@ -1028,7 +1038,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
1028
1038
is_qpi_mode = true ;
1029
1039
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_READ_INST_BYTE - 1 ] & 0x1F ;
1030
1040
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_READ_INST_BYTE - 1 ] >> 5 ;
1031
- _utils_determine_alt_size ( mode_cycles * 4 ) ;
1041
+ _alt_size = mode_cycles * 4 ;
1032
1042
tr_debug (" Read Bus Mode set to 4-4-4, Instruction: 0x%xh" , _read_instruction);
1033
1043
// _inst_width = QSPI_CFG_BUS_QUAD;
1034
1044
_address_width = QSPI_CFG_BUS_QUAD;
@@ -1043,7 +1053,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
1043
1053
set_quad_enable = true ;
1044
1054
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_144_READ_INST_BYTE - 1 ] & 0x1F ;
1045
1055
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_144_READ_INST_BYTE - 1 ] >> 5 ;
1046
- _utils_determine_alt_size ( mode_cycles * 4 ) ;
1056
+ _alt_size = mode_cycles * 4 ;
1047
1057
_address_width = QSPI_CFG_BUS_QUAD;
1048
1058
_data_width = QSPI_CFG_BUS_QUAD;
1049
1059
tr_debug (" Read Bus Mode set to 1-4-4, Instruction: 0x%xh" , _read_instruction);
@@ -1056,7 +1066,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
1056
1066
set_quad_enable = true ;
1057
1067
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_114_READ_INST_BYTE - 1 ] & 0x1F ;
1058
1068
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_114_READ_INST_BYTE - 1 ] >> 5 ;
1059
- _utils_determine_alt_size ( mode_cycles) ;
1069
+ _alt_size = mode_cycles;
1060
1070
_data_width = QSPI_CFG_BUS_QUAD;
1061
1071
tr_debug (" Read Bus Mode set to 1-1-4, Instruction: 0x%xh" , _read_instruction);
1062
1072
break ;
@@ -1067,7 +1077,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
1067
1077
read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE];
1068
1078
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE - 1 ] & 0x1F ;
1069
1079
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE - 1 ] >> 5 ;
1070
- _utils_determine_alt_size ( mode_cycles * 2 ) ;
1080
+ _alt_size = mode_cycles * 2 ;
1071
1081
_address_width = QSPI_CFG_BUS_DUAL;
1072
1082
_data_width = QSPI_CFG_BUS_DUAL;
1073
1083
tr_debug (" Read Bus Mode set to 2-2-2, Instruction: 0x%xh" , _read_instruction);
@@ -1080,7 +1090,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
1080
1090
read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE];
1081
1091
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE - 1 ] & 0x1F ;
1082
1092
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE - 1 ] >> 5 ;
1083
- _utils_determine_alt_size ( mode_cycles * 2 ) ;
1093
+ _alt_size = mode_cycles * 2 ;
1084
1094
_address_width = QSPI_CFG_BUS_DUAL;
1085
1095
_data_width = QSPI_CFG_BUS_DUAL;
1086
1096
tr_debug (" Read Bus Mode set to 1-2-2, Instruction: 0x%xh" , _read_instruction);
@@ -1091,7 +1101,7 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
1091
1101
read_inst = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE];
1092
1102
_dummy_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE - 1 ] & 0x1F ;
1093
1103
uint8_t mode_cycles = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE - 1 ] >> 5 ;
1094
- _utils_determine_alt_size ( mode_cycles) ;
1104
+ _alt_size = mode_cycles;
1095
1105
_data_width = QSPI_CFG_BUS_DUAL;
1096
1106
tr_debug (" Read Bus Mode set to 1-1-2, Instruction: 0x%xh" , _read_instruction);
1097
1107
break ;
@@ -1212,8 +1222,10 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
1212
1222
status_reg_qer_setup[2 ] = 0x2 ; // Bit 1 of config Reg 2
1213
1223
1214
1224
// Configure BUS Mode to 1_1_1 for all commands other than Read
1215
- _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
1216
- QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0 );
1225
+ if (QSPI_STATUS_OK != _qspi_configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
1226
+ 0 , QSPI_CFG_BUS_SINGLE, 0 )) {
1227
+ return -1 ;
1228
+ }
1217
1229
1218
1230
// Read Status Register
1219
1231
if (QSPI_STATUS_OK == _qspi_send_general_command (read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL , 0 ,
@@ -1315,28 +1327,6 @@ int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield,
1315
1327
return largest_erase_type;
1316
1328
}
1317
1329
1318
- void QSPIFBlockDevice::_utils_determine_alt_size (uint8_t mode_bits)
1319
- {
1320
- _alt_enabled = true ;
1321
- switch (mode_bits) {
1322
- case 8 :
1323
- _alt_size = QSPI_CFG_ALT_SIZE_8;
1324
- break ;
1325
- case 16 :
1326
- _alt_size = QSPI_CFG_ALT_SIZE_16;
1327
- break ;
1328
- case 24 :
1329
- _alt_size = QSPI_CFG_ALT_SIZE_24;
1330
- break ;
1331
- case 32 :
1332
- _alt_size = QSPI_CFG_ALT_SIZE_32;
1333
- break ;
1334
- default :
1335
- _alt_enabled = false ;
1336
- break ;
1337
- }
1338
- }
1339
-
1340
1330
/* **************************************************/
1341
1331
/* ********** QSPI Driver API Functions *************/
1342
1332
/* **************************************************/
@@ -1351,7 +1341,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst,
1351
1341
// Send Read command to device driver
1352
1342
size_t buf_len = size;
1353
1343
1354
- if (_qspi.read (read_inst, _alt_enabled ? QSPI_ALT_DEFAULT_VALUE : -1 , (unsigned int )addr, (char *)buffer, &buf_len) != QSPI_STATUS_OK) {
1344
+ if (_qspi.read (read_inst, (_alt_size == 0 ) ? -1 : QSPI_ALT_DEFAULT_VALUE , (unsigned int )addr, (char *)buffer, &buf_len) != QSPI_STATUS_OK) {
1355
1345
tr_error (" Read failed" );
1356
1346
return QSPI_STATUS_ERROR;
1357
1347
}
0 commit comments