on 2025-05-14 2:00 AM
This tutorial is a comprehensive guide for debugging code from external serial flash on the STM32N6. It covers: setting up the environment, configuring the debugger, and validating the setup.
To debug the code running from the external serial flash on the STM32N6 effectively, set up the external memory in the memory-mapped mode. The FSBL (first stage bootloader), which runs from AXI-SRAM2, acts as the debugger entry point. It sets up the XSPI interface, turns on memory-mapped mode, and jumps to the preprogrammed external memory.
As a first step in debugging, you can place the debugger program on the external memory. This setup allows seamless execution and debugging directly from external flash.
A known limitation exists when placing a breakpoint in application code running from external memory before the FSBL execution. This is because the external memory isn’t yet configured in memory-mapped mode. It prevents the debugger from setting a breakpoint at that address. Once in debug mode, and after the FSBL function configures the external serial flash, you can enable such breakpoints.
This article assumes you have installed STM32CubeMX (6.13 or later), the latest version of the STM32N6 HAL driver, STM32CubeProgrammer (2.18 or later), and STM32CubeIDE (1.17.0 or later).
The hardware used to showcase is the STM32N6570-DK and make sure you have it in DEV boot mode to program the code:
The FSBL will be our entry point for debugging, but we must have all projects in the same workspace to have the *.elf files visible in the debugger configuration. The following steps show how to add the XIP template, which will be used to demonstrate the process. The template is located at:
C:\Users\%username%\STM32Cube\Repository\STM32Cube_FW_N6_V1.1.1\Projects\STM32N6570-DK\Templates\Template_FSBL_XIP\STM32CubeIDE
cd "${ProjDirPath}/Debug" && echo y | "C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_SigningTool_CLI.exe" -bin "${ProjName}.bin" -nk -of 0x80000000 -t fsbl -o "${ProjName}-Trusted.bin" -hv 2.3 -dump "${ProjName}-Trusted.bin"
cp "${BuildArtifactFileBaseName}.elf" "../CustomN6.stldr”
C:\Users\%username%\STM32Cube\Repository\STM32Cube_FW_N6_V1.1.1\Projects\STM32N6570-DK\Templates\Template_FSBL_XIP\STM32CubeIDE\AppS\Debug\Template_XIP_AppS-Trusted.bin
BOOT_Application
instead of the usual main
. Now, in the FSBL firmware, the XSPI has the external memory configured in memory-mapped mode:BOOT_Application
function:
TIP: you might need to power cycle the board in case of a failure message appears when clicking to enter in debug mode. Also, you'll get a failure message if an existing breakpoint is kept in between debug sessions.
An error message may occur when you enter debug mode with the external memory preprogrammed. If this happens, power cycle the board (disconnect and reconnect it to the computer). This is due to a small error in the default *.stldr provided, which will be corrected on future releases. To avoid this problem, it’s possible to add these lines in the stm32_sfdp_driver.c, function EXTMEM_DRIVER_NOR_SFDP_DeInit:
#ifdef STM32_EXTMEMLOADER_STM32CUBETARGET
memory_mapmode(DISABLE);
#endif
Rebuild the ExtMemLoader and use the CustomN6.stldr instead.
By following these steps, you can successfully debug code running from external flash on STM32N6. This tutorial offers a practical approach. It includes setting up the environment, configuring the debugger, and validating the setup.
Getting started with STM32CubeN6 for STM32N6 series - User manual
How to proceed with boot ROM on STM32N6 MCUs - User manual
Discovery kit with STM32N657X0 MCU - User manual
STM32N647/657xx Arm<Sup>®</Sup>-based 32-bit MCUs - Reference manual