2008年12月5日星期五

转贴:ARM Getting Started: Using USBprog and OpenOCD

http://www.geektalks.cn/staticpages/index.php?page=20080529200728776

Sun Ge

<sun_ge@yahoo.cn>
version 1.1
 
Figure: Quickly assembled AT91SAM7S development system.

Project Origin

A couple of weeks ago, I bought a chip of AT91SAM7S32 from OURAVR ― a local net shop and also a community for AVR/ARM related electronic design ― just a chip, because I could afford neither a evaluation board nor a JTAG adapter with USB interface. (Unfortunately my laptop only have USB ports for I/O, I am unable to use a relatively cheaper Wiggler-like JTAG device.)

So, after searching in my tool box, I found the following things:

  • a lot of AVR chips, including a ATMEGA32.

  • USB device chips: USBN9604 and some FTDI chips, but without a FT2232 which can support USB to JTAG bridge directly.

  • crystals, 74245 level shifter, solderless bread board, SMD to DIP convert boards, voltage regulator, USB socket, RCLs, adult videos, …

OK, that enough. I could make a mini development board by myself. And Benedikt Sauter provided us a wonderful tool ― USBprog, I once tried it as a good AVRISP MK2 Clone. It can also be programmed as a OpenOCD adapter for programming and debugging ARM microcontrollers.

If you are acquainted with AVR microcontroller, also have a USBprog or just a USBN9604 chip on hand, this article will give you a method to play with ATMEL ARM with the following advantages:

  • very low cost: less than 20 US dollars totally.

  • promptly available: you can build the whole system in a weekend.

But there are also disadvantages:

  • So far flash download speed of USBprog is much slower than Wiggler or FT2232 based JTAG device. (programming the whole 32KB flash of AT91SAM7S32 will cost about 200 seconds.)

Make a AT91SAM7S32 Development Board

Instead of making a PCB, we can solder AT91SAM7S32 on a QFP to DIP board, add other components on that PCB or on a bread board attached to it. Female pin headers can be soldered for those GPIO ports.

Figure: schematics of the AT91SAM7S32 mini development board.

Make a USBprog as OpenOCD Adapter

You can build a new USBprog just like me, or add a level shifter and a JTAG header on your exist USBprog. Before or after the electronic task, firmware for OpenOCD should be downloaded to ATMEGA32.

Figure: schematics of USBprog as a OpenOCD adapter.

 
Important
If USBprog cannot be recognized by Linux or OpenOCD software
  1. decoupling capacitor between VCC and GND is absolutely necessary for this high frequency circuit.

  2. substitute the 24MHz crystal by a 24MHz external oscillator.

  3. if use a 24MHz crystal for USBN9604 other than a oscillator, 1M Ohm resistor between XIN and XOUT is necessary.

Install GNU Tool Chain For ARM

We have a evaluation board and a JTAG now, next you would like to install a free cross compile and debug environment on your computer. Installation procedure is almost as same as AVR's, first fetch binutils-2.16, gcc-4.0.2, newlib-1.14.0, and gdb-6.6 source. Of course it's recommended to use the latest versions of these tools. Then uncompress these packages.

$mkdir [binutils-build] #In this way, we can keep the source code tree clean.
$cd [binutils-build]
$[binutils-source]/configure --target=arm-elf --prefix=[toolchain-prefix] \
--enable-interwork --enable-multilib
$make
$su -c 'make install'
$export PATH="$PATH:[toolchain-prefix]/bin"
$mkdir [gcc-build] #In this way, we can keep the source code tree clean.
$cd [gcc-build]
$su # you should become to root to execute the next configure script.
#[gcc-source]/configure --target=arm-elf --prefix=[toolchain-prefix] \
--enable-interwork --enable-multilib \
--enable-languages="c,c++" --with-newlib \
--with-headers=[newlib-source]/newlib/libc/include
$make
$su -c 'make install'
$mkdir [newlib-build] #In this way, we can keep the source code tree clean.
$cd [newlib-build]
$[newlib-source]/configure --target=arm-elf --prefix=[toolchain-prefix] \
--enable-interwork --enable-multilib
$make
$su -c 'make install'
$mkdir [gdb-build] #In this way, we can keep the source code tree clean.
$cd [gdb-build]
$[gdb-source]/configure --target=arm-elf --prefix=[toolchain-prefix]
--enable-interwork --enable-multilib
$make
$su -c 'make install'

Install OpenOCD

First fetch the source archive from SVN Repository, then compiles as following.

$cd trunk
$./configure --enable-usbprog
$make
$su -c 'make install'

An example project

As an example project, download and unpack at91sam7s_getting_started_1.0.zip from ATMEL. Edit Makefile, We should change two variables to the following values:

ERASE_FCT=rm -f
TARGET=AT91SAM7S32

I would like to add some lines for further use.

GDBINITFILE=gdbinit-$(OUTFILE_FLASH)
$(GDBINITFILE): $(OUTFILE_FLASH).elf
@echo "file $(OUTFILE_FLASH).elf" > $(GDBINITFILE)
@echo "target remote localhost:3333" >> $(GDBINITFILE)
@echo "monitor arm7_9 force_hw_bkpts enable" >> $(GDBINITFILE)
@echo
@echo "Use 'arm-elf-gdb -x $(GDBINITFILE)'"

Because we use a 16MHz crystal for main oscillator to generate 48MHz main clock, not a 18.432MHz one which was used by ATMEL's evaulation board, we should also edit lowlevel.c, change AT91C_BASE_PMC->PMC_PLLR to a different value:

AT91C_BASE_PMC->PMC_PLLR = AT91C_CKGR_USBDIV_1           |
AT91C_CKGR_OUT_0 |
(16 << 8) |

(AT91C_CKGR_MUL & (95 << 16)) |
(AT91C_CKGR_DIV & 16);

also edit include/AT91SAM7S-EK.h:

/*
#define AT91B_MAIN_OSC 18432000 // Main Oscillator MAINCK
#define AT91B_MCK ((18432000*73/14)/2) // Output PLL Clock (48 MHz)
*/
#define AT91B_MAIN_OSC 16000000 // Main Oscillator MAINCK

#define AT91B_MCK ((16000000*96/16)/2) // Output PLL Clock (48 MHz)
#define AT91B_MASTER_CLOCK AT91B_MCK


没有评论: