How to load an Mbed OS ELF debug file into Keil-MDK

Debugging an embedded program can be a complicated and time-consuming process. This short tutorial illustrates a simple way to load an elf debug file from an Mbed OS application in Keil® MDK, thus allowing easy debug of the code.


You will need to have the following software and equipment for this tutorial:

Debugging an application

1. We will illustrate the debugging technique on a blinky project.

a. Import mbed-os-example-blinky project: mbed import mbed-os-example-blinky

b. Compile the code with Mbed CLI: mbed compile -t GCC_ARM -m UBLOX_EVK_ODIN_W2

c. Drag and drop the binary file to the development board.

2. Open Keil MDK and make a new project.


3. A window titled 'Select Device for Target will come up'. We’re using a UBLOX_EVK_ODIN_W2 board which has a STM32F439ZIY6 processor. Therefore, select STM32F439ZIYx as the device.


4. Skip the Manage Run Time Environment menu.

5. From the Project tab, select Options for Target menu.

a. Go to the debug tab, and select the correct debug interface. The UBLOX_EVK_ODIN_W2 uses ST-Link. Therefore, we selected the ST-Link Debugger.

b. Untick the 'Load Application at Startup' tick box, since we don’t have a predefined elf file for the Keil MDK project.

c. Create an initialization file in the root of the Keil MDK project. We can name the file evk.ini.


6. Open the initialization file created in the previous step. We'll use the Keil MDK debug commands to specify the elf file and the entry point for debug:

load C:\Users\geogek01\Documents\Engineering\mbedCLIproj\mbed-os-example-blinky\BUILD\UBLOX_EVK_ODIN_W2\GCC_ARM\mbed-os-example-blinky.elf

g, main

The first line loads the elf file, and in the second line, we instruct Keil MDK to go to the main function.

7. Click on the menu Debug/Start Stop Debug session. The debug session begins, and we can take advantage of the Keil MDK debug features.


The code can now be debugged by inserting breakpoints or stepping through lines.

Please log in to start a discussion or ask a question.