Linux Debugger configuration: Difference between revisions

From Miosix Wiki
Jump to navigation Jump to search
Use extended-remote
No edit summary
Line 1: Line 1:
The debugging of Miosix on Linux can be done through [http://openocd.org/ OpenOCD], that creates a bridge between GDB and the JTAG device.
The debugging of Miosix on Linux can be done through [http://openocd.org/ OpenOCD], that creates a bridge between GDB and the JTAG device.


== Setting up OpenOCD ==
= Setting up OpenOCD =


=== Install OpenOCD ===
== Install OpenOCD ==
<source lang="bash">
<source lang="bash">
sudo apt-get install openocd # Install OpenOCD for Ubuntu/Debian
sudo apt install openocd # Install OpenOCD for Ubuntu/Debian
</source>
</source>


=== Run OpenOCD ===
== Run OpenOCD ==
The OpenOCD configuration is included in the official Miosix distribution under the path 'miosix/arch'. You must choose the proper config file for the device in use. For example for the stm32f429zi_stm32f4discovery board:
The OpenOCD configuration is included in the official Miosix distribution for most of the supported boards under the path 'miosix/arch/board/<board name>/openocd.cfg'. For example for the stm32f429zi_stm32f4discovery board:
<source lang="bash">
<source lang="bash">
openocd -f miosix/arch/cortexM4_stm32f4/stm32f429zi_stm32f4discovery/stm32f4discovery.cfg
openocd -f miosix/arch/board/stm32f429zi_stm32f4discovery/openocd.cfg
</source>
</source>


Line 18: Line 18:
'''If breakpoints don't work on your board''' you can try adding the option <code>-c 'gdb_breakpoint_override hard'</code> to the OpenOCD invocation. This option disables GDB software breakpoints and always forces the use of hardware breakpoints, which might be needed if OpenOCD provides an incomplete memory map to GDB.
'''If breakpoints don't work on your board''' you can try adding the option <code>-c 'gdb_breakpoint_override hard'</code> to the OpenOCD invocation. This option disables GDB software breakpoints and always forces the use of hardware breakpoints, which might be needed if OpenOCD provides an incomplete memory map to GDB.


== Debugging with GDB ==
= Debugging with GDB =
The GDB used is provided by the official [[Miosix_Toolchain|Miosix Toolchain]]. If you haven't already installed it's time to do it. The debugger must be launched on the ELF binary file.
The GDB used is provided by the official [[Miosix_Toolchain|Miosix Toolchain]]. Although the board is flashed with the ''.bin'' file, you'll have to pass the corresponding ''.elf'' file, since this file format includes debugging symbols.
<source lang="bash">
<source lang="bash">
arm-miosix-eabi-gdb main.elf
arm-miosix-eabi-gdb main.elf
</source>
</source>


=== Connect GDB ===
== Connect GDB ==
OpenOCD provide a network interface for connect the debugger, the follow command is necessary for establish the connection:
OpenOCD provide a network interface for connect the debugger, the follow command is necessary for establish the connection:
<source lang="bash">
<source lang="bash">
Line 35: Line 35:
</source>
</source>


=== Reset the board ===
== Reset the board ==
After the connection (and after each change of configuration) you must reset the board in a safe state:
After the connection (and after each change of configuration) you must reset the board in a safe state:
<source lang="bash">
<source lang="bash">
Line 41: Line 41:
</source>
</source>


=== Flash a new firmware ===
== Using gdb ==
 
This is not a full tutorial on using GDB, information can be found online. Here we only list the basics:
 
Setting breakpoints can be done with the ''break'' command followed by the function name or source code line:
<source lang="bash">
(gdb) break main
</source>
 
or
 
<source lang="bash">
(gdb) break main.cpp:30
</source>
 
Running the board can be done with the ''run'' command, which will run till the first breakpoint is hit.
 
Note that when in-circuit debugging there is only a limited number of hardware breakpoints you can set. If you exceed the number you can remove all breakpoints with:
 
<source lang="bash">
(gdb) del break
</source>
 
and start over.
 
== Flash a new firmware ==
If you want to upload to the board a new firmware version you can made it through gdb and OpenOCD, you must indicate the binary file and the address of the flash memory of your board:
If you want to upload to the board a new firmware version you can made it through gdb and OpenOCD, you must indicate the binary file and the address of the flash memory of your board:
<source lang="bash">
<source lang="bash">

Revision as of 21:42, 10 May 2026

The debugging of Miosix on Linux can be done through OpenOCD, that creates a bridge between GDB and the JTAG device.

Setting up OpenOCD

Install OpenOCD

sudo apt install openocd # Install OpenOCD for Ubuntu/Debian

Run OpenOCD

The OpenOCD configuration is included in the official Miosix distribution for most of the supported boards under the path 'miosix/arch/board/<board name>/openocd.cfg'. For example for the stm32f429zi_stm32f4discovery board:

openocd -f miosix/arch/board/stm32f429zi_stm32f4discovery/openocd.cfg

OpenOCD provides built-in configuration files for many boards, chips and debugging adapters. You can see the entire range of files in the directory /usr/share/openocd/scripts. If Miosix does not provide a configuration file for you, in most cases there will be appropriate scripts available together with OpenOCD.

If breakpoints don't work on your board you can try adding the option -c 'gdb_breakpoint_override hard' to the OpenOCD invocation. This option disables GDB software breakpoints and always forces the use of hardware breakpoints, which might be needed if OpenOCD provides an incomplete memory map to GDB.

Debugging with GDB

The GDB used is provided by the official Miosix Toolchain. Although the board is flashed with the .bin file, you'll have to pass the corresponding .elf file, since this file format includes debugging symbols.

arm-miosix-eabi-gdb main.elf

Connect GDB

OpenOCD provide a network interface for connect the debugger, the follow command is necessary for establish the connection:

(gdb) target remote <ip>:<port>

The default socket is listening on port 3333 in the loopback interface of your computer. So you can use the default command:

(gdb) target extended-remote :3333

Reset the board

After the connection (and after each change of configuration) you must reset the board in a safe state:

(gdb) monitor reset halt

Using gdb

This is not a full tutorial on using GDB, information can be found online. Here we only list the basics:

Setting breakpoints can be done with the break command followed by the function name or source code line:

(gdb) break main

or

(gdb) break main.cpp:30

Running the board can be done with the run command, which will run till the first breakpoint is hit.

Note that when in-circuit debugging there is only a limited number of hardware breakpoints you can set. If you exceed the number you can remove all breakpoints with:

(gdb) del break

and start over.

Flash a new firmware

If you want to upload to the board a new firmware version you can made it through gdb and OpenOCD, you must indicate the binary file and the address of the flash memory of your board:

(gdb) monitor flash write_image erase main.bin 0x08000000

It's often necessary to perform a reset of the board before and after the firmware upload.