Skip to content

Commit e9722b4

Browse files
committed
drivers: flash: stm32 xspi flash read with memcopy when executing
When the application is executed in external flash, the read operation cannot be in indirect mode but with memcopy. Note that writing or erasing the external flash being executed is not possible during the execution. Signed-off-by: Francois Ramu <[email protected]>
1 parent 20efb9e commit e9722b4

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

drivers/flash/flash_stm32_xspi.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ static int flash_stm32_xspi_erase(const struct device *dev, off_t addr,
10351035
goto erase_end;
10361036
}
10371037
}
1038-
#endif
1038+
#endif /* CONFIG_STM32_MEMMAP */
10391039

10401040
XSPI_RegularCmdTypeDef cmd_erase = {
10411041
.OperationType = HAL_XSPI_OPTYPE_COMMON_CFG,
@@ -1173,7 +1173,7 @@ static int flash_stm32_xspi_read(const struct device *dev, off_t addr,
11731173
{
11741174
const struct flash_stm32_xspi_config *dev_cfg = dev->config;
11751175
struct flash_stm32_xspi_data *dev_data = dev->data;
1176-
int ret;
1176+
int ret = 0;
11771177

11781178
if (!xspi_address_is_valid(dev, addr, size)) {
11791179
LOG_ERR("Error: address or size exceeds expected values: "
@@ -1186,29 +1186,28 @@ static int flash_stm32_xspi_read(const struct device *dev, off_t addr,
11861186
return 0;
11871187
}
11881188

1189-
#ifdef CONFIG_STM32_MEMMAP
1189+
#if defined(CONFIG_STM32_MEMMAP) || defined(CONFIG_STM32_APP_IN_EXT_FLASH)
11901190
ARG_UNUSED(dev_cfg);
11911191
ARG_UNUSED(dev_data);
1192-
1193-
xspi_lock_thread(dev);
1192+
/* When the call is made by an app executing in external flash, skip the memory-mapped mode check */
1193+
#ifdef CONFIG_STM32_MEMMAP
11941194

11951195
/* Do reads through memory-mapping instead of indirect */
11961196
if (!stm32_xspi_is_memorymap(dev)) {
11971197
ret = stm32_xspi_set_memorymap(dev);
11981198
if (ret != 0) {
11991199
LOG_ERR("READ: failed to set memory mapped");
1200-
goto read_end;
1200+
return ret;
12011201
}
12021202
}
12031203

12041204
__ASSERT_NO_MSG(stm32_xspi_is_memorymap(dev));
1205-
1205+
#endif /* CONFIG_STM32_MEMMAP */
12061206
uintptr_t mmap_addr = STM32_XSPI_BASE_ADDRESS + addr;
12071207

12081208
LOG_DBG("Memory-mapped read from 0x%08lx, len %zu", mmap_addr, size);
12091209
memcpy(data, (void *)mmap_addr, size);
1210-
ret = 0;
1211-
goto read_end;
1210+
return ret;
12121211
#else
12131212
XSPI_RegularCmdTypeDef cmd = xspi_prepare_cmd(dev_cfg->data_mode, dev_cfg->data_rate);
12141213

@@ -1274,13 +1273,10 @@ static int flash_stm32_xspi_read(const struct device *dev, off_t addr,
12741273
xspi_lock_thread(dev);
12751274

12761275
ret = xspi_read_access(dev, &cmd, data, size);
1277-
goto read_end;
1278-
#endif
1279-
1280-
read_end:
12811276
xspi_unlock_thread(dev);
12821277

12831278
return ret;
1279+
#endif /* CONFIG_STM32_MEMMAP || CONFIG_STM32_APP_IN_EXT_FLASH */
12841280
}
12851281

12861282
/* Function to write the flash (page program) : with possible OCTO/SPI and STR/DTR */

0 commit comments

Comments
 (0)