Dangerous Prototypes

Dangerous Prototypes => Bus Blaster JTAG debugger => Topic started by: frank26080115 on March 10, 2011, 07:15:56 am

Title: Trouble Using OpenOCD for AT91SAM7XC512
Post by: frank26080115 on March 10, 2011, 07:15:56 am
I'm stumped on how to use OpenOCD and Bus Blaster to write to my AT91SAM7XC512

The document "using open source tools for at91sam7s cross development" appears to be very outdated as many of the commands have different parameters now. Many of the command names appears to have changed as well. Many guides I found are completely useless, since many of the commands they have used no longer exist, such as "jtag_device".

Running this in a cfg
Code: [Select]
interface ft2232
ft2232_device_desc "Dual RS232-HS"
ft2232_layout jtagkey
ft2232_vid_pid 0x0403 0x6010

jtag_khz 30000

results in
Code: [Select]
Open On-Chip Debugger 0.4.0 (2010-02-22-19:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.berlios.de/doc/doxygen/bugs.html
30000 kHz
Info : max TCK change to: 30000 kHz
Info : clock speed 30000 kHz
Warn : There are no enabled taps.  AUTO PROBING MIGHT NOT WORK!!
Warn : AUTO auto0.tap - use "jtag newtap auto0 tap -expected-id 0x7f1f1f1f ..."
Warn : AUTO auto0.tap - use "... -irlen 2"
Error: auto0.tap: IR capture error; saw 0x0003 not 0x0001
Info : JTAG tap: auto0.tap tap/device found: 0x7f1f1f1f (mfg: 0x78f, part: 0xf1f1, ver: 0x7)
Error: auto0.tap: IR capture error; saw 0x0003 not 0x0001
Command handler execution failed
Warn : jtag initialization failed; try 'jtag init' again.
Warn : gdb services need one or more targets defined

and if I tie JTAGSEL to enable boundary scan

Code: [Select]
Open On-Chip Debugger 0.4.0 (2010-02-22-19:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.berlios.de/doc/doxygen/bugs.html
30000 kHz
Info : max TCK change to: 30000 kHz
Info : clock speed 30000 kHz
Warn : There are no enabled taps.  AUTO PROBING MIGHT NOT WORK!!
Warn : AUTO auto0.tap - use "jtag newtap auto0 tap -expected-id 0x0b63207f ..."
Warn : AUTO auto0.tap - use "... -irlen 2"
Error: auto0.tap: IR capture error; saw 0x0003 not 0x0001
Info : JTAG tap: auto0.tap tap/device found: 0x0b63207f (mfg: 0x03f, part: 0xb632, ver: 0x0)
Error: auto0.tap: IR capture error; saw 0x0003 not 0x0001
Command handler execution failed
Warn : jtag initialization failed; try 'jtag init' again.
Warn : gdb services need one or more targets defined

Note, my target is powered and appears to be responding, as I am able to see its identifiers
Also notice the line "Error: auto0.tap: IR capture error; saw 0x0003 not 0x0001"

From the OpenOCD manual says "The bit pattern loaded by the TAP into the JTAG shift register on entry to the ir capture state, such as 0x01. JTAG requires the two LSBs of this value to be 01."

So I added the line

Code: [Select]
jtag newtap at91samx512 cpu -irlen 4 -ircapture 0x1 -irmask 0x1 -expected-id 0x7f1f1f1f
or if the jumper is in
Code: [Select]
jtag newtap at91samx512 cpu -irlen 4 -ircapture 0x1 -irmask 0x1 -expected-id 0x0b63207f

and then got

Code: [Select]
Open On-Chip Debugger 0.4.0 (2010-02-22-19:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.berlios.de/doc/doxygen/bugs.html
30000 kHz
Warn : at91samx512.cpu: nonstandard IR mask
Info : max TCK change to: 30000 kHz
Info : clock speed 30000 kHz
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Command handler execution failed
Warn : jtag initialization failed; try 'jtag init' again.
Warn : gdb services need one or more targets defined

I double checked the power, and also even tried 2000 kHz instead of 30000 kHz

Also note that I am specifying at91sam7x512 instead of at91sam7xc512 because OpenOCD told me I should (I forgot when I got an warning, but it did tell me to use x instead of xc)

it got the ID just fine at 30000 kHz, I think the speed and connections and power are all fine. I can still use SAM-BA with the TST and ERASE pins.

Can anybody help me simply write a .bin file into my AT91SAM7XC512?
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: robots on March 10, 2011, 08:21:37 pm
try to look at some example, like this one
http://openocd.git.sourceforge.net/git/ ... db;hb=HEAD (http://openocd.git.sourceforge.net/git/gitweb.cgi?p=openocd/openocd;a=blob;f=tcl/target/at91sam7x256.cfg;h=dd364585feba5a7b407449600893608f646114db;hb=HEAD)

You can include this file by adding following line to your config
source [find target/XXXX.cfg]

I am guessing that sam7x256 is not much different from sam7xc512, probably just ID

BTW, i doubt that you can use jtag_khz 2000, or even 30000. That is too much for uninitialized cpu, that is running from internal oscillator. Check the documentation :)
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: frank26080115 on March 10, 2011, 08:28:08 pm
Thanks for the pointer to that file, it was not included in the package I downloaded, I tried the at91sam7sx.cfg before and got a bunch of errors regarding the IDs not matching (not surprised)

Do I have to recompile anything so that the at91sam7x256.cfg works? is there anywhere in the source code where I can check that the ID I want is defined?
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: frank26080115 on March 11, 2011, 01:57:57 am
Hi I just got home and got started again, I noticed something

I changed my cfg to
Code: [Select]
interface ft2232
ft2232_device_desc "Dual RS232-HS"
ft2232_layout jtagkey
ft2232_vid_pid 0x0403 0x6010

jtag_khz 2000

reset_config srst_only srst_pulls_trst

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

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 0x1 -expected-id $_CPUTAPID

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm7tdmi

$_TARGETNAME configure -event reset-init {
# disable watchdog
mww 0xfffffd44 0x00008000
# enable user reset
mww 0xfffffd08 0xa5000001
# CKGR_MOR : enable the main oscillator
mww 0xfffffc20 0x00000601
sleep 10
# CKGR_PLLR: 96.1097 MHz
mww 0xfffffc2c 0x00481c0e
sleep 10
# PMC_MCKR : MCK = PLL / 2 ~= 48 MHz
mww 0xfffffc30 0x00000007
sleep 10
# MC_FMR: flash mode (FWS=1,FMCN=60)
mww 0xffffff60 0x003c0100
sleep 100
}

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

#flash bank <driver> <base_addr> <size> <chip_width> <bus_width> <target_number> [<target_name> <banks> <sectors_per_bank> <pages_per_sector> <page_size> <num_nvmbits> <ext_freq_khz>]
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME at91sam7 0 0 0 0 $_TARGETNAME 0 0 0 0 0 0 0 18432

and got

Code: [Select]
Open On-Chip Debugger 0.4.0 (2010-02-22-19:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.berlios.de/doc/doxygen/bugs.html
2000 kHz
srst_only srst_pulls_trst srst_gates_jtag srst_open_drain
Warn : sam7x512.cpu: nonstandard IR mask
Info : max TCK change to: 30000 kHz
Info : clock speed 2000 kHz
Info : JTAG tap: sam7x512.cpu tap/device found: 0x3f0f0f0f (mfg: 0x787, part: 0xf0f0, ver: 0x3)
Info : Embedded ICE version 1
Info : sam7x512.cpu: hardware has 2 breakpoint/watchpoint units

after a long time of waiting for something to happen

Code: [Select]
target state: halted
target halted in Thumb state due to breakpoint, current mode: Supervisor
cpsr: 0x600000f3 pc: 0x00003ff1

And then nothing else happens, which I guess is expected since I didn't really tell it to do anything, correct?

Also I noticed that I need to disconnect my JTAG entirely before powering up my MCU or else I will get the error

Code: [Select]
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.

Is there any way to re-use OpenOCD without constantly physically disconnecting-reconnecting my JTAG cable?

Also 30000 KHz does seem to cause problems, 2000 KHz works
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: robots on March 11, 2011, 08:54:01 pm
You have to close openocd cleanly by telneting to it and issuing shutdown command.
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: frank26080115 on March 12, 2011, 05:34:57 am
thanks! I telnet-ed in and was able to write my .bin file, although it's a pain to do so through command line, surely there must be a way to make this simpler... I am unable to run the same commands from the .cfg file, putting

Code: [Select]
flash write_image erase "C:/Users/Frank/Documents/Projects/SuperCalculator/Code/SandBox/bin/lcd_test-flash.bin" 0x00100000 bin

into the .cfg file gives error "command requires more arguments", but in telnet, it will actually work.
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: robots on March 12, 2011, 12:59:13 pm
config file is a config file ... not script file.

You can issue commands on the commandline like this
openocd -f ./openocd.cfg -c "init" -c "flash write_image ........" -c "shutdown"
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: frank26080115 on March 13, 2011, 02:59:23 am
[quote author="robots"]config file is a config file ... not script file.

You can issue commands on the commandline like this
openocd -f ./openocd.cfg -c "init" -c "flash write_image ........" -c "shutdown"[/quote]

that didn't work, i ran

Code: [Select]
openocd -f "C:/Users/Frank/Documents/Projects/SuperCalculator/Code/SandBox/openocd.cfg" -c "init" -c "flash write_image erase unlock 'C:/Users/Frank/Documents/Projects/SuperCalculator/Code/SandBox/bin/lcd_test-flash.bin' 0x100000 bin" -c "shutdown"

and got
Code: [Select]
Open On-Chip Debugger 0.4.0 (2010-02-22-19:05)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.berlios.de/doc/doxygen/bugs.html
2000 kHz
srst_only srst_pulls_trst srst_gates_jtag srst_open_drain
Warn : sam7x512.cpu: nonstandard IR mask
flash write_image erase C:/Users/Frank/Documents/Projects/SuperCalculator/Code/SandBox/bin/lcd_test-flash.bin 0x00100000 bin: command requires more arguments
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: frank26080115 on March 13, 2011, 05:38:14 am
Spent some time and wrote a custom C# WinForm GUI for OpenOCD purely designed for writing files, handles launching OpenOCD and initiating Telnet connection in the background, problem solved
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: ian on March 18, 2011, 10:03:52 am
Hi Frank,

I'm glad you got it solved. Care to share :) It sounds like a great utility. I've been following eagerly, hoping it wasn't a hardware failure ;) I tested extensively with hardware loaned to me by a forum member, but you never know what is going to happen out in the wild.

You've done a lot of proving here and testing with bbv1, thank you so much. I'd like to give you a BBv2 as soon as they ship, would you please PM me your address?
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: frank26080115 on March 19, 2011, 01:16:12 am
Hi Ian



I'm slightly reluctant to share this GUI I made, it has many short comings, and I don't want to make the source code clean and neat and stuff. I also don't want to constantly look after it when people eventually find things wrong with it or want new features.

WIth that said, I'm uploading what it is at the moment. The binary and source are included.

The main focus of my GUI is to reduce repetitive actions by remembering the most recently used files, and to let people use Windows file open dialogs instead of typing file paths.

Only one instance of OpenOCD can be used at any given time, and Telnet will always use the localhost at port 4444 . Like I said, it's very customized to my own specific needs. The GUI essentially dumbs down OpenOCD to something like avrdude or pickit2, but probably with even less features.

There are some launch options, so you can call "OpenOCDHelperGUI.exe pathtobinaryfile.bin" from a makefile, which will auto-fill the path-to-flash-file textbox (but not immediantly begin the write operation). If the argument is a .cfg file, then the .cfg file is added to the list of .cfg files (it will not be considered a flash binary). Finally, if the argument is a .ini file, then the settings for the GUI will be loaded from the specified .ini file instead of the one that is stored in your AppData folder.

Oh, and OpenOCD must be in your PATH environmental variable

The "Show Info" button is supposed to display information about the flash memory of the microcontroller, it's kind of important to know what offset to write the binary image to.
Title: Re: Trouble Using OpenOCD for AT91SAM7XC512
Post by: wrljet on December 16, 2012, 05:38:38 pm
Thank you Frank, for that C# pgm.

Very helpful to me with Eclipse and OpenOCD with STM32.

-Bill

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01092106144session_write_close ( )...(null):0
20.01122237720ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01122238496Database_MySQL->query( ).../DatabaseHandler.php:119
40.05392377216Database_MySQL->error( ).../Db-mysql.class.php:273