From fe05606630f8b2f61cdfd93569e67334171d6791 Mon Sep 17 00:00:00 2001 From: Guillaume Gautier Date: Tue, 11 Jun 2024 11:04:33 +0200 Subject: [PATCH] drivers: flash: select ncs line for stm32 xspi Add support to select the nCS line for XSPI from the device tree. Disable the nCS override. This setting only works with series that have an XSPIM (so not H5) Signed-off-by: Guillaume Gautier --- drivers/flash/flash_stm32_xspi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/flash/flash_stm32_xspi.c b/drivers/flash/flash_stm32_xspi.c index ae7cbb6862b3c9..c99bf7b2793958 100644 --- a/drivers/flash/flash_stm32_xspi.c +++ b/drivers/flash/flash_stm32_xspi.c @@ -1940,12 +1940,11 @@ static int flash_stm32_xspi_init(const struct device *dev) if (dev_data->hxspi.Instance == XSPI1) { xspi_mgr_cfg.IOPort = HAL_XSPIM_IOPORT_1; - xspi_mgr_cfg.nCSOverride = HAL_XSPI_CSSEL_OVR_NCS1; } else if (dev_data->hxspi.Instance == XSPI2) { - ospi_mgr_cfg.IOPort = HAL_XSPIM_IOPORT_2; - ospi_mgr_cfg.nCSOverride = HAL_XSPI_CSSEL_OVR_NCS2; + xspi_mgr_cfg.IOPort = HAL_XSPIM_IOPORT_2; } - ospi_mgr_cfg.Req2AckTime = 1; + xspi_mgr_cfg.nCSOverride = HAL_XSPI_CSSEL_OVR_DISABLED; + xspi_mgr_cfg.Req2AckTime = 1; if (HAL_XSPIM_Config(&dev_data->hxspi, &xspi_mgr_cfg, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) { @@ -2221,6 +2220,11 @@ static struct flash_stm32_xspi_data flash_stm32_xspi_dev_data = { .ClockMode = HAL_XSPI_CLOCK_MODE_0, .ChipSelectBoundary = 0, .MemoryMode = HAL_XSPI_SINGLE_MEM, +#if defined(HAL_XSPIM_IOPORT_1) || defined(HAL_XSPIM_IOPORT_2) + .MemorySelect = ((DT_INST_PROP(0, ncs_line) == 1) + ? HAL_XSPI_CSSEL_NCS1 + : HAL_XSPI_CSSEL_NCS2), +#endif .FreeRunningClock = HAL_XSPI_FREERUNCLK_DISABLE, #if defined(OCTOSPI_DCR4_REFRESH) .Refresh = 0,