Showing posts with label 0basics. Show all posts
Showing posts with label 0basics. Show all posts

Tuesday, September 2, 2008

Openocd and JTAG

Finally got jtag working for the LPC-H2148, the config file with the openocd sources didnt quite work. The config below works with the Olimex parallel port wiggler and the usb ocd tiny, using the current openocd source (svn) built against the current libftdi, but NOT libft2xx. (dont need either of course for the parallel port). Uncomment the relevant section depending on the interface.

Changing the 14765 to 12000 (starting from the openocd config file) and adding the calc_checksum helped greatly. I dont know what the board/chip is doing but it helps greatly (if you cant connect) to power cycle the board, press the reset button a time or two, and run openocd (openocd -f filename.cfg). Telnet into openocd telnet localhost 4444

If you compiled for flash then:

reset halt
flash write_image erase blink.elf
reset


If you compiled to run out of ram only:

reset halt
load_image blink.elf
resume 0x40000000




#daemon configuration
telnet_port 4444
gdb_port 3333

#Parallel Port Interface
#interface parport
#parport_port 0
#parport_cable wiggler
#jtag_speed 0

# OpenOCD JTAG TINY
#interface ft2232
#ft2232_device_desc "Olimex OpenOCD JTAG TINY"
#ft2232_layout "olimex-jtag"
#ft2232_vid_pid 0x15BA 0x0004
#jtag_speed 20

#delays on reset lines
jtag_nsrst_delay 200
jtag_ntrst_delay 200

# NOTE!!! LPCs need reset pulled while RTCK is low. 0 to activate
# JTAG, power-on reset is not enough, i.e. you need to perform a
# reset before being able to talk to the LPC2148, attach is not
# possible.

#use combined on interfaces or targets that can't set TRST/SRST separately
reset_config trst_and_srst srst_pulls_trst

#jtag scan chain
jtag_device 4 0x1 0xf 0xe

target arm7tdmi little 0 arm7tdmi-s_r4

working_area 0 0x40000000 0x4000 nobackup

#flash bank lpc2000 0x0 0x7d000 0 0 0 lpc2000_v2 14765
flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v2 12000 calc_checksum

Roll your own gcc

gcc is not the best, but widely used, works on most platforms, and you are far more likely to find information or help on the net than any other compiler. So why not use it right?

A good place for a pre-built is code sourcery. But if you want to build your own, there is really not much to it.


This works for 4.2.x not 4.3.x, just use 4.2.x




#IF WINDOWS
Go to http://www.mingw.org, find and download

MinGW=5.1.3.exe
MSYS-1.0.11-2004.04.30-1.exe

Install both
Run the Msys shell/prompt to continue as if on a native Linux system.
#ENDIF

#IF LINUX
Make sure you have texinfo, bison, and flex installed, as well as gcc, make and other typical programs
On ubuntu this would be

sudo apt-get install build-essential bison flex texinfo

Note the makeinfo error I am trying to avoid here is part of the texinfo package
#ENDIF

Most of this section is simply a list of the commands to type.

#IF LINUX
You probably dont run as root all the time so you may need to use a directory other than /arm or
as root create /arm and chown to your username so that you can finish the build as the user.
It wants to run from the path used to create it so think about where you want it and who you want
to use it. If you do all of this as root and keep it in /arm (and make it readable by everyone) everyone
can use it.
#ENDIF

Download http://ftp.gnu.org/gnu/gcc/gcc-4.2.2/gcc-core-4.2.2.tar.bz2
Download http://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.gz

ZZZ='--target=arm-thumb-elf --prefix=/arm'
mkdir /arm
cd /arm
tar xzvf /path/to/binutils-2.18.tar.gz
cd binutils-2.18
mkdir build
cd build
../configure $ZZZ

#IF WINDOWS AND SOMETIMES LINUX
edit the Makefile in this directory
Find and change the line from

MAKEINFO = /arm/binutils-2.18/missing makeinfo

to

MAKEINFO = /bin/makeinfo

#ENDIF

make all install

(this will take a while)

/arm/bin/arm-thumb-elf-as --version

GNU assembler (GNU Binutils) 2.18
...

Now binutils, the assembler, linker and other utilties is complete. If you only want to use assembly language this is all you need

To clean up the binutils build files

cd /arm
rm -rf binutils-2.18

On to gcc

cd /arm
tar xjvf /path/to/gcc-core-4.2.2.tar.bz2
cd gcc-4.2.2
mkdir build
cd build
../configure $ZZZ --disable-libssp
make all install

#IF WINDOWS
This will fail at some point with errors that look like

In file included from ../../gcc/libgcc2.c:35:
./tm.h:6:28: error: config/dbxelf.h: No such file or directory
...

It doesnt like the -I by itself in the xgcc command line
The culprit is in gcc/Makefile, a line that starts with

INCLUDES = -I. -I$(@D) -I$(srcdir) ...

Just get rid of that second include

INCLUDES = -I. -I$(srcdir) ...

Then start the build again

make all install

and it will complete this time
#ENDIF

/arm/arm-thumb-elf-gcc --version

arm-thumb-elf-gcc.exe (GCC) 4.2.2

To clean up the gcc build files

cd /arm
rm -rf gcc-4.2.2

#IF WINDOWS
You can exit msys and then copy the arm directory tree from
z:\msys\1.0\arm to z:\arm
(so that your binaries are in z:\arm\bin\)
z:\ is of course whatever directory you happen to be working with C:\ for example
#ENDIF

Welcome to lpcstuff

Welcome, I thought I would keep track of my Philips LPC2000 microcontroller development board experiments.

Currently I have a few boards from Olimex like the LPC-H2148, LPC-H2124, and LPC-H2129.