How to debug an external .elf file in STM32CubeIDE
- June 26, 2025
- 0 replies
- 1225 views
Summary
This article provides a quick guide on debugging an application using its external *.elf file. It includes instructions and explanations on how to implement the file into the STM32CubeIDE interface and enter debug mode, enabling the user to verify externally generated code. This example can be tailored to any STM32 microcontroller.
Introduction
An *.elf file (executable and linkable format) is a standard file format used in embedded systems development, including microcontroller applications. It is the output of the compilation and linking process and contains all the necessary information for the microcontroller to execute the application. It includes the executable code, initialized and uninitialized data used by the application, symbols, addresses, and other metadata useful for debugging. Finally, information about how the program is mapped into the microcontroller's memory.
In this article, a blank project is created so the STM32CubeIDE interface has the proper configurations to read and debug the *.elf file.
Special thanks to
1. Prerequisites
This article assumes you have installed:
- STM32CubeMX (6.13 or later)
- STM32CubeIDE (1.18.0 or later)
- STM32N6 HAL driver (1.1.1 or later)
The hardware used to showcase is the STM32N6570-DK, but this example can be tailored to any STM32 microcontroller.
2. Proof of concept
2.1 Select a demo and build it
The *.elf file chosen for this demonstration can be found in the STM32N6’s “Examples” >> “UART” >> “UART_HyperTerminal_IT” Repository, or under the default installation path:
C:\Users\%username%\STM32Cube\Repository\STM32Cube_FW_N6_V1.1.1\Projects\STM32N6570-DK\Examples\UART\UART_HyperTerminal_IT
The example performs the following operations:
- Displays the TxBuffer content in the HyperTerminal interface and stores the received data in the RxBuffer.
- Sends the received data in the RxBuffer back to the HyperTerminal for display once 10 bytes are received.
Make sure to open the project using your STM32CubeIDE and rebuild it to generate the *.ELF file.
2.2 Generating a blank project in STM32CubeIDE
Create a new project using the STM32CubeMX integration inside the STM32CubeIDE, by clicking [File][New][STM32 Project], under the [MCU Selector] section for your desired microcontroller, in this case [STM32N657X0H3Q]. Once the project is created, press [Ctrl+S] to save the blank project, and the base code is generated.
2.3 Debug file location
Place the *.elf file you wish to debug inside the directory of the project generated in the blank project.
2.4 Debug configuration
Back to the blank project, right-click on the Project name and then [Debug As] >> [Debug Configurations…].
OBS.: If your current project does not show up under the “STM32 C/C++ Application”, you can just select the “New launch configuration” button and then choose your current project:
Change "C/C++ Application" to your external *.elf with the absolute path (the path from the project generated in Step 2), click [Apply] and then [Debug]:
2.5 Enter in debug
Ensure that your board is properly connected to your PC, then click [Resume] icon or press the [F8] Key.
Note that a message claiming main.c was not found might appear, but it should not affect your debugging session. The *.elf file does contain the location of the original project’s file. This message only appears if the original project that generated the *.elf file is no longer at the same path.
2.6 Validation
To verify the debugging, use terminal emulator software, such as Tera Term or the embedded software available in STM32CubeIDE, with the following configuration:
After setting it up, the code executes as it was intended to:
Conclusion
Debugging an application is a critical step in ensuring its reliability, functionality, and performance. By leveraging tools like STM32CubeIDE and STM32CubeMX, developers gain access to a robust and user-friendly environment for application validation and debugging. These tools are particularly valuable as they allow effective debugging even in scenarios where the application's source code is unavailable.
Related links
- Product page: Discovery kit with STM32N657X0 MCU
- Data brief: STM32N6570-DK - Discovery kit with STM32N657X0 MCU
- STM32CubeMX: STM32Cube initialization code generator
- STM32CubeIDE: Integrated development environment for STM32
- User manual 3249: Getting started with STM32CubeN6 for STM32N6 series
- Knowledge article: How to debug STM32N6 using STM32CubeIDE
