JTAG and OpenOCD, part 3: Eclipse Debugging

The final step in the setup of an embedded programming environment is often getting debugging to work. It requires all the other steps to function. This is really the main selling point of JTAG over SAMBA – live code debugging.

First, you need to download Zylin Embedded CDT. Searching Google will get you directions, just use the installation manager of Eclipse to do this. Once you have this installed, move on.

Go into Debug Configurations.

debug-1
Create a new “Zylin Embedded Debug (Native)”, give it a specific name. I am unsure if you need different ones for Flash and SRAM, but better safe than sorry… debug-2

Select your project and the .elf, not the .hex or .bin. (This will need to change for each project, one of the few things that does. I am sure there is a way to avoid this, please comment if you know how to get Eclipse to autoselect the project’s binary when you right-click it and “Debug as”.)

debug-3

In the Debugger tab, you’ll probably have to change the GDB debugger’s command name.

debug-4
In the Commands tab, you will have to enter a script into the “Initialize” commands, these are the ones that work for me (lifted from aifrog.com, which has a very good explanation of what they do):

debug-5
target remote localhost:3333
monitor reset  
monitor sleep 500
monitor poll
monitor soft_reset_halt  
monitor arm7_9 sw_bkpts enable
monitor armv4_5 core_state arm
monitor mww 0xFFFFFD44 0xa0008000
monitor mww 0xfffffd08 0xa5000401
monitor mww 0xFFFFFC20 0x00000601
monitor sleep 100
monitor mww 0xFFFFFC2C 0x00480a0e
monitor sleep 200
monitor mww 0xFFFFFC30 0x00000007
monitor sleep 100
monitor mww 0xffffff60 0x00320100
monitor sleep 100
load
break main
continue

Now you’re ready to debug. Run the OpenOCD flashing tool, which will stay open (remove that “shutdown” at the end of the .cfg if you have it) and listen for TCP on 3333 and telnet on 4444. Now run the debugger, and you should see this:
debug-6

It will pause when it gets inside main. Try inserting a breakpoint between the two LED toggles so you can see it running and stopping when you resume. When you close the debugger you should probably also kill the OpenOCD session as well.

3 Responses to JTAG and OpenOCD, part 3: Eclipse Debugging

  1. michael says:

    thanks for publishing this.
    it has been very helpfull.

  2. Afi says:

    Hi,
    I tried this manual with the new version of OpenOCD v 0.4.0., Eclipse Helios, Yagarto 2.20.1 with GCC 4.5.0, Zylin and OLIMEX ARM-USB-TINY-H JTAG debbuger.

    However, I received these errors:

    target remote localhost:3333
    0x000003c0 in main () at main.c:139
    139 for (j = 1000000; j != 0; j– ); // wait 1 second 1000000
    monitor reset
    JTAG tap: at91sam7s.cpu tap/device found: 0x3f0f0f0f (mfg: 0x787, part: 0xf0f0, ver: 0x3)
    NOTE! DCC downloads have not been enabled, defaulting to slow memory writes. Type ‘help dcc’.
    NOTE! Severe performance degradation without fast memory access enabled. Type ‘help fast’.
    monitor sleep 500
    monitor poll
    background polling: on
    TAP: at91sam7s.cpu (enabled)
    target state: running
    monitor soft_reset_halt
    requesting target halt and executing a soft reset
    target state: halted
    target halted in ARM state due to debug-request, current mode: Supervisor
    cpsr: 0x200000d3 pc: 0x00000000
    monitor arm7_9 sw_bkpts enable
    arm7_9 sw_bkpts enable: command requires more arguments
    in procedure ‘arm7_9’ called at file “command.c”, line 650
    called at file “command.c”, line 361
    monitor armv4_5 core_state arm
    Runtime error, file “command.c”, line 650:
    wrong # args: should be “armv4_5 params”
    monitor mww 0xFFFFFD44 0xa0008000
    monitor mww 0xfffffd08 0xa5000401
    monitor mww 0xFFFFFC20 0\32700000601
    Invalid command argument
    value option value (‘0\37700000601’) is not valid
    Command handler execution failed
    in procedure ‘mww’ called at file “command.c”, line 650
    called at file “command.c”, line 361
    monitor sleep 100
    monitor mww 0xFFFFFC2C 0\32700480a0e
    Invalid command argument
    value option value (‘0\37700480a0e’) is not valid
    Command handler execution failed
    in procedure ‘mww’ called at file “command.c”, line 650
    called at file “command.c”, line 361
    monitor sleep 200
    monitor mww 0xFFFFFC30 0\32700000007
    Invalid command argument
    value option value (‘0\37700000007’) is not valid
    Command handler execution failed
    in procedure ‘mww’ called at file “command.c”, line 650
    called at file “command.c”, line 361
    monitor sleep 100
    monitor mww 0xffffff60 0\32700320100
    Invalid command argument
    value option value (‘0\37700320100’) is not valid
    Command handler execution failed
    in procedure ‘mww’ called at file “command.c”, line 650
    called at file “command.c”, line 361
    monitor sleep 100
    load
    Loading section .text, size 0xe3c lma 0x0
    Loading section .data, size 0x470 lma 0xe3c
    Start address 0x0, load size 4780
    Transfer rate: 26 KB/sec, 2390 bytes/write.
    break main
    Breakpoint 1 at 0x16c: file main.c, line 59.
    continue
    Unable to set 32 bit software breakpoint at address 0000016c – check that memory is read/writable

  3. Afi says:

    I already solved the problem, the solution is on:
    http://forum.sparkfun.com/viewtopic.php?f=18&t=23131

Leave a comment