From 302983fd7d20b85f1736f96e0d0705e1a3d76a5c Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Fri, 6 Jan 2023 13:40:29 +0100 Subject: [PATCH] drivers: flash: stm32 qspi driver correct device size The find_lsb_set is giving the position of the first '1' found, starting from 1. "Bits are numbered starting at 1 from the least significant bit." So that the find_lsb_set(64MBytes) is 27. The HAL_QSPI_Init() accepts Init.FlashSize where "FlashSize+1 is effectively the number of address bits required to address the flash memory." To get 64MBytes = 2^26, the value of the Init.FlashSize must be 25. and bit written to the DCR = 25. Signed-off-by: Francois Ramu --- drivers/flash/flash_stm32_qspi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/flash/flash_stm32_qspi.c b/drivers/flash/flash_stm32_qspi.c index a14dbe17a7c..123829f89d5 100644 --- a/drivers/flash/flash_stm32_qspi.c +++ b/drivers/flash/flash_stm32_qspi.c @@ -1189,7 +1189,8 @@ static int flash_stm32_qspi_init(const struct device *dev) __ASSERT_NO_MSG(prescaler <= STM32_QSPI_CLOCK_PRESCALER_MAX); /* Initialize QSPI HAL */ dev_data->hqspi.Init.ClockPrescaler = prescaler; - dev_data->hqspi.Init.FlashSize = find_lsb_set(dev_cfg->flash_size); + /* Give a bit position from 0 to 31 to the HAL init minus 1 for the DCR1 reg */ + dev_data->hqspi.Init.FlashSize = find_lsb_set(dev_cfg->flash_size) - 2; HAL_QSPI_Init(&dev_data->hqspi);