Skip to content

Commit 96648b2

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 96648b2

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

drivers/flash/flash_stm32_xspi.c

Lines changed: 12 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,31 @@ 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+
/*
1193+
* When the call is made by an app executing in external flash,
1194+
* skip the memory-mapped mode check
1195+
*/
1196+
#ifdef CONFIG_STM32_MEMMAP
11941197

11951198
/* Do reads through memory-mapping instead of indirect */
11961199
if (!stm32_xspi_is_memorymap(dev)) {
11971200
ret = stm32_xspi_set_memorymap(dev);
11981201
if (ret != 0) {
11991202
LOG_ERR("READ: failed to set memory mapped");
1200-
goto read_end;
1203+
return ret;
12011204
}
12021205
}
12031206

12041207
__ASSERT_NO_MSG(stm32_xspi_is_memorymap(dev));
1205-
1208+
#endif /* CONFIG_STM32_MEMMAP */
12061209
uintptr_t mmap_addr = STM32_XSPI_BASE_ADDRESS + addr;
12071210

12081211
LOG_DBG("Memory-mapped read from 0x%08lx, len %zu", mmap_addr, size);
12091212
memcpy(data, (void *)mmap_addr, size);
1210-
ret = 0;
1211-
goto read_end;
1213+
return ret;
12121214
#else
12131215
XSPI_RegularCmdTypeDef cmd = xspi_prepare_cmd(dev_cfg->data_mode, dev_cfg->data_rate);
12141216

@@ -1274,13 +1276,10 @@ static int flash_stm32_xspi_read(const struct device *dev, off_t addr,
12741276
xspi_lock_thread(dev);
12751277

12761278
ret = xspi_read_access(dev, &cmd, data, size);
1277-
goto read_end;
1278-
#endif
1279-
1280-
read_end:
12811279
xspi_unlock_thread(dev);
12821280

12831281
return ret;
1282+
#endif /* CONFIG_STM32_MEMMAP || CONFIG_STM32_APP_IN_EXT_FLASH */
12841283
}
12851284

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

0 commit comments

Comments
 (0)