cancel
Showing results for 
Search instead for 
Did you mean: 

How to debug an external ELF in STM32CubeIDE

B.Montanari
ST Employee

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 @BSter.1 and @Cartu38 OpenDev for their helpful post on the STM32CubeIDE forum board, which can be accessed here.

1. Prerequisites

This article assumes you have installed:

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.

BMontanari_0-1750793983954.png

2.3 Debug file location

Place the *.ELF file you wish to debug inside the directory of the project generated in the blank project.

BMontanari_1-1750793983956.png

2.4 Debug configuration

Back to the blank project, right-click on the Project name and then [Debug As] >> [Debug Configurations…].

BMontanari_2-1750793983960.png

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:

BMontanari_3-1750793983964.png

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]:

BMontanari_4-1750793983969.png

2.5 Enter in debug

Ensure that your board is properly connected to your PC, then click [Resume] icon or press the [F8] Key.

BMontanari_5-1750793983969.png

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 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:

BMontanari_6-1750793983971.png

 

BMontanari_7-1750793983973.png

After setting it up, the code executes as it was intended to:

BMontanari_8-1750793983974.png

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

Version history
Last update:
‎2025-06-25 8:00 AM
Updated by: