Commit 2345bc99 authored by Francois Ramu's avatar Francois Ramu Committed by Alberto Escolar
Browse files

drivers: flash: stm32 xspi flash driver skip init when executing in place



The flash_stm32_xspi driver should not initialize the xspi,
if this one is being use to execute in Place : the init is skipped.
This mode is identified with the CONFIG_STM32_APP_IN_EXT_FLASH.
Checking the memory mapped mode bit is possible when the xspi
peripheral clock is not off (stm32h5 has no clock_control_get_status API)

Signed-off-by: default avatarFrancois Ramu <francois.ramu@st.com>
parent c33d93d4
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -966,16 +966,6 @@ static int stm32_xspi_set_memorymap(const struct device *dev)
	return 0;
}

/* Function to return true if the octoflash is in MemoryMapped else false */
static bool stm32_xspi_is_memorymap(const struct device *dev)
{
	struct flash_stm32_xspi_data *dev_data = dev->data;

	return ((READ_BIT(dev_data->hxspi.Instance->CR,
			  XSPI_CR_FMODE) == XSPI_CR_FMODE) ?
			  true : false);
}

static int stm32_xspi_abort(const struct device *dev)
{
	struct flash_stm32_xspi_data *dev_data = dev->data;
@@ -989,6 +979,17 @@ static int stm32_xspi_abort(const struct device *dev)
}
#endif /* CONFIG_STM32_MEMMAP */


#if defined(CONFIG_STM32_MEMMAP) || defined(CONFIG_STM32_APP_IN_EXT_FLASH)
/* Function to return true if the octoflash is in MemoryMapped else false */
static bool stm32_xspi_is_memorymap(const struct device *dev)
{
	struct flash_stm32_xspi_data *dev_data = dev->data;

	return READ_BIT(dev_data->hxspi.Instance->CR, XSPI_CR_FMODE) == XSPI_CR_FMODE;
}
#endif

/*
 * Function to erase the flash : chip or sector with possible OCTO/SPI and STR/DTR
 * to erase the complete chip (using dedicated command) :
@@ -2047,7 +2048,7 @@ static int flash_stm32_xspi_init(const struct device *dev)
		return -ENODEV;
	}

#ifdef CONFIG_STM32_MEMMAP
#ifdef CONFIG_STM32_APP_IN_EXT_FLASH
	/* If MemoryMapped then configure skip init
	 * Check clock status first as reading CR register without bus clock doesn't work on N6
	 * If clock is off, then MemoryMapped is off too and we do init
@@ -2056,13 +2057,13 @@ static int flash_stm32_xspi_init(const struct device *dev)
				     (clock_control_subsys_t) &dev_cfg->pclken)
				     == CLOCK_CONTROL_STATUS_ON) {
		if (stm32_xspi_is_memorymap(dev)) {
			LOG_ERR("NOR init'd in MemMapped mode");
			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 */
#endif /* CONFIG_STM32_APP_IN_EXT_FLASH */

	/* 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)