OpenOCD for AT91SAM7SE - Part 2
Configuring the JTAG Adapter
In order to get OpenOCD up and running, we must configure the JTAG interface. Without this, OpenOCD will start, print a few error messages and stop.
Open On-Chip Debugger 0.6.0-rc1 (2012-08-08-20:04) Licensed under GNU GPL v2 For bug reports, read http://openocd.sourceforge.net/doc/doxygen/bugs.html Runtime Error: embedded:startup.tcl:47: Can't find openocd.cfg in procedure 'script' at file "embedded:startup.tcl", line 47 Error: Debug Adapter has to be specified, see "interface" command in procedure 'init'
When started without any command line options, OpenOCD expects its configuration in a file named openocd.cfg, located in the current directory. Let's create this file, using a text editor.
Selecting the Interface
The first thing we need to tell OpenOCD in this file is the name of the interface. This depends on the JTAG adapter you are using. For most USB JTAG adapters based on FTDI chips, this will be:
For the Turtelizer support package, this is slightly different:
You may run into a problem here. Some time ago the OpenOCD development team decided not to provide any official binaries anymore. They offer the source code only, expecting the vendor of the JTAG hardware to build the binaries. All supported interfaces are optionally selected during this build stage and therefore the binary you received from somewhere may not support your specific JTAG hardware.
Luckily, if the specified interface is not supported, OpenOCD will list all known interfaces
The following debug interfaces are available: 1: parport 2: ft2232 3: ftdi 4: usb_blaster 5: amt_jtagaccel 6: gw16012 7: presto 8: usbprog 9: jlink 10: vsllink 11: rlink 12: ulink 13: arm-jtag-ew 14: stlink
If your's is not included, ask your JTAG hardware vendor for the right binary. Btw., the list above has been retrieved from the binary offered at www.freddiechopin.info. Freddie's binary distributions for Windows PCs are most complete and highly recommended.
Selecting the Layout
Next, we must specify the interface layout. The reason is, that only the main JTAG signals are at fixed pins of the FTDI chip. Selecting pins for additional I/Os like reset lines or LEDs is left to the manufacturer. Layouts are currently hard coded in the OpenOCD binary and selected with the ft2232_layout configuration. For the Turtelizer 2, add the following line to openocd.cfg.
Since OpenOCD version 0.6.0 it is possible to specify the pin layout in the configuration file. But this hadn't been documented yet. Freddie Chopin was so kind to add two new configuration files for Turtelizer 2, which make use of this new feature. One is for Rev-B and the other for Rev-C adapters. By the time we will try to test this new feature.
Selecting the USB Device
Saving our two lines in openocd.cfg (interface and layout) and trying to run OpenOCD will still fail with
Error: neither device description nor serial number specified Error: please add "ft2232_device_desc
" or "ft2232_serial " to your .cfg file in procedure 'init'
OpenOCD needs to know, which USB device it should connect to. You may either specify the interface description or the devices serial number here. When using Turtelizer 2, add the following line to openocd.cfg:
ft2232_device_desc "Turtelizer JTAG/RS232 Adapter"
Saving this and trying to run OpenOCD again should give you an output similar to:
Info : only one transport option; autoselect 'jtag' Info : device: 4 "2232C" Info : deviceID: 67354056 Info : SerialNumber: TLVE8EUJA Info : Description: Turtelizer JTAG/RS232 Adapter A Error: An adapter speed is not selected in the init script. Insert a call to adapter_khz or jtag_rclk to proceed. in procedure 'init'
OpenOCD still terminates, but we will not test your patience any further. The next step will solve this final issue.
Just one more hint. If you look to the output above, you will probably notice the serial number. This is a unique ID, which may be used instead of the device descriptor. You will need this if you are attaching more than one Turtelizer to the same PC:
Selecting the Initial Adapter Speed
Unlike other interfaces like RS-232 or Ethernet, JTAG does not define any standardized speeds. Uploading large binaries to your target board can become quite annoying, so you always want to run at the highest possible speed. This, however, is limited by two factors:
- Maximum speed of the JTAG adapter
- Maximum speed of the target board
The latter is the critical part, which requires further evaluation. Most ARM CPUs start running at a special slow clock. This is also true for the EIR, which initially uses the 32kHz oscillator. Usually the bootloader will reconfigure the clocks to let the CPU run at full speed. But when the CPU is controlled via JTAG, the bootloader may not have a chance to execute or may be completely absent. On the other hand, many ARM CPUs cannot handle JTAG clock frequencies much higher than the CPU clock.
The good news first: There is a mechanism called adaptive clocking, where the CPU returns the JTAG clock on a separate pin. This signal is used by the JTAG adapter to synchronize its output clock. OpenOCD supports this mode, when the following is given in the configuration file:
It will set the JTAG clock speed to 3MHz and automatically adjust it to lower speeds, if required.
Now some bad news. First of all, Turtelizer doesn't support this feature. Simply because the FT2232D used in this adapter doesn't support it. There are other adapters based on the later FT2232H, which do support adaptive clocking. But still, they are not able to synchronize down to the full range. It is still required to "manually" adjust the clock. Well, and the final show stopper is the AT91SAM7SE CPU, which neither supports adaptive clocking.
We will solve this by starting at a low frequency of 8kHz. Later we will use OpenOCD to bring up the PLL, run the CPU at full speed and increase the Turtelizer's JTAG speed to its maximum. Add the following line to openocd.cfg:
For completeness, here is the contents of openocd.cfg we got so far:
interface ft2232 ft2232_layout turtelizer2 ft2232_device_desc "Turtelizer JTAG/RS232 Adapter" adapter_khz 8
If using the Turtelizer 2 support package, replace the first line with
Starting OpenOCD should now result in the following output and this time OpenOCD will no longer terminated with an error.
Open On-Chip Debugger 0.6.0-rc1 (2012-08-08-20:04) Licensed under GNU GPL v2 For bug reports, read http://openocd.sourceforge.net/doc/doxygen/bugs.html Info : only one transport option; autoselect 'jtag' 8 kHz Info : device: 4 "2232C" Info : deviceID: 67354056 Info : SerialNumber: TLVE8EUJA Info : Description: Turtelizer JTAG/RS232 Adapter A Info : clock speed 8 kHz Warn : There are no enabled taps. AUTO PROBING MIGHT NOT WORK!! Warn : AUTO auto0.tap - use "jtag newtap auto0 tap -expected-id 0x3f0f0f0f ..." Warn : AUTO auto0.tap - use "... -irlen 4" Warn : gdb services need one or more targets defined
Of course, your output will slightly vary. But in general you can see, that OpenOCD automatically switches to auto probing and even suggest to add jtag newtap to our configuration file. You will here more about this in the third part.