Skip to content

Commit a5f9793

Browse files
gautierg-stkartben
authored andcommitted
drivers: flash: stm32 xspi: add memmap support for n6
Add memory-mapped support for STM32N6 XSPI Flash driver. Signed-off-by: Guillaume Gautier <[email protected]>
1 parent f69fcdf commit a5f9793

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

drivers/flash/flash_stm32_xspi.c

+28-7
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,13 @@ static int stm32_xspi_config_mem(const struct device *dev)
743743
return -EIO;
744744
}
745745

746+
if (stm32_xspi_read_cfg2reg(&dev_data->hxspi,
747+
XSPI_OCTO_MODE, XSPI_DTR_TRANSFER, reg) != 0) {
748+
/* Check the configuration has been correctly done on SPI_NOR_REG2_ADDR1 */
749+
LOG_ERR("XSPI flash config read failed");
750+
return -EIO;
751+
}
752+
746753
LOG_INF("XSPI flash config is OCTO / DTR");
747754
}
748755

@@ -846,7 +853,7 @@ static int stm32_xspi_set_memorymap(const struct device *dev)
846853
const struct flash_stm32_xspi_config *dev_cfg = dev->config;
847854
struct flash_stm32_xspi_data *dev_data = dev->data;
848855
XSPI_RegularCmdTypeDef s_command = {0}; /* Non-zero values disturb the command */
849-
XSPI_MemoryMappedTypeDef s_MemMappedCfg;
856+
XSPI_MemoryMappedTypeDef s_MemMappedCfg = {0};
850857

851858
/* Configure octoflash in MemoryMapped mode */
852859
if ((dev_cfg->data_mode == XSPI_SPI_MODE) &&
@@ -939,6 +946,13 @@ static int stm32_xspi_set_memorymap(const struct device *dev)
939946
/* Enable the memory-mapping */
940947
s_MemMappedCfg.TimeOutActivation = HAL_XSPI_TIMEOUT_COUNTER_DISABLE;
941948

949+
#ifdef XSPI_CR_NOPREF
950+
s_MemMappedCfg.NoPrefetchData = HAL_XSPI_AUTOMATIC_PREFETCH_ENABLE;
951+
#ifdef XSPI_CR_NOPREF_AXI
952+
s_MemMappedCfg.NoPrefetchAXI = HAL_XSPI_AXI_PREFETCH_DISABLE;
953+
#endif /* XSPI_CR_NOPREF_AXI */
954+
#endif /* XSPI_CR_NOPREF */
955+
942956
ret = HAL_XSPI_MemoryMapped(&dev_data->hxspi, &s_MemMappedCfg);
943957
if (ret != HAL_OK) {
944958
LOG_ERR("%d: Failed to enable memory mapped", ret);
@@ -2031,12 +2045,19 @@ static int flash_stm32_xspi_init(const struct device *dev)
20312045
}
20322046

20332047
#ifdef CONFIG_STM32_MEMMAP
2034-
/* If MemoryMapped then configure skip init */
2035-
if (stm32_xspi_is_memorymap(dev)) {
2036-
LOG_DBG("NOR init'd in MemMapped mode");
2037-
/* Force HAL instance in correct state */
2038-
dev_data->hxspi.State = HAL_XSPI_STATE_BUSY_MEM_MAPPED;
2039-
return 0;
2048+
/* If MemoryMapped then configure skip init
2049+
* Check clock status first as reading CR register without bus clock doesn't work on N6
2050+
* If clock is off, then MemoryMapped is off too and we do init
2051+
*/
2052+
if (clock_control_get_status(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
2053+
(clock_control_subsys_t) &dev_cfg->pclken[0])
2054+
== CLOCK_CONTROL_STATUS_ON) {
2055+
if (stm32_xspi_is_memorymap(dev)) {
2056+
LOG_ERR("NOR init'd in MemMapped mode");
2057+
/* Force HAL instance in correct state */
2058+
dev_data->hxspi.State = HAL_XSPI_STATE_BUSY_MEM_MAPPED;
2059+
return 0;
2060+
}
20402061
}
20412062
#endif /* CONFIG_STM32_MEMMAP */
20422063

0 commit comments

Comments
 (0)