Skip to content

Commit c84deff

Browse files
author
Veijo Pesonen
committed
SFDP: consolidates check for addressability
Takes implementations found from SPIFBlockDevice and QSPIFBlockDevice and makes those as part of the SFDP module.
1 parent 2ce3bed commit c84deff

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void
630630
}
631631

632632
// Check that density is not greater than 4 gigabits (i.e. that addressing beyond 4 bytes is not required)
633-
if ((param_table[7] & 0x80) != 0) {
634-
tr_error("Init - verify flash density failed");
633+
if (sfdp_detect_addressability(param_table, _sfdp_info.bptbl) < 0) {
634+
tr_error("Verify 4byte addressing failed");
635635
return -1;
636636
}
637637

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void
629629
}
630630

631631
// Check address size, currently only supports 3byte addresses
632-
if ((param_table[2] & 0x4) != 0 || (param_table[7] & 0x80) != 0) {
633-
tr_error("init - verify 3byte addressing Failed");
632+
if (sfdp_detect_addressability(param_table, _sfdp_info.bptbl) < 0) {
633+
tr_error("Verify 3byte addressing failed");
634634
return -1;
635635
}
636636

drivers/internal/SFDP.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield,
150150
*/
151151
int sfdp_detect_device_density(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info);
152152

153+
/** Detect is it possible to access the whole memory region
154+
*
155+
* @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
156+
* @param bptbl_info Basic Parameter Table information structure
157+
*
158+
* @return 0 on success, negative error code on failure
159+
*/
160+
int sfdp_detect_addressability(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info);
161+
153162
/** @}*/
154163
} /* namespace mbed */
155164
#endif

drivers/source/SFDP.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,5 +360,27 @@ int sfdp_detect_device_density(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info)
360360
return 0;
361361
}
362362

363+
#if DEVICE_QSPI
364+
int sfdp_detect_addressability(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info)
365+
{
366+
// Check that density is not greater than 4 gigabits (i.e. that addressing beyond 4 bytes is not required)
367+
if ((bptbl_ptr[7] & 0x80) != 0) {
368+
return -1;
369+
}
370+
371+
return 0;
372+
}
373+
#elif DEVICE_SPI
374+
int sfdp_detect_addressability(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info)
375+
{
376+
// Check address size, currently only supports 3byte addresses
377+
if ((bptbl_ptr[2] & 0x4) != 0 || (bptbl_ptr[7] & 0x80) != 0) {
378+
return -1;
379+
}
380+
381+
return 0;
382+
}
383+
#endif
384+
363385
} /* namespace mbed */
364386
#endif /* (DEVICE_SPI || DEVICE_QSPI) */

0 commit comments

Comments
 (0)