cancel
Showing results for 
Search instead for 
Did you mean: 

How to debug STM32N6 using STM32CubeIDE

B.Montanari
ST Employee

Summary

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.

Introduction

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.

1. Software setup

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).

2. Hardware setup

The hardware used to showcase is the STM32N6570-DK and make sure you have it in DEV boot mode to program the code:

BMontanari_0-1746721362224.png


3. Debug instructions

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


3.1 Step 1: Open STM32CubeIDE

  • Click in [File][Open Projects from File System…]
  • Add the path to the [Import source], ensure that all projects are present, [Finish]

BMontanari_1-1746721390464.png


3.2 
Step 2: Project setup

  • After this, a group of three projects should appear in your IDE. This example will focus on the FSBL (bootloader) and AppS (application). The ExtMemLoader's main purpose is to provide a custom external loader file. Although this is optional, since the STM32CubeProgrammer already includes a functional *.stldr file for the Discovery kit:

BMontanari_2-1746721418605.png

3.3 Step 3: Add post build step and Build All

  • As described in here, it’s possible to add the postscript to sign the binaries. In short, we can add this post build command for the [FSBL] and [AppS] projects:

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"
BMontanari_3-1746721449634.png
  • Known limitation: the current post build script for the ExtMemLoader might require admin rights to include the *.stldr file, in case you see this message:

    BMontanari_0-1747139055723.png

 

  • It’s possible to replace the post build with this command: 

cp "${BuildArtifactFileBaseName}.elf" "../CustomN6.stldr”
  • Which will create the CustomN6.stldr file within the project folder:

BMontanari_4-1746721486613.png


3.4 
Step 4: Configure the Debugger

  • Configure the Debugger to write both applications and run them in the same session. Right-click on [Template_XIP_FSBL] and then [Debug As] -> [Debug Configurations...]:

BMontanari_5-1746721510541.png

 

  • In the [Debug Configurations] window, go to the [Debugger] tab. Then, [Add] the following external loader MX66UW1G45G_STM32N6570-DK.stldr:

BMontanari_6-1746721534459.png

 

  • Check [Enabled] and uncheck [Initialize].
  • It’s possible to use the CustomN6.stldr instead. For that, in the [External loader] window, select the [Workspace...] and locate the CustomN6.stldr:

BMontanari_7-1746721573142.png


3.5 
Step 5: Startup configuration

  • Go to the [Startup] tab and add the AppS project. Make sure to uncheck the [Perform build] and [Download]:


BMontanari_8-1746721661415.png

 

  • To program the AppS in the external serial FLASH, click on [Add...] and point to the signed binary. It will be available in the Debug folder with the project’s name-Trusted.bin. Make sure to add the address pointing to the external memory as well 0x70100000: 

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
BMontanari_9-1746721688961.png

 

  • Due to the limitation of placing breakpoints, we'll set the first breakpoint in the FSBL function call BOOT_Application instead of the usual main. Now, in the FSBL firmware, the XSPI has the external memory configured in memory-mapped mode:

BMontanari_10-1746721712376.png
  • The final view should be like this:

BMontanari_11-1746721729649.png
  • Click [Apply] and [Close]. Configuration and the debug are now ready to run.

3.6 Step 6: Prepare the board

  • Disconnect the board from your computer.
  • Next, move the BOOT1 switch to the H position while keeping the BOOT0 switch to the L position to enter DEV BOOT mode. This is shown in the section above “2. Hardware setup”.

3.7 Step 7: Start debugging

  • Connect the board to the computer and click [Debug] in the IDE. If all steps were completed successfully, running the application should halt at the breakpoint set in the BOOT_Application function:

    BMontanari_12-1746721758572.png

 

  • The code starts in the FSBL application running from an address within AXISRAM2. After the code stops here, press [Resume]. The green LED should start blinking on the board.
  • By pausing the code, it's possible to notice it's running from the external flash. This can be verified by examining the function addresses in the call stack. At this point, it’s possible to utilize all standard debug features. These features include breakpoints, variables, registers, and memory views.

    BMontanari_13-1746721810189.png

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.

4. Dealing with reprogramming errors

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
BMontanari_14-1746721864427.png

Rebuild the ExtMemLoader and use the CustomN6.stldr instead.

Conclusion

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.

References

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

Version history
Last update:
‎2025-05-13 7:36 AM
Updated by:
Contributors