From 12b8ebee4de31b72e1cae9c70f8fc75292c5cafb Mon Sep 17 00:00:00 2001 From: Georgij Cernysiov Date: Tue, 26 Nov 2024 21:49:26 +0100 Subject: [PATCH 1/2] drivers: flash: stm32 ospi: early init exit for memmap mode Exit the init earlier when OSPI is in memory map mode. Avoid unnecessary checks and prevent pin reconfiguration that might cause line spikes. Clock check beforehand is preserved. Remove '\n' from the LOG_DBG string. Signed-off-by: Georgij Cernysiov --- drivers/flash/flash_stm32_ospi.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/flash/flash_stm32_ospi.c b/drivers/flash/flash_stm32_ospi.c index 1057ee56635f01..0f0453d967f2fc 100644 --- a/drivers/flash/flash_stm32_ospi.c +++ b/drivers/flash/flash_stm32_ospi.c @@ -2103,6 +2103,21 @@ static int flash_stm32_ospi_init(const struct device *dev) uint32_t prescaler = STM32_OSPI_CLOCK_PRESCALER_MIN; int ret; + if (!device_is_ready(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE))) { + LOG_ERR("clock control device not ready"); + return -ENODEV; + } + +#ifdef CONFIG_STM32_MEMMAP + /* If MemoryMapped then configure skip init */ + if (stm32_ospi_is_memorymap(dev)) { + LOG_DBG("NOR init'd in MemMapped mode"); + /* Force HAL instance in correct state */ + dev_data->hospi.State = HAL_OSPI_STATE_BUSY_MEM_MAPPED; + return 0; + } +#endif /* CONFIG_STM32_MEMMAP */ + /* The SPI/DTR is not a valid config of data_mode/data_rate according to the DTS */ if ((dev_cfg->data_mode != OSPI_OPI_MODE) && (dev_cfg->data_rate == OSPI_DTR_TRANSFER)) { @@ -2118,21 +2133,6 @@ static int flash_stm32_ospi_init(const struct device *dev) return ret; } - if (!device_is_ready(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE))) { - LOG_ERR("clock control device not ready"); - return -ENODEV; - } - -#ifdef CONFIG_STM32_MEMMAP - /* If MemoryMapped then configure skip init */ - if (stm32_ospi_is_memorymap(dev)) { - LOG_DBG("NOR init'd in MemMapped mode\n"); - /* Force HAL instance in correct state */ - dev_data->hospi.State = HAL_OSPI_STATE_BUSY_MEM_MAPPED; - return 0; - } -#endif /* CONFIG_STM32_MEMMAP */ - #if STM32_OSPI_USE_DMA /* * DMA configuration From 7d21dfb095d4c2b7444fe10c8e99a5741fec08b1 Mon Sep 17 00:00:00 2001 From: Georgij Cernysiov Date: Wed, 27 Nov 2024 12:50:22 +0100 Subject: [PATCH 2/2] drivers: flash: stm32 xspi: early init exit for memmap mode Exit the init earlier when XSPI is in memory map mode. Avoid unnecessary checks and prevent pin reconfiguration that might cause line spikes. Clock check beforehand is preserved. Remove '\n' from the LOG_DBG string. Signed-off-by: Georgij Cernysiov --- drivers/flash/flash_stm32_xspi.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/flash/flash_stm32_xspi.c b/drivers/flash/flash_stm32_xspi.c index 2eeef514393a6e..81d6f21eb64879 100644 --- a/drivers/flash/flash_stm32_xspi.c +++ b/drivers/flash/flash_stm32_xspi.c @@ -2019,6 +2019,21 @@ static int flash_stm32_xspi_init(const struct device *dev) uint32_t prescaler = STM32_XSPI_CLOCK_PRESCALER_MIN; int ret; + if (!device_is_ready(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE))) { + LOG_ERR("clock control device not ready"); + return -ENODEV; + } + +#ifdef CONFIG_STM32_MEMMAP + /* If MemoryMapped then configure skip init */ + if (stm32_xspi_is_memorymap(dev)) { + LOG_DBG("NOR init'd in MemMapped mode"); + /* Force HAL instance in correct state */ + dev_data->hxspi.State = HAL_XSPI_STATE_BUSY_MEM_MAPPED; + return 0; + } +#endif /* CONFIG_STM32_MEMMAP */ + /* The SPI/DTR is not a valid config of data_mode/data_rate according to the DTS */ if ((dev_cfg->data_mode != XSPI_OCTO_MODE) && (dev_cfg->data_rate == XSPI_DTR_TRANSFER)) { @@ -2034,21 +2049,6 @@ static int flash_stm32_xspi_init(const struct device *dev) return ret; } - if (!device_is_ready(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE))) { - LOG_ERR("clock control device not ready"); - return -ENODEV; - } - -#ifdef CONFIG_STM32_MEMMAP - /* If MemoryMapped then configure skip init */ - if (stm32_xspi_is_memorymap(dev)) { - LOG_DBG("NOR init'd in MemMapped mode\n"); - /* Force HAL instance in correct state */ - dev_data->hxspi.State = HAL_XSPI_STATE_BUSY_MEM_MAPPED; - return 0; - } -#endif /* CONFIG_STM32_MEMMAP */ - if (dev_cfg->pclk_len > 3) { /* Max 3 domain clock are expected */ LOG_ERR("Could not select %d XSPI domain clock", dev_cfg->pclk_len);