Difference between revisions of "DevGuide/GDB OpenOCD Debug"

From PaparazziUAV
Jump to navigation Jump to search
Line 1: Line 1:
== JTAG debugging ==
== JTAG adapters ==
[[Image:lpcjtag.jpg|thumb|JTAG USB Board]]
Recently some new [[JTAG]] adapters that use the FTDI2232 USB-parallel converter were introduced through OpenOCD (you can try your Wiggler with that, too). USB JTAG adapters include Floss-JTAG, Olimex or Amontec and also fine with Windows (Yagarto).
Paparazzi boards do not have a [[JTAG]] interface. The one time we needed a [[JTAG]] debugger because of some strange problems we used Keil/Olimex LPC2148 boards with a professional [[JTAG]] tool. All the parallel port Wiggler adapters and the software for that showed poor performance and were abandoned.


Recently some new [[JTAG]] adapters that use the FTDI2232 USB-parallel converter were introduced through OpenOCD (you can try your Wiggler with that, too). The USB [[JTAG]] adapters are available from Olimex or Amontec and work fine with Windows (Yagarto). Getting them to work with Linux is still a little adventure. This is collected info from various sites. The paparazzi-dev packages should be installed.
Also see [[DevGuide/OpenOCD]] for installation instructions.


== Install ==
== Debugging with GDB over JTAG ==
Openocd 0.5 is a recommendation of the paparazzi-dev package, install it if not already done so. For older distributions (Debian squeeze, Ubunutu Lucid, Maverick and Natty) backported packages are available in the Paparazzi repositories. See [[Installation]].
=== Procedure ===
# Start openocd in a new shell since this process needs to remain running.
#: To connect to the Lisa/L board run the command
#:<pre>openocd -f interface/lisa-l.cfg -f board/lisa-l.cfg</pre>
#: To connect to the Lisa/M board via FLOSS-JTAG run the command:
#:<pre>openocd -f interface/flossjtag.cfg -f board/lisa-l.cfg</pre>


=== from source ===
# Start GDB with an argument of the elf file created and uploaded to the board.
#: If you programmed with the ap target then the command would be along the lines of
#:<pre>/opt/paparazzi/arm-multilib/bin/arm-none-eabi-gdb var/<airframe>/ap/ap.elf</pre>
#: Replace <airframe> with the name of the airframe that has been built.
# Now connect GDB to the board
#:<pre>target remote localhost:3333</pre>
# Now we need to set some break points in the code.
#: In this example the ap target was part of the rotorcraft and main.c contains the main program. Open rotorcraft sw/airborne/firmwares/rotorcraft/main.c and find a line at which you'd like to set a break point.
#: <pre>break main.c:113</pre>
# Stop the currently running code
#: <pre>monitor reset halt</pre>
# Reset the code back to the start
#: <pre>monitor reset init</pre>
# Now we can run the program which will stop at the break point we set.
#:<pre>continue</pre>


The low level interfacing is done by libftdi, get it from http://www.intra2net.com/de/produkte/opensource/ftdi/ It is possible to use a closed source version from FTDI, too.
=== Useful commands ===
* We probably want to ignore the interrupt calls for the moment so we can step through the code as it's being called. Note that we don't always want to do this. (STM32 command only)
*:<pre>monitor cortex_m3 maskisr on</pre>
* A stack trace can be printed with the command
*:<pre>bt</pre>
* show the variable of a variable
*:<pre>print i2c1.status</pre>
* Show (eXamine) the value of the 9 bytes hardware register at address 0x40005800 and show them in hex format:
*:<pre>x/9x 0x40005800</pre>
* In some cases you may not be able to access some memory areas in the mcu, in that case you should try:
*:<pre>set mem inaccessible-by-default off</pre>


wget http://www.intra2net.com/de/produkte/opensource/ftdi/TGZ/libftdi-0.10.tar.gz
tar xvfz libftdi-0.10.tar.gz
cd libftdi-0.10
./configure
make
make install
Get the OpenOCD software http://openfacts.berlios.de/index-en.phtml?title=Building_OpenOCD It needs some additional packages to be built.
apt-get install autoconf
apt-get install automake
apt-get install subversion
svn checkout svn://svn.berlios.de/openocd/trunk
cd trunk
./bootstrap
./configure --enable-ft2232_libftdi
make
make install
For some debian distributions you might have to add '/usr/local/lib' to /etc/ld.so.conf.d/i486-linux-gnu.conf and call
ldconfig
Put an entry with the vendor/device ID into your udev rules directory to get the correct access rights (or use the file from cvs in conf/system/udev/rules). This applies to Amontec JTAG-Tiny.
add 'BUS=="usb", SYSFS{idVendor}=="0403", SYSFS{idProduct}=="cff8", GROUP="plugdev"'
Generate an OpenOCD config - this one worked for me, might need some polishing
#daemon configuration
telnet_port 4444
gdb_port 3333
#interface
interface ft2232
ft2232_layout "jtagkey"
ft2232_vid_pid 0x0403 0xcff8
jtag_speed 2
# reset_config <signals> [combination] [trst_type] [srst_type]
reset_config trst_and_srst
#jtag scan chain
jtag_device 4 0x1 0xf 0xe
jtag_nsrst_delay 333
jtag_ntrst_delay 333
#target configuration, what to do on a target reset
target arm7tdmi little run_and_halt 0 arm7tdmi-s_r4
run_and_halt_time 0 30
daemon_startup reset
#target_script 0 reset openocd.script
working_area 0 0x40000000 0x4000 nobackup
 
