OpenOCD+Eclipse+Olimex ARM-USB-OCD+Olimer AT91SAM7x256

Hi,

I have recently bought an Olimex ARM-USB-OCD and Olimex AT91SAM7x256. Then I try to follow the tutorial from James Lynch (titled AT91SAM7 Serial Communication), which I think is very well written.

I use the following for my setup:

  1. WindowsXP Service Pack 3

  2. OpenOCD SVN 1888 (from Yagarto website, before it was removed recently).

  3. Yagarto tools (binutils: 2.19.1, gcc: 4.3.3, newlib: 1.17.0, gdb: 6.8.50-20080308-cvs).

  4. Eclipse 3.4.2 that is updated with CDT 5.0.1 and Zylin Embedded 4.7.1

  5. Olimex ARM-USB-OCD and Olimex AT91SAM7x256.

Output of Make with Eclipse looks like this…

**** Build of configuration Default for project demo_sam7ex256 ****

make all

arm-elf-as -mapcs-32 -g -o crt.o crt.s

arm-elf-gcc -mcpu=arm7tdmi -I./ -c -fno-common -O0 -g -fomit-frame-pointer -Wcast-align -c -o main.o main.c

arm-elf-gcc -mcpu=arm7tdmi -I./ -c -fno-common -O0 -g -fomit-frame-pointer -Wcast-align -c -o lowlevelinit.o lowlevelinit.c

arm-elf-gcc -mcpu=arm7tdmi -I./ -c -fno-common -O0 -g -fomit-frame-pointer -Wcast-align -c -o usart0_setup.o usart0_setup.c

arm-elf-gcc -mcpu=arm7tdmi -I./ -c -fno-common -O0 -g -fomit-frame-pointer -Wcast-align -c -o usart0_isr.o usart0_isr.c

arm-elf-gcc -mcpu=arm7tdmi -I./ -c -fno-common -O0 -g -fomit-frame-pointer -Wcast-align -c -o isrsupport.o isrsupport.c

…linking

arm-elf-ld -v -omain.out -Tdemo_sam7ex256.cmd -Map main.map --cref -omain.out crt.o main.o lowlevelinit.o usart0_setup.o usart0_isr.o isrsupport.o libgcc.a

GNU ld (GNU Binutils) 2.19.1

…create binary file

arm-elf-objcopy --output-target=binary main.out main.bin

…create dump file

arm-elf-objdump -x --syms main.out > main.dmp

However, when I setup the second make target for flash programming, following the tutorial from James, I run into several problems. Mostly are related to deprecated commands in OpenOCD configuration files. In the tutorial, there two *.cfg file, the openocd_program.cfg and the openocd.cfg.

After reading the OpenOCD document and tweaking the files, I have the following results for the target build…

**** Build of configuration Default for project demo_sam7ex256 ****

make program

Flash Programming with OpenOCD…

'C:/Program Files/openocd-r1888/bin/'openocd-ftd2xx.exe -s ‘C:/Program Files/openocd-r1888/bin/’ -f openocd_program.cfg # program the onchip FLASH here

Open On-Chip Debugger 0.2.0-in-development (2009-05-23-14:36) svn:1888M

(snapshot 1888 from SVN tree + patch, no official release)

BUGS? Read http://svn.berlios.de/svnroot/repos/openocd/trunk/BUGS

2000 kHz

Unknown command: reset run

make: *** [program] Error 1

My openocd_program.cfg (updated from James’ version) looks like

telnet_port 4444

gdb_port 3333

interface ft2232

ft2232_device_desc “Olimex OpenOCD JTAG A”

ft2232_layout “olimex-jtag”

ft2232_vid_pid 0x15BA 0x0003

jtag_khz 2000

jtag_nsrst_delay 200

jtag_ntrst_delay 200

reset_config srst_only srst_pulls_trst

if { [info exists CHIPNAME] } {

set _CHIPNAME $CHIPNAME

} else {

set _CHIPNAME sam7x256

}

if { [info exists ENDIAN] } {

set _ENDIAN $ENDIAN

} else {

set _ENDIAN little

}

if { [info exists CPUTAPID ] } {

set _CPUTAPID $CPUTAPID

} else {

set _CPUTAPID 0x3f0f0f0f

}

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

set _TARGETNAME [format “%s.cpu” $_CHIPNAME]

target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm7tdmi_r4

#run_and_halt_time <target#> <time_in_ms>

#run_and_halt_time 0 30 deprecated

reset run

sleep 100

halt

commands below are specific to AT91sam7 Flash Programming

---------------------------------------------------------

#$_TARGETNAME configure -event reset-init “script script.ocd”

$_TARGETNAME configure -work-area-phys 0x00200000 -work-area-size 0x4000 -work-area-backup 0

#flash bank at91sam7 0 0 0 0 <target#>

flash bank at91sam7 0 0 0 0 0

init

reset halt

