September 11, 2009

ARM7TDMI cross development with OpenOCD 0.5.0

In this article, I’ll talk about programming and debugging of ATMEL AT91SAM7S256 chips with OpenOCD 0.5.0.

This article covers cross compiling, cross debugging and OpenOCD configuration issues.

First of all, we need to install OpenOCD into our system.
I noticed that my development environment is Ubuntu 9.04 i386.

OpenOCD installation has 6 steps:
1- Installing dependencies,

   $ sudo apt-get install automake autoconf libftdi-dev flex build-essential libtool texinfo

2- Checking out OpenOCD from git repository,

   $ mkdir openocd0.5.0 && cd openocd0.5.0
   $ git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd 
   $ cd openocd

3- Configuring OpenOCD,

   $ ./bootstrap
   $ ./configure --enable-ft2232_libftdi --enable-ep93xx --enable-rlink --enable-maintainer-mode

4- Compiling OpenOCD,

   $ make

5- Installing OpenOCD,

   $ sudo make install

6- Adding rules to udev in order to run OpenOCD as also normal user.
(If you do not add this script into udev, you cannot run openocd with usb jtag dongles, unless you are root!)
Create a 45-ft2232.rules file as root in /etc/udev/rules.d, and then copy and paste this script into it.

   BUS!="usb", ACTION!="add", SUBSYSTEM!=="usb_device", GOTO="kcontrol_rules_end"

   SYSFS{idProduct}=="0003", SYSFS{idVendor}=="15ba", MODE="664", GROUP="plugdev"

   LABEL="kcontrol_rules_end"

After adding this rule, do not forget the restart udev deamon.
In order to restart udev,

   $ sudo /etc/init.d/udev restart

This udev rule is specific for Olimex ARM-USB-OCD JTAG interface. if you would like to use another jtag dongle (rlink, amontec, etc), you have to change idPruduct and idVendor value of this configuration script with the jtag which you want to use.

Now, we can start OpenOCD
The simple way to start OpenOCD

   $ openocd -f configuration_file  <-s start_script> <-d#debug_verbosity_level>

‘<>’ shows optional parameters.

   bolat@bolat-desktop:~/workspace/eclipse_sam7_blink_flash$ openocd -f at91sam7s256-armusbocd-flash-debug.cfg

starting openocd

Now, we can compile our sample project (from James P Lynch) and burn binary image into the ATMEL sam7s256 processor

   bolat@bolat-desktop:~/workspace/eclipse_sam7_blink_flash $ make all
   bolat@bolat-desktop:~/workspace/eclipse_sam7_blink_flash $ make program

Let us start to debug our code
In order to debug our code, we need to arm-linux-gdb; although in this project, i have used arm-elf-gcc, -so as to compile our source with debug symbols- arm-linux-gdb can be used without any problem.

    $ ddd --debugger arm-linux-gdb main.out

start ddd

as shown in the picture it is best way to start arm-linux-gdb in the working directory.

We have started ddd with arm-linux-gdb attached with main.out(elf file with debug symbols) but, it is not adequate to start debug process, to start debug process we should invoke gdb configuration script.
This can be 2 ways:
1- Prepare a configuration script and then execute in the gdb (in this case arm-linux-gdb) as shown in the picture

ddd debug configuration script

or
2- Prepare .gdbinit file in the working directory (where main.out is), then invoke gdb. In this case configuration script invoked immediately when the gdb runs.

Debugging application.
Debug script mentioned about in this article provides with four actions.
1- connection of the gdb server created by OpenOCD,

   target remote localhost:3333

2- Forces breakpoints as hardware breakpoints,

   monitor gdb_breakpoint_override hard

3- Loading debug symbols from file main.out,

   load

4- Last, setting up a hw breakpoint into main function entry.

   break main

It is almost done. Now you can debug our code with conventional gdb commands.
Incidentally, sam7p256 chips supports up to 2 hw breakpoints. If you cannot execute step and stepi command, decrease break points in use.

ddd debug

Project source code, openocd and arm-linux-gdb configuration scripts can be download here.

 

Older Posts »

Powered by WordPress