# flash bank lpc2000 <base> <size> 0 0 <variant> <target#> <clock> ['calc_checksum']
# mthomas: LPC2138 @ 12MHz 0x7D000 from 500*1024 (not 512!)
flash bank lpc2000 0x0 0x7D000 0 0 lpc2000_v2 0 12000 calc_checksum
The arm-gdb is not in the Paparazzi package yet, you have to get it from somwhere else for now. This .gdbinit should start gdb in the correct way:
#set directories $cdir:$cwd:../lcds16x2/
set can-use-hw-watchpoints 2
set complaints 33
set history save
set history size 333
set logging on
set output-radix 0x10
set step-mode on
set trust-readonly-sections on
set verbose on
set watchdog 15
target remote localhost:3333
monitor soft_reset_halt
# only for RAM: monitor arm7_9 sw_bkpts enable
monitor arm7_9 force_hw_bkpts enable
hbreak main
#load
#continue
Get Eclipse 3.2.2  (Debian Etch Eclipse package does not work, there is some problem with JRE 1.4.x)
wget http://download.eclipse.org/eclipse/downloads/drops/R-3.2.2-200702121330/download.php?dropFile=eclipse-SDK-3.2.2-linux-gtk.tar.gz
tar xvfz eclipse-SDK-3.2.2-linux-gtk.tar.gz
Unzip the Eclipse embedded CDT from Zylin for embedded debugging http://www.zylin.com/embeddedcdt.html
wget http://www.zylin.com/embeddedcdt-linux-gtk-20060908.zip
wget http://www.zylin.com/zylincdt-20060908.zip
cd eclipse
unzip embeddedcdt-linux-gtk-20060908.zip
unzip zylincdt-20060908.zip
Now you have to get used to Eclipse, read this using the LPC2148 examples: http://www.yagarto.de/howto/yagarto2/index.html


[[Category:Hardware]] [[Category:Software]] [[Category:Developer_Documentation]]
[[Category:Hardware]] [[Category:Software]] [[Category:Developer_Documentation]]

Revision as of 06:32, 12 February 2012

JTAG adapters

Recently some new JTAG adapters that use the FTDI2232 USB-parallel converter were introduced through OpenOCD (you can try your Wiggler with that, too). USB JTAG adapters include Floss-JTAG, Olimex or Amontec and also fine with Windows (Yagarto).

Also see DevGuide/OpenOCD for installation instructions.

Debugging with GDB over JTAG

Procedure

  1. Start openocd in a new shell since this process needs to remain running.
    To connect to the Lisa/L board run the command
    openocd -f interface/lisa-l.cfg -f board/lisa-l.cfg
    To connect to the Lisa/M board via FLOSS-JTAG run the command:
    openocd -f interface/flossjtag.cfg -f board/lisa-l.cfg
  1. Start GDB with an argument of the elf file created and uploaded to the board.
    If you programmed with the ap target then the command would be along the lines of
    /opt/paparazzi/arm-multilib/bin/arm-none-eabi-gdb var/<airframe>/ap/ap.elf
    Replace <airframe> with the name of the airframe that has been built.
  2. Now connect GDB to the board
    target remote localhost:3333
  3. Now we need to set some break points in the code.
    In this example the ap target was part of the rotorcraft and main.c contains the main program. Open rotorcraft sw/airborne/firmwares/rotorcraft/main.c and find a line at which you'd like to set a break point.
    break main.c:113
  4. Stop the currently running code
    monitor reset halt
  5. Reset the code back to the start
    monitor reset init
  6. Now we can run the program which will stop at the break point we set.
    continue

Useful commands

  • We probably want to ignore the interrupt calls for the moment so we can step through the code as it's being called. Note that we don't always want to do this. (STM32 command only)
    monitor cortex_m3 maskisr on
  • A stack trace can be printed with the command
    bt
  • show the variable of a variable
    print i2c1.status
  • Show (eXamine) the value of the 9 bytes hardware register at address 0x40005800 and show them in hex format:
    x/9x 0x40005800
  • In some cases you may not be able to access some memory areas in the mcu, in that case you should try:
    set mem inaccessible-by-default off