Skip to content

Commit fe49c9c

Browse files
author
Veijo Pesonen
committed
Q/SPIF: Abstracts SFDP table reading functionality from device
1 parent 829a3cd commit fe49c9c

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ int QSPIFBlockDevice::init()
252252
}
253253

254254
/**************************** Parse Basic Parameters Table ***********************************/
255-
if (0 != _sfdp_parse_basic_param_table(_sfdp_info.bptbl.addr, _sfdp_info.bptbl.size)) {
255+
if (_sfdp_parse_basic_param_table(callback(this, &QSPIFBlockDevice::_qspi_send_read_sfdp_command),
256+
_sfdp_info.bptbl.addr, _sfdp_info.bptbl.size) < 0) {
256257
tr_error("Init - Parse Basic Param Table Failed");
257258
status = QSPIF_BD_ERROR_PARSING_FAILED;
258259
goto exit_point;
@@ -626,11 +627,12 @@ int QSPIFBlockDevice::remove_csel_instance(PinName csel)
626627
/*********************************************************/
627628
/********** SFDP Parsing and Detection Functions *********/
628629
/*********************************************************/
629-
int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size)
630+
int QSPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader,
631+
uint32_t basic_table_addr, size_t basic_table_size)
630632
{
631-
uint8_t param_table[SFDP_BASIC_PARAMS_TBL_SIZE]; /* Up To 16 DWORDS = 64 Bytes */
633+
uint8_t param_table[SFDP_BASIC_PARAMS_TBL_SIZE]; /* Up To 20 DWORDS = 80 Bytes */
632634

633-
int status = _qspi_send_read_sfdp_command(basic_table_addr, (char *)param_table, basic_table_size);
635+
int status = sfdp_reader(basic_table_addr, param_table, basic_table_size);
634636
if (status != QSPI_STATUS_OK) {
635637
tr_error("Init - Read SFDP First Table Failed");
636638
return -1;

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
317317
/* SFDP Detection and Parsing Functions */
318318
/****************************************/
319319
// Parse and Detect required Basic Parameters from Table
320-
int _sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size);
320+
int _sfdp_parse_basic_param_table(mbed::Callback<int(mbed::bd_addr_t, void *, mbed::bd_size_t)> sfdp_reader,
321+
uint32_t basic_table_addr, size_t basic_table_size);
321322

322323
// Detect the soft reset protocol and reset - returns error if soft reset is not supported
323324
int _sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr);

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ using namespace mbed;
4343

4444
/* Basic Parameters Table Parsing */
4545
/**********************************/
46-
#define SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES 64 /* 16 DWORDS */
4746
//READ Instruction support according to BUS Configuration
4847
#define SPIF_BASIC_PARAM_TABLE_FAST_READ_SUPPORT_BYTE 2
4948
#define SPIF_BASIC_PARAM_TABLE_QPI_READ_SUPPORT_BYTE 16
@@ -183,7 +182,7 @@ int SPIFBlockDevice::init()
183182

184183

185184
/**************************** Parse Basic Parameters Table ***********************************/
186-
if (0 != _sfdp_parse_basic_param_table(hdr_info.bptbl.addr, hdr_info.bptbl.size)) {
185+
if (0 != _sfdp_parse_basic_param_table(callback(this, &SPIFBlockDevice::_spi_send_read_sfdp_command), hdr_info.bptbl.addr, hdr_info.bptbl.size)) {
187186
tr_error("init - Parse Basic Param Table Failed");
188187
status = SPIF_BD_ERROR_PARSING_FAILED;
189188
goto exit_point;
@@ -620,13 +619,12 @@ spif_bd_error SPIFBlockDevice::_spi_send_general_command(int instruction, bd_add
620619
/*********************************************************/
621620
/********** SFDP Parsing and Detection Functions *********/
622621
/*********************************************************/
623-
int SPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size)
622+
int SPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader,
623+
uint32_t basic_table_addr, size_t basic_table_size)
624624
{
625-
uint8_t param_table[SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES]; /* Up To 16 DWORDS = 64 Bytes */
626-
//memset(param_table, 0, SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES);
625+
uint8_t param_table[SFDP_BASIC_PARAMS_TBL_SIZE]; /* Up To 20 DWORDS = 80 Bytes */
627626

628-
spif_bd_error status = _spi_send_read_command(SPIF_SFDP, param_table, basic_table_addr /*address*/,
629-
basic_table_size);
627+
int status = sfdp_reader(basic_table_addr, param_table, basic_table_size);
630628
if (status != SPIF_BD_ERROR_OK) {
631629
tr_error("init - Read SFDP First Table Failed");
632630
return -1;

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ class SPIFBlockDevice : public mbed::BlockDevice {
230230
int _spi_send_read_sfdp_command(mbed::bd_addr_t addr, void *rx_buffer, mbed::bd_size_t rx_length);
231231

232232
// Parse and Detect required Basic Parameters from Table
233-
int _sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size);
233+
int _sfdp_parse_basic_param_table(mbed::Callback<int(mbed::bd_addr_t, void *, mbed::bd_size_t)> sfdp_reader,
234+
uint32_t basic_table_addr, size_t basic_table_size);
234235

235236
// Detect fastest read Bus mode supported by device
236237
int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size, int &read_inst);

0 commit comments

Comments
 (0)