Skip to content

Commit 7d1886e

Browse files
author
Veijo Pesonen
committed
SFDP: consolidation of sfdp_detect_page_size
1 parent 8a076d4 commit 7d1886e

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ using namespace mbed;
3131

3232
/* Default QSPIF Parameters */
3333
/****************************/
34-
#define QSPIF_DEFAULT_PAGE_SIZE 256
3534
#define QSPIF_DEFAULT_SE_SIZE 4096
3635
// The SFDP spec only defines two status registers. But some devices,
3736
// have three "status-like" registers (one status, two config)
@@ -62,7 +61,6 @@ using namespace mbed;
6261
#define QSPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE 23
6362
#define QSPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE 15
6463
#define QSPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE 13
65-
#define QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE 40
6664
// Quad Enable Params
6765
#define QSPIF_BASIC_PARAM_TABLE_QER_BYTE 58
6866
#define QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE 56
@@ -652,7 +650,7 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void
652650
_device_size_bytes = (density_bits + 1) / 8;
653651

654652
// Set Page Size (QSPI write must be done on Page limits)
655-
_page_size_bytes = _sfdp_detect_page_size(param_table, basic_table_size);
653+
_page_size_bytes = sfdp_detect_page_size(param_table, basic_table_size);
656654

657655
if (_sfdp_detect_reset_protocol_and_reset(param_table) != QSPIF_BD_ERROR_OK) {
658656
tr_error("Init - Detecting reset protocol/resetting failed");
@@ -832,21 +830,6 @@ int QSPIFBlockDevice::_sfdp_set_qpi_enabled(uint8_t *basic_param_table_ptr)
832830
return 0;
833831
}
834832

835-
int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int basic_param_table_size)
836-
{
837-
unsigned int page_size = QSPIF_DEFAULT_PAGE_SIZE;
838-
839-
if (basic_param_table_size > QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE) {
840-
// Page Size is specified by 4 Bits (N), calculated by 2^N
841-
int page_to_power_size = ((int)basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE]) >> 4;
842-
page_size = 1 << page_to_power_size;
843-
tr_debug("Detected Page Size: %d", page_size);
844-
} else {
845-
tr_debug("Using Default Page Size: %d", page_size);
846-
}
847-
return page_size;
848-
}
849-
850833
int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr,
851834
int basic_param_table_size,
852835
sfdp_smptbl_info &smptbl)

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ using namespace mbed;
3030
/****************************/
3131
#define SPIF_DEFAULT_READ_SIZE 1
3232
#define SPIF_DEFAULT_PROG_SIZE 1
33-
#define SPIF_DEFAULT_PAGE_SIZE 256
3433
#define SPIF_DEFAULT_SE_SIZE 4096
3534
#define SPI_MAX_STATUS_REGISTER_SIZE 2
3635
#ifndef UINT64_MAX
@@ -49,7 +48,6 @@ using namespace mbed;
4948
#define SPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE 23
5049
#define SPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE 15
5150
#define SPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE 13
52-
#define SPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE 40
5351
// Address Length
5452
#define SPIF_ADDR_SIZE_3_BYTES 3
5553
#define SPIF_ADDR_SIZE_4_BYTES 4
@@ -653,7 +651,7 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void
653651
_erase_instruction = SPIF_SE;
654652

655653
// Set Page Size (SPI write must be done on Page limits)
656-
_page_size_bytes = _sfdp_detect_page_size(param_table, sfdp_info.bptbl.size);
654+
_page_size_bytes = sfdp_detect_page_size(param_table, sfdp_info.bptbl.size);
657655

658656
// Detect and Set Erase Types
659657
_sfdp_detect_erase_types_inst_and_size(param_table, sfdp_info.bptbl.size, _erase4k_inst, sfdp_info.smptbl);
@@ -665,21 +663,6 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void
665663
return 0;
666664
}
667665

668-
unsigned int SPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int basic_param_table_size)
669-
{
670-
unsigned int page_size = SPIF_DEFAULT_PAGE_SIZE;
671-
672-
if (basic_param_table_size > SPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE) {
673-
// Page Size is specified by 4 Bits (N), calculated by 2^N
674-
int page_to_power_size = ((int)basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE]) >> 4;
675-
page_size = local_math_power(2, page_to_power_size);
676-
tr_debug("Detected Page Size: %d", page_size);
677-
} else {
678-
tr_debug("Using Default Page Size: %d", page_size);
679-
}
680-
return page_size;
681-
}
682-
683666
int SPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
684667
int &erase4k_inst,
685668
sfdp_smptbl_info &smptbl)

drivers/internal/SFDP.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ int sfdp_parse_headers(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader,
126126
*/
127127
int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_smptbl_info &smtbl);
128128

129+
/** Detect page size used for writing on flash
130+
*
131+
* @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
132+
* @param bptbl_size Size of memory holding a Basic Parameter Table
133+
*
134+
* @return Page size
135+
*/
136+
size_t sfdp_detect_page_size(uint8_t *bptbl_ptr, size_t bptbl_size);
137+
129138
/** @}*/
130139
} /* namespace mbed */
131140
#endif

drivers/source/SFDP.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,24 @@ int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp
192192
return 0;
193193
}
194194

195+
size_t sfdp_detect_page_size(uint8_t *basic_param_table_ptr, size_t basic_param_table_size)
196+
{
197+
constexpr int SFDP_BASIC_PARAM_TABLE_PAGE_SIZE = 40;
198+
constexpr int SFDP_DEFAULT_PAGE_SIZE = 256;
199+
200+
unsigned int page_size = SFDP_DEFAULT_PAGE_SIZE;
201+
202+
if (basic_param_table_size > SFDP_BASIC_PARAM_TABLE_PAGE_SIZE) {
203+
// Page Size is specified by 4 Bits (N), calculated by 2^N
204+
int page_to_power_size = ((int)basic_param_table_ptr[SFDP_BASIC_PARAM_TABLE_PAGE_SIZE]) >> 4;
205+
page_size = 1 << page_to_power_size;
206+
tr_debug("Detected Page Size: %d", page_size);
207+
} else {
208+
tr_debug("Using Default Page Size: %d", page_size);
209+
}
210+
return page_size;
211+
}
212+
213+
195214
} /* namespace mbed */
196215
#endif /* (DEVICE_SPI || DEVICE_QSPI) */

0 commit comments

Comments
 (0)