Skip to content

Commit 2ce3bed

Browse files
author
Veijo Pesonen
committed
SFDP: consolidates device density detection
Combines implementations found from SPIFBlockDevice and QSPIFBlockDevice and makes it as part of the SFDP module.
1 parent 1f36b1c commit 2ce3bed

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,10 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void
635635
return -1;
636636
}
637637

638-
// Get device density (stored in bits - 1)
639-
uint32_t density_bits = ((param_table[7] << 24) |
640-
(param_table[6] << 16) |
641-
(param_table[5] << 8) |
642-
param_table[4]);
643-
sfdp_info.bptbl.device_size_bytes = (density_bits + 1) / 8;
638+
if (sfdp_detect_device_density(param_table, _sfdp_info.bptbl) < 0) {
639+
tr_error("Detecting device density failed");
640+
return -1;
641+
}
644642

645643
// Set Page Size (QSPI write must be done on Page limits)
646644
_page_size_bytes = sfdp_detect_page_size(param_table, sfdp_info.bptbl.size);

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,10 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(Callback<int(bd_addr_t, void
634634
return -1;
635635
}
636636

637-
// Get device density (stored in bits - 1)
638-
uint32_t density_bits = (
639-
(param_table[7] << 24) |
640-
(param_table[6] << 16) |
641-
(param_table[5] << 8) |
642-
param_table[4]);
643-
sfdp_info.bptbl.device_size_bytes = (density_bits + 1) / 8;
644-
tr_debug("Density bits: %" PRIu32 " , device size: %llu bytes", density_bits, sfdp_info.bptbl.device_size_bytes);
637+
if (sfdp_detect_device_density(param_table, _sfdp_info.bptbl) < 0) {
638+
tr_error("Detecting device density failed");
639+
return -1;
640+
}
645641

646642
// Set Default read/program/erase Instructions
647643
_read_instruction = SPIF_READ;

drivers/internal/SFDP.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield,
141141
int region,
142142
const sfdp_smptbl_info &smptbl);
143143

144+
/** Detect device density
145+
*
146+
* @param bptbl_ptr Pointer to memory holding a Basic Parameter Table structure
147+
* @param bptbl_info Basic Parameter Table information structure
148+
*
149+
* @return 0 on success, negative error code on failure
150+
*/
151+
int sfdp_detect_device_density(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info);
152+
144153
/** @}*/
145154
} /* namespace mbed */
146155
#endif

drivers/source/SFDP.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,21 @@ int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield,
344344
return largest_erase_type;
345345
}
346346

347+
int sfdp_detect_device_density(uint8_t *bptbl_ptr, sfdp_bptbl_info &bptbl_info)
348+
{
349+
// stored in bits - 1
350+
uint32_t density_bits = (
351+
(bptbl_ptr[7] << 24) |
352+
(bptbl_ptr[6] << 16) |
353+
(bptbl_ptr[5] << 8) |
354+
bptbl_ptr[4]);
355+
356+
bptbl_info.device_size_bytes = (density_bits + 1) / 8;
357+
358+
tr_info("Density bits: %" PRIu32 " , device size: %llu bytes", density_bits, bptbl_info.device_size_bytes);
359+
360+
return 0;
361+
}
362+
347363
} /* namespace mbed */
348364
#endif /* (DEVICE_SPI || DEVICE_QSPI) */

0 commit comments

Comments
 (0)