Skip to content

Commit 31bd0c2

Browse files
kshypachovaescolar
authored andcommitted
drivers: flash: stm32_ospi: fix memory mapped mode
Set the OSPI memory mapped timeout period to avoid keeping the chip select line asserted indefinitely after memory mapped accesses. This is needed when OSPI1 and OSPI2 operate simultaneously with shared IO0-IO3 and CLK lines, and both instances use memory mapped mode. The timeout period follows the recommendation from the STM32U575xx and STM32U585xx device errata, ES0499 section 2.6.4. Allow dqs-port to be set to 0. The STM32 HAL uses value 0 to indicate that the DQS port is not used. Update the debug log printed when CONFIG_STM32_MEMMAP is not enabled, because stm32_ospi_set_memorymap() is not called in that case. Signed-off-by: Kirill Shypachov <kshypachov@outlook.com>
1 parent 247a256 commit 31bd0c2

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

drivers/flash/flash_stm32_ospi.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ LOG_MODULE_REGISTER(flash_stm32_ospi, CONFIG_FLASH_LOG_LEVEL);
6767
#define STM32_OSPI_SUBSECTOR_4K_ERASE_MAX_TIME 400U
6868
#define STM32_OSPI_WRITE_REG_MAX_TIME 40U
6969

70+
/*
71+
* Flash active hold timeout. Required when using the Octal SPI interface in
72+
* pin multiplexing mode on STM32U5xx devices.
73+
*/
74+
#define STM32_OCTOSPIM_TIMEOUT 0x34
75+
7076
/* used as default value for DTS writeoc */
7177
#define SPI_NOR_WRITEOC_NONE 0xFF
7278

@@ -1112,7 +1118,12 @@ static int stm32_ospi_set_memorymap(const struct device *dev)
11121118
}
11131119

11141120
/* Enable the memory-mapping */
1121+
#if defined(CONFIG_SOC_SERIES_STM32U5X) && defined(OCTOSPIM)
1122+
s_MemMappedCfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_ENABLE;
1123+
s_MemMappedCfg.TimeOutPeriod = STM32_OCTOSPIM_TIMEOUT;
1124+
#else
11151125
s_MemMappedCfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_DISABLE;
1126+
#endif /* CONFIG_SOC_SERIES_STM32U5X && OCTOSPIM*/
11161127

11171128
ret = HAL_OSPI_MemoryMapped(&dev_data->hospi, &s_MemMappedCfg);
11181129
if (ret != HAL_OK) {
@@ -2580,9 +2591,7 @@ static int flash_stm32_ospi_init(const struct device *dev)
25802591
(long)(STM32_OSPI_BASE_ADDRESS),
25812592
dev_cfg->flash_size);
25822593
#else
2583-
LOG_DBG("NOR octo-flash at 0x%lx (0x%x bytes)",
2584-
(long)(STM32_OSPI_BASE_ADDRESS),
2585-
dev_cfg->flash_size);
2594+
LOG_DBG("Serial flash is in direct mode, not memory-mapped mode");
25862595
#endif /* CONFIG_STM32_MEMMAP */
25872596

25882597
return 0;

dts/bindings/ospi/st,stm32-ospi.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ properties:
139139
dqs-port:
140140
type: int
141141
enum:
142+
- 0
142143
- 1
143144
- 2
144145
description: |
145146
Specifies which port of the OCTOSPI IO Manager is used for the dqs pin.
146147
147148
If absent, then n is used where `n` is the OSPI
148-
instance number.
149+
instance number, 0 means signal is not used.
149150
150151
Note: You might need to enable the OCTOSPI I/O manager clock to use the
151152
property. Please refer to Reference Manual.

0 commit comments

Comments
 (0)