drivers: flash: stm32 qspi driver in Dual Flash Mode when MemoryMapped

Configure the quad-spi in DualFlash Mode when enabling the MemoryMapped
then reading is possible with memcopy.
DUAL flash mode is possible on stm32 series with QUADSPI_CR_DFM

Signed-off-by: Francois Ramu <francois.ramu@st.com>
This commit is contained in:
Francois Ramu 2024-02-01 10:16:10 +01:00 committed by David Leach
commit f6a9e0aef2

View file

@ -35,7 +35,7 @@
#define STM32_QSPI_BASE_ADDRESS DT_INST_REG_ADDR(0)
#define STM32_QSPI_RESET_GPIO DT_INST_NODE_HAS_PROP(0, reset_gpios)
#define STM32_QSPI_RESET_CMD DT_INST_NODE_HAS_PROP(0, reset_cmd)
#define STM32_QSPI_RESET_CMD DT_PROP(DT_NODELABEL(quadspi), set_cmd)
#include <stm32_ll_dma.h>
@ -1392,6 +1392,19 @@ static int flash_stm32_qspi_init(const struct device *dev)
dev_data->hqspi.Init.ClockPrescaler = prescaler;
/* 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;
#if DT_PROP(DT_NODELABEL(quadspi), dual_flash) && defined(QUADSPI_CR_DFM)
/*
* When the DTS has <dual-flash>, it means Dual Flash Mode
* Even in DUAL flash config, the SDFP is read from one single quad-NOR
* else the magic nb is wrong (0x46465353)
* That means that the Dual Flash config is set after the SFDP sequence
*/
dev_data->hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
dev_data->hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_3_CYCLE;
dev_data->hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
/* Set Dual Flash Mode only on MemoryMapped */
dev_data->hqspi.Init.FlashID = QSPI_FLASH_ID_1;
#endif /* dual_flash */
HAL_QSPI_Init(&dev_data->hqspi);
@ -1485,6 +1498,16 @@ static int flash_stm32_qspi_init(const struct device *dev)
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
#ifdef CONFIG_STM32_MEMMAP
#if DT_PROP(DT_NODELABEL(quadspi), dual_flash) && defined(QUADSPI_CR_DFM)
/*
* When the DTS has dual_flash, it means Dual Flash Mode for Memory MAPPED
* Force Dual Flash mode now, after the SFDP sequence which is reading
* one quad-NOR only
*/
MODIFY_REG(dev_data->hqspi.Instance->CR, (QUADSPI_CR_DFM), QSPI_DUALFLASH_ENABLE);
LOG_DBG("Dual Flash Mode");
#endif /* dual_flash */
ret = stm32_qspi_set_memory_mapped(dev);
if (ret != 0) {
LOG_ERR("Failed to enable memory-mapped mode: %d", ret);