2025-10-09 11:44 AM
Hello superhero MCU enthusiasts,
I'm playing with the STM32N6570-DK and have created a simple project with an FSBL that initializes the MCU and boots the Appl. Once booted, the Appl flashes a "Hello World" LED.
Both can be loaded to external flash using the STM32CubeProgrammer.
Now, I'm trying to map external PSRAM (XSPI1 -> 0x90000000) inside the FSBL, but it fails.
To do that, I change a line in a file in the FSBL, stm32_extmem_conf.h, line 35 of (PSRAM disabled):
#define EXTMEM_DRIVER_PSRAM 0
Now I try to enable and map the external PSRAM by setting the definition to 1:
#define EXTMEM_DRIVER_PSRAM 1
However, it doesn't succeed.
When debugging I see we land into a HardFault.
The FSBL generates a HardFault when executing SAL_XSPI_EnableMapMode, because the function HAL_XSPI_MemoryMapped fails.
I can't find the cause.
Anyone?
I posted a project here with a short Readme.md:
https://github.com/AngryCarrot61/STM32N6570-DK_004
Note: to see FSBL and Appl working one has to set EXTMEM_DRIVER_PSRAM to 0.
However the goal is to get PSRAM mapped (XSPI1 at 0x90000000).
Flashing:
the debug directories for FSBL and Appl contain a batch file: '0_SigningTool.bat'.
After compiling, run the batch files to sign the binaries.
Using STM32CubeProgrammer we select EL 'MX66UW1G45G_STM32N6570-DK'.
FSBL will be loaded at 0x70000000, and Appl at 0x70100000.
Enjoy!
Any help is much apreciated regarding the part to map the PSRAM!
Cheers!
2025-10-09 12:05 PM
The FSBL is crashing at HAL_XSPI_MemoryMapped() because:
The PSRAM isn’t properly initialized before entering memory-mapped mode.
The stm32_extmem_conf.c shipped with the BSP assumes OctoSPI NOR Flash by default.
The PSRAM device (like AP Memory APS256XXN used on the DK board) requires different initialization commands and timings.
So when you set
the FSBL tries to map it, but the init structure for XSPI1 doesn’t match the PSRAM’s protocol → invalid command sequence → bus fault → HardFault.
The working fix:
You need to modify the external memory configuration used by FSBL to correctly initialize the PSRAM.
Leave:
Locate the function that initializes external memory (usually something like EXTMEM_Init() or EXTMEM_InitPSRAM()).
Replace the PSRAM init with this correct configuration for the DK’s AP Memory PSRAM (OctoSPI1 → XSPI1):
Then call PSRAM_Init() during your FSBL init sequence before jumping to the Application.
MPU setup (critical):
Ensure the FSBL enables MPU access for the PSRAM region before mapping it:
Without this, you’ll get a HardFault as soon as code or DMA touches 0x90000000.
verification
After boot:
If you apply those three key fixes (correct MemoryType, DTR mode, MPU region), HAL_XSPI_MemoryMapped() will succeed and the FSBL will no longer HardFault.
Would you like me to adapt this into a ready-to-paste STM32CubeIDE code snippet (with includes + call sequence for FSBL main.c)?