Skip to content

Commit 513073b

Browse files
taltenbachkartben
authored andcommitted
drivers: flash: stm32_qspi: Fix erase size for dual-flash
When dual-flash mode is enabled, any erase operation is executed on both flash memories in parallel. This means from the flash driver's point of view, the size of a given sector/block is twice the size of a sector/block on a single flash memory. For example, assuming 4-KiB sectors for each flash memory, if the flash driver is asked to erase at address 0x0000, the erase size must be a multiple of 8 KiB since each sector erase operation will cause a 4-KiB sector to erased in each flash memory. Before this commit, the doubled erase size was only considered in 'setup_pages_layout'. Now, the actual sizes of the erase operations are properly set in the flash driver's data and are used everywhere in the driver. Signed-off-by: Thomas Altenbach <[email protected]>
1 parent 8c638f2 commit 513073b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/flash/flash_stm32_qspi.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ static int setup_pages_layout(const struct device *dev)
11921192
return -ENOTSUP;
11931193
}
11941194

1195-
uint32_t erase_size = BIT(exp) << STM32_QSPI_DOUBLE_FLASH;
1195+
uint32_t erase_size = BIT(exp);
11961196

11971197
/* We need layout page size to be compatible with erase size */
11981198
if ((layout_page_size % erase_size) != 0) {
@@ -1364,6 +1364,13 @@ static int spi_nor_process_bfp(const struct device *dev,
13641364
memset(data->erase_types, 0, sizeof(data->erase_types));
13651365
for (uint8_t ti = 1; ti <= ARRAY_SIZE(data->erase_types); ++ti) {
13661366
if (jesd216_bfp_erase(bfp, ti, etp) == 0) {
1367+
/* In dual-flash mode, the erase size is doubled since each erase operation
1368+
* is executed on both flash memories.
1369+
*/
1370+
if (IS_ENABLED(STM32_QSPI_DOUBLE_FLASH)) {
1371+
etp->exp++;
1372+
}
1373+
13671374
LOG_DBG("Erase %u with %02x",
13681375
(uint32_t)BIT(etp->exp), etp->cmd);
13691376
}

0 commit comments

Comments
 (0)