Skip to content

Commit cee9123

Browse files
drivers: memc: stm32_xspi_psram: Add conditional HAL API support
Add conditional compilation to support different STM32 XSPI HAL capabilities across product lines: - Use XSPIM (XSPI Manager) configuration when available (STM32H7RS) - Use 16-line data mode on STM32H7RS, 8-line on STM32H5 - Include MaxTran and MemorySelect Init fields only when XSPIM exists This allows the driver to automatically use full hardware capabilities on STM32H7RS (16-line XSPI with dual-port manager) while maintaining compatibility with STM32H5 series that have simpler single-port XSPI/OCTOSPI implementation with 8-line max. Related to zephyrproject-rtos/hal_stm32#328 Signed-off-by: Ayush Kothari <ayushkot96@gmail.com>
1 parent 9c1fbc8 commit cee9123

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/memc/memc_stm32_xspi_psram.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ static int memc_stm32_xspi_psram_init(const struct device *dev)
217217
struct memc_stm32_xspi_psram_data *dev_data = dev->data;
218218
XSPI_HandleTypeDef *hxspi = &dev_data->hxspi;
219219
uint32_t ahb_clock_freq;
220+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
221+
XSPIM_CfgTypeDef cfg = {0};
222+
#endif
220223
XSPI_RegularCmdTypeDef cmd = {0};
221224
XSPI_MemoryMappedTypeDef mem_mapped_cfg = {0};
222225
uint32_t prescaler = STM32_XSPI_CLOCK_PRESCALER_MIN;
@@ -294,13 +297,12 @@ static int memc_stm32_xspi_psram_init(const struct device *dev)
294297
return -EIO;
295298
}
296299

300+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
297301
if (!IS_ENABLED(CONFIG_STM32_APP_IN_EXT_FLASH)) {
298302
/*
299303
* Do not configure the XSPIManager if running on the ext flash
300304
* since this includes stopping each XSPI instance during configuration
301305
*/
302-
XSPIM_CfgTypeDef cfg = {0};
303-
304306
if (hxspi->Instance == XSPI1) {
305307
cfg.IOPort = HAL_XSPIM_IOPORT_1;
306308
} else if (hxspi->Instance == XSPI2) {
@@ -309,10 +311,11 @@ static int memc_stm32_xspi_psram_init(const struct device *dev)
309311
cfg.nCSOverride = HAL_XSPI_CSSEL_OVR_DISABLED;
310312

311313
if (HAL_XSPIM_Config(hxspi, &cfg, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
312-
LOG_ERR("XSPIMgr Init failed");
314+
LOG_ERR("XSPI Manager config failed");
313315
return -EIO;
314316
}
315317
}
318+
#endif
316319

317320
/* Configure AP memory registers */
318321
ret = ap_memory_configure(hxspi);
@@ -334,8 +337,14 @@ static int memc_stm32_xspi_psram_init(const struct device *dev)
334337
cmd.AddressMode = HAL_XSPI_ADDRESS_8_LINES;
335338
cmd.AddressWidth = HAL_XSPI_ADDRESS_32_BITS;
336339
cmd.AddressDTRMode = HAL_XSPI_ADDRESS_DTR_ENABLE;
340+
#if defined(HAL_XSPI_DATA_16_LINES)
341+
/* Use 16-line if DT requests and hardware supports it */
337342
cmd.DataMode = DT_INST_PROP(0, io_x16_mode) ? HAL_XSPI_DATA_16_LINES
338343
: HAL_XSPI_DATA_8_LINES;
344+
#else
345+
/* STM32H5 max is 8 lines */
346+
cmd.DataMode = HAL_XSPI_DATA_8_LINES;
347+
#endif
339348
cmd.DataDTRMode = HAL_XSPI_DATA_DTR_ENABLE;
340349
cmd.DummyCycles = DUMMY_CLK_CYCLES_WRITE;
341350
cmd.DQSMode = HAL_XSPI_DQS_ENABLE;
@@ -412,9 +421,13 @@ static struct memc_stm32_xspi_psram_data memc_stm32_xspi_data = {
412421
.SampleShifting = HAL_XSPI_SAMPLE_SHIFT_NONE,
413422
.DelayHoldQuarterCycle = HAL_XSPI_DHQC_ENABLE,
414423
.ChipSelectBoundary = DT_INST_PROP(0, st_csbound),
415-
.MaxTran = 0U,
424+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
425+
.MaxTran = 0U, /* Communication regulation (STM32H7RS only) */
426+
#endif
416427
.Refresh = 0x81U,
417-
.MemorySelect = HAL_XSPI_CSSEL_NCS1,
428+
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
429+
.MemorySelect = HAL_XSPI_CSSEL_NCS1, /* Chip select (STM32H7RS only) */
430+
#endif
418431
},
419432
},
420433
};

0 commit comments

Comments
 (0)