Skip to content

Commit 8c638f2

Browse files
taltenbachkartben
authored andcommitted
drivers: flash: stm32_qspi: Fix page size for dual-flash
When dual-flash mode is enabled, even bytes are written to the first flash memory and odd bytes to the second flash memory. This means, from the flash driver's point of view, the size of a flash page is twice the size of a single flash memory's page. So if each flash memory has 256-byte pages, 512 bytes should be used as page size by the flash driver. Using 256 bytes was working fine but is suboptimal. Signed-off-by: Thomas Altenbach <[email protected]>
1 parent c4afaaa commit 8c638f2

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/flash/flash_stm32_qspi.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ static int flash_stm32_qspi_write(const struct device *dev, off_t addr,
763763
const void *data, size_t size)
764764
{
765765
int ret = 0;
766+
size_t page_size = SPI_NOR_PAGE_SIZE << STM32_QSPI_DOUBLE_FLASH;
766767

767768
if (!qspi_address_is_valid(dev, addr, size)) {
768769
LOG_DBG("Error: address or size exceeds expected values: "
@@ -807,15 +808,13 @@ static int flash_stm32_qspi_write(const struct device *dev, off_t addr,
807808
size_t to_write = size;
808809

809810
/* Don't write more than a page. */
810-
if (to_write >= SPI_NOR_PAGE_SIZE) {
811-
to_write = SPI_NOR_PAGE_SIZE;
811+
if (to_write >= page_size) {
812+
to_write = page_size;
812813
}
813814

814815
/* Don't write across a page boundary */
815-
if (((addr + to_write - 1U) / SPI_NOR_PAGE_SIZE)
816-
!= (addr / SPI_NOR_PAGE_SIZE)) {
817-
to_write = SPI_NOR_PAGE_SIZE -
818-
(addr % SPI_NOR_PAGE_SIZE);
816+
if (((addr + to_write - 1U) / page_size) != (addr / page_size)) {
817+
to_write = page_size - (addr % page_size);
819818
}
820819

821820
ret = qspi_send_cmd(dev, &cmd_write_en);
@@ -1371,7 +1370,7 @@ static int spi_nor_process_bfp(const struct device *dev,
13711370
++etp;
13721371
}
13731372

1374-
data->page_size = jesd216_bfp_page_size(php, bfp);
1373+
data->page_size = jesd216_bfp_page_size(php, bfp) << STM32_QSPI_DOUBLE_FLASH;
13751374

13761375
LOG_DBG("Page size %u bytes", data->page_size);
13771376
LOG_DBG("Flash size %u bytes", flash_size);

0 commit comments

Comments
 (0)