2025-06-10 10:27 AM
Hello everyone,
I’m working on an STM32H7S3L8H6H with two XSPI interfaces:
In my bootloader I configure both and start the external memory manager:
MX_XSPI1_Init();
MX_XSPI2_Init();
MX_EXTMEM_MANAGER_Init();
This maps the flash at 0x7000_0000 and the PSRAM at 0x9000_0000. After jumping to main() in the application (which is executing from the XSPI2 flash), I’ve marked XSPI1 as “Runtime Context” in CubeMX and still call:
MX_XSPI1_Init();
But it hangs here:
// inside MX_XSPI1_Init():
if (HAL_XSPIM_Config(&hxspi1, &sXspiManagerCfg, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
Error_Handler(); // stops here
}
I have validated each interface separately, XSPI2 boots and runs code, and XSPI1 handles PSRAM reads/writes without issue. So now, how can I access and use the PSRAM from within the application (which is itself executing from the external flash) ?
Any pointers, configuration tips or code snippets would be greatly appreciated. Thank you!
Solved! Go to Solution.
2025-06-30 2:10 AM
Hello @andgarriv ?
Your configuration appears to be correct.
To safeguard all the modifications you made to the MX_XSPI1_Init()
function, please place your custom code inside the designated USER CODE sections. These sections are reserved areas in the code where user modifications are protected from being overwritten when the code is regenerated. Additionally, any initializations related to this function should also be included in these USER CODE sections to ensure their preservation.
Furthermore, in CubeMX, navigate to the Project Manager tab, then to Advanced Settings, and uncheck the automatic regeneration of the MX_XSPI1_Init()
function. This will prevent the tool from overwriting your manual changes each time the code is regenerated.
Kr,
2025-06-11 1:30 AM
Hello @andgarriv;
Could you please check the XSPI1 configuration?
Is the memory interface running with the maximum speed 200 MHz and with VDD<2.7V?
If yes, make sure that HSLV is enabled.
I recommend you to look at Recommendations for high-speed low-voltage mode (HSLV) on the STM32H7RS.
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-06-11 2:15 AM
Hello Kaouthar,
XSPI1 is working correctly in the boot code, and in both codebases it’s initialized with the same configuration. It’s running at 50 MHz (200 Mhz without prescaler), VDD = 1.8 V, and HSLV mode is enabled.
Let me know if you need anything else!
2025-06-16 3:30 AM - edited 2025-06-16 7:12 AM
Hello @andgarriv ,
Could you please share your MX_XSPI1_Init() and MX_XSPI2_Init() configurations ?
Please, ensure that each XSPI is mapped independently to its corresponding port (e.g., XSPI1 to Port 1 and XSPI2 to Port 2)
Kind regards,
2025-06-27 5:44 AM
Hi @NesrynELMK,
I was able to make it work, but I had to significantly simplify the MX_XSPI1_Init() function in order for the RAM (XSPI1) to initialize properly during application startup.
Here is the reduced version I’m using:
static void MX_XSPI1_Init(void)
{
hxspi1.Instance = XSPI1;
hxspi1.Init.FifoThresholdByte = 1;
hxspi1.Init.MemoryMode = HAL_XSPI_SINGLE_MEM;
hxspi1.Init.MemoryType = HAL_XSPI_MEMTYPE_APMEM;
hxspi1.Init.MemorySize = HAL_XSPI_SIZE_64MB;
hxspi1.Init.ChipSelectHighTimeCycle = 1;
hxspi1.Init.FreeRunningClock = HAL_XSPI_FREERUNCLK_DISABLE;
hxspi1.Init.ClockMode = HAL_XSPI_CLOCK_MODE_0;
hxspi1.Init.WrapSize = HAL_XSPI_WRAP_NOT_SUPPORTED;
hxspi1.Init.ClockPrescaler = 0;
hxspi1.Init.SampleShifting = HAL_XSPI_SAMPLE_SHIFT_NONE;
hxspi1.Init.DelayHoldQuarterCycle = HAL_XSPI_DHQC_DISABLE;
hxspi1.Init.ChipSelectBoundary = HAL_XSPI_BONDARYOF_NONE;
hxspi1.Init.MaxTran = 0;
hxspi1.Init.Refresh = 0;
hxspi1.Init.MemorySelect = HAL_XSPI_CSSEL_NCS1;
if (HAL_XSPI_Init(&hxspi1) != HAL_OK)
{
Error_Handler();
}
}
Most of the extra logic generated by CubeMX was causing issues, so I had to remove it manually. However, this makes it tedious since I need to re-edit the function every time I regenerate code from STM32CubeMX. Full generated function is on Boot code.
If there's a way to keep a custom MX_XSPI1_Init() while still using code generation, or to configure CubeMX to only generate the minimal init, that would be very helpful.
Let me know if you’ve found a cleaner workaround.
Best regards,
Andrés
2025-06-30 2:10 AM
Hello @andgarriv ?
Your configuration appears to be correct.
To safeguard all the modifications you made to the MX_XSPI1_Init()
function, please place your custom code inside the designated USER CODE sections. These sections are reserved areas in the code where user modifications are protected from being overwritten when the code is regenerated. Additionally, any initializations related to this function should also be included in these USER CODE sections to ensure their preservation.
Furthermore, in CubeMX, navigate to the Project Manager tab, then to Advanced Settings, and uncheck the automatic regeneration of the MX_XSPI1_Init()
function. This will prevent the tool from overwriting your manual changes each time the code is regenerated.
Kr,