Now the questions…

  1. According to OpenOCd manual, I should replace run_and_halt_time 0 30 with the reset run, sleep 100 and halt. I may not be doing it right, since the target build failed on the “reset run”. Can anybody please shed some lights on this?

  2. The “daemon_startup reset” is also deprecated and can be replaced with init and reset halt. Have I placed it at the right spot?

  3. Calling the script.ocd was done using event handler, have I used the correct event name? Notice that I used reset-init for event name.

Thank you very much for your time to look at my posting. I appreciate any feedback or directions that any of you may give me.

Chris

Hi Chris,

I have an identical setup to yourself and have just spent 3 weeks trying to figure out how to write a binary file to the internal flash on the SAM7, and then run the debugger within Eclipe.

After may hours reading the OpenOCD documentation and experimentation, I have managed to create new versions of config files to write to flash. However, I’ve not yet had any success in debugging, but I’m working on it.

Anyway, here are my two config files for writing to flash. These files are used in exactly the same way as those in Jim Lynch’s tutorial.

at91sam7s256-armusbocd-flash-program.cfg

define our ports

telnet_port 4444

gdb_port 3333

tcl_port 6666

#commands specific to the Olimex ARM_USB_OCD

interface ft2232

ft2232_device_desc “Olimex OpenOCD JTAG A”

ft2232_layout “olimex-jtag”

ft2232_vid_pid 0x15BA 0x0003

jtag_speed 1

jtag_nsrst_delay 200

#jtag_ntrst_delay 200

reset_config srst_only srst_pulls_trst

if { [info exists CHIPNAME] } {

set _CHIPNAME $CHIPNAME

} else {

set _CHIPNAME sam7s256

}

if { [info exists ENDIAN] } {

set _ENDIAN $ENDIAN

} else {

set _ENDIAN little

}

if { [info exists CPUTAPID ] } {

set _CPUTAPID $CPUTAPID

} else {

set _CPUTAPID 0x3f0f0f0f

}

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

set _TARGETNAME [format “%s.cpu” $_CHIPNAME]

target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm7tdmi

Flash write routine is in the script.ocd file within the project.

$_TARGETNAME configure -event reset-init “script script.ocd”

$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x00200000 -work-area-size 0x4000 -work-area-backup 0

#flash bank <chip_width> <bus_width>

flash bank at91sam7 0 0 0 0 0

init

reset init

shutdown

and my script.ocd file is :

OpenOCD Target Script for Atmel AT91SAM7S256

#mww 0xffffff64 0x5a000004 # clear lock bit 0 -only use if flash bank known to be locked

#mww 0xffffff64 0x5a002004 # clear lock bit 1 -only use if flash bank known to be locked

mww 0xfffffd44 0x00008000 # disable watchdog

mww 0xfffffd08 0xa5000001 # enable user reset

mww 0xfffffc20 0x00000601 # CKGR_MOR : enable the main oscillator

sleep 10

mww 0xfffffc2c 0x00481c0e # CKGR_PLLR: 96.1097 MHz

sleep 10

mww 0xfffffc30 0x00000007 # PMC_MCKR : MCK = PLL / 2 ~= 48 MHz

sleep 10

mww 0xffffff60 0x003c0100 # MC_FMR: flash mode (FWS=1,FMCN=60)

sleep 100

halt

sleep 10

arm7_9 dcc_downloads enable

sleep 10

poll

flash probe 0

flash write_bank 0 main.bin 0x0

reset run

sleep 10

I hope this helps, and you are able to progess a little further.

Hi Andrew,

I appreciate your post that helps me move forward.

Either way, after a few tests using your suggested configuration, I got to the point you were. I then decided to try something else.

I switched to older OpenOCD version the r717 and yagarto binary tuils 2.18. However, I kept everything else at the same version(Eclipse, CDT, Zylin 4.7.1).

Then I followed the instructions from the James Lynch tutorial (AT91SAM7 Serial Communications) again… and I have better luck… :lol:

I do not believe I have gotten everything down correctly, since the program does not behave as described in the tutorial. The serial port seems to respond immediately on every character that it receives. But at this point, I can write to flash and can debug (I have not verified everything, but I can step into and step over).

That is where I am right now… a few questions for you inf you do not mind

  1. Does you hardware from Olimex has the AT91SAM7S256 or AT91SAM7X256? Just curious…

  2. How did you figure out the changes you made to the configuration file and the script.ocd file? What manuals did you refer to (if any)?

Thanks again for your response and please let me know your current state.

Chris.

Chris,

I’m glad to hear that you’ve managed to get a working system. I, too have just succeeded in configuring a working setup, including on-circuit-debugging, based on the latest version of OpenOCD, Yagarto tools and Eclipse.

To answer your questions :

    • I have an Olimex SAM7-P256 board with an Atmel at91SAM7s256 ARM processor on board.
    • Working out the changes was not simple - The main documents I used were the PDF manual contained within the OpenOCD package and Jim Lynch’s tutorial - The OpenOCD manual is not the simplest of manuals to understand. It makes the assumption that the reader understands GDB and configuring debugging in general. I’m just a newbie with an interest, and it took me several readings along with internet searches on various forums, such as this one, to grasp the basics. I then started putting together the config files based around the various component parts. (interface, target, etc.) I compared the files in Jim Lynch’s tutorial with those in the OpenOCD package and through trial and error, plus a measure of frustration and late nights, managed to put a working set together.

Incidentally, I ‘wrote’ the scripts on WinXP SP3, running in a virtual machine on an iMac. But I have now transferred all the same config files and scripts, without any changes, to Mac versions of the same tools running natively on the iMac under OSX! (I am not a lover of the Windows platform)

My final system is:

iMac (20" Intel) running OS 10.5.7

OpenOCD R1888

Yagarto Tools 4.3.3

Eclipse Galileo

Olimex ARM-USB-OCD dongle

Olimex SAM7-P256 board

Hewlett Packard 20B pocket calculator - modified to add a Jtag connector - This calculator uses an Atmel at91SAM7L128 processor and has a keyboard & LCD - Ideal for tinkering and developing on. Plus HP have made a development kit freely downloadable from the their website)

I have tested the setup with several small C embedded applications to flash the two LEDs on the Olimex board and read the two switches, and all seems to work as expected. I can write to on chip flash and enter debugging, single step and read registers, etc. so all is looking promising.

And now to start on the HP 20B :lol:

p.s. I haven’t posted the remaining config files & scripts for debugging, but if you would like a copy then please say, and I will.

Andrew,

Good job… good to hear that you can set it up using all the greatest and latest as well.

From your descriptions, there are minor differences on our setup and hardware. The dev board that I have is SAM7-EX256 from Olimex to start with.

Well, enjoy the system that you setup and yes, please share your config file and script file, if you don’t mind. I definitely plan to try to upgrade my system in the near future.

Thanks again,

Chris

As requested, here are the two files relating to debugging. They are utilised in the same manner as those in Jin Lynch’s tutorial.

The first is the OpenOCD config file. This is essentially the same as the flash programming config file as listed above, but without the line that calls the flash script file:

#define our ports
telnet_port 4444
gdb_port 3333
tcl_port 6666

#commands specific to the Olimex ARM_USB_OCD
interface ft2232
ft2232_device_desc "Olimex OpenOCD JTAG A"
ft2232_layout "olimex-jtag"
ft2232_vid_pid 0x15BA 0x0003
jtag_speed 1
jtag_nsrst_delay 200
#jtag_ntrst_delay 200

reset_config srst_only srst_pulls_trst

if { [info exists CHIPNAME] } {	
	set  _CHIPNAME $CHIPNAME    
} else {	 
	set  _CHIPNAME sam7x256
}

if { [info exists ENDIAN] } {	
	set  _ENDIAN $ENDIAN    
} else {	 
	set  _ENDIAN little
}

if { [info exists CPUTAPID ] } {
	set _CPUTAPID $CPUTAPID
} else {
	set _CPUTAPID 0x3f0f0f0f
}

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

set _TARGETNAME [format "%s.cpu" $_CHIPNAME]

target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm7tdmi

$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x00200000 -work-area-size 0x4000 -work-area-backup 0

#flash bank <driver> <base> <size> <chip_width> <bus_width>
flash bank at91sam7 0 0 0 0 0

init

… and the second is the debugger initialisation and script. To be entered into the appropriate dialog in Eclipse.

# debug initialisation and scripts for use with Eclipse and OpenOCD.

# add the following line to 'initialize commands' field in the commands tab of the debugger configuration dialog

target remote localhost:3333


# add the following script to the run commands field in the commands tab of the debugger configuration dialog

monitor reset init
monitor sleep 500
monitor mww 0xFFFFFD44 0x00008000
monitor mww 0xFFFFFC20 0x00000601
monitor sleep 10
monitor mww 0xFFFFFC2C 0x00480a0e
monitor sleep 10
monitor mww 0xFFFFFC30 0x00000007
monitor sleep 10
monitor mww 0xFFFFFF60 0x003c0100
monitor sleep 100
set mem inaccessible-by-default off
load
break main
continue

Hi Andrew,

are you using the Eclipse CDT 6.0 GDB Hardware Debugging, or the Zylin CDT extensions to integrate GDB/OpenOCD into Galileo?

I have tried both and both, I am sometimes getting into funny states that I must power cycle the board, as the Eclipse/GDB/OpenOCD is unable to reset the AT91SAM7XC512 properly.

We use the Amontec JTAG, not the Olimex one, and the Atmel demo board for SAM7XC256 as well as our own board based on the XC512, but the results seem to be pretty much the same.

BTW, thanks for the hint on the HP 20B, that is quite an interesting platform!

Petr