PSAS/ OlimexLPC2148Setup

Background Reading and Useful Links:

General Physical Setup:

Setup under Linux

Alternate Setup under Debian Linux (courtesy of Bdale Garbee, thanks Bdale!)

Fetch upstream bits, and populate a Dist/ directory

   export MYSRCPATH=/home/bdale/src/cross-tools
   export MYPREFIX=/opt/cross

   mkdir -p $MYSRCPATH/Dist
   cd $MYSRCPATH/Dist

   wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.2.1/gcc-4.2.1.tar.bz2
   wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.2.1/gcc-4.2.1.tar.bz2.sig
   gpg --verify gcc-4.2.1.tar.bz2.sig

   wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2
   wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2.sig
   gpg --verify binutils-2.17.tar.bz2.sig

   wget ftp://ftp.gnu.org/gnu/gdb/gdb-6.6.tar.bz2
   wget ftp://ftp.gnu.org/gnu/gdb/gdb-6.6.tar.bz2.sig
   gpg --verify gdb-6.6.tar.bz2.sig

   wget ftp://sources.redhat.com/pub/newlib/newlib-1.15.0.tar.gz

   wget http://www.gnuarm.com/t-arm-elf

Unpack upstream bits, and prepare build environment. Resurrecting the "one-tree" script would make this more efficient, but compile cycles are cheap enough that it's probably not worth worrying about...

   cd $MYSRCPATH

   tar xvjf Dist/binutils-2.17.tar.bz2
   tar xvjf Dist/gcc-4.2.1.tar.bz2
   tar xvjf Dist/gdb-6.6.tar.bz2
   tar xvzf Dist/newlib-1.15.0.tar.gz
   cp Dist/t-arm-elf gcc-4.2.1/gcc/config/arm/t-arm-elf

Resolve build dependencies (incomplete)

   sudo apt-get install texinfo libexpat1 libexpat1-dev

Build it all...

   mkdir -p $MYSRCPATH/target/arm-elf/binutils
   cd $MYSRCPATH/target/arm-elf/binutils
   ../../../binutils-2.17/configure \
           --target=arm-elf --prefix=$MYPREFIX \
           --enable-interwork --enable-multilib --with-float=soft
   make all
   sudo make install

   export PATH=$PATH:$MYPREFIX/bin

   mkdir -p $MYSRCPATH/target/arm-elf/gcc
   cd $MYSRCPATH/target/arm-elf/gcc
   # following must be run as root to allow dir creation in /opt/cross!
   sudo ../../../gcc-4.2.1/configure \
           --target=arm-elf --prefix=$MYPREFIX --enable-interwork \
           --enable-multilib --with-float=soft \
           --enable-languages="c,c++" --with-newlib \
           --with-headers=../../../newlib-1.15.0/newlib/libc/include
   make all-gcc
   sudo make install-gcc

   mkdir -p $MYSRCPATH/target/arm-elf/newlib
   cd $MYSRCPATH/target/arm-elf/newlib
   ../../../newlib-1.15.0/configure --target=arm-elf --prefix=$MYPREFIX \
           --enable-interwork --enable-multilib --with-float=soft
   make all
   # pass PATH into sudo environment so /opt/cross/bin is included
   sudo env PATH=$PATH make install

   cd $MYSRCPATH/target/arm-elf/gcc
   make all
   sudo make install

   mkdir -p $MYSRCPATH/target/arm-elf/gdb
   cd $MYSRCPATH/target/arm-elf/gdb
   ../../../gdb-6.6/configure --target=arm-elf --prefix=$MYPREFIX \
            --enable-interwork --enable-multilib --with-float=soft
   make all
   sudo make install

Get the Olimex USB jtag dongle working with the Debian openocd package

   mkdir -p $MYSRCPATH/jtag
   cd  $MYSRCPATH/jtag

   sudo apt-get install openocd

   # create lpc2xxx_armusbocd.cfg containing content found below, which
   # was copied from somewhere I neglected to make note of, and may not
   # be *entirely* correct for this target yet!

   # power up target board, *then* the Olimex USB jtag widget, then run:
   sudo openocd -f ./lpc2xxx_armusbocd.cfg
           telnet localhost 4444
                   poll
                   halt
                   poll

Take gdb for a quick test drive

   cd  $MYSRCPATH/jtag
   # create init.gdb file containing
           target remote localhost:3333
           # monitor arm7_9 sw_bkpts enable
           monitor poll

   arm-elf-gdb --command init.gdb
            info registers

Setup on Windows 2K/XP

First, install the Olimex ARM-USB-OCD drivers and connect to the LPC2148.

  1. You can install the 2006 drivers off the Olimex CD, but we're going to recommend you grab the 2007 drivers from the web. It's actually attached below, but it might not be the absolute latest version - for that, see: http://openocd.berlios.de/web/
    1. After you install the drivers, plug in the ARM-USB-OCD. Windows will then freak out and ask you a bzillion times for drivers. This is normal. Keep pointing the new hardware wizard to: C:\Program Files\openocd-2007re141\driver\arm_usb_ocd
    2. Overwrite the lpc2xxx_armusbocd.cfg file in C:\Program Files\openocd-2007re141\bin\configs\ with the one that Dave reworked for us (see below!).
    3. Once this stuff is running, it's helpful to make sure that you can communicate with the LPC2148 via OpenOCD. Plug in the hardware (make sure you've read the proper order in which to do this), then in the bin directory of the openocd folder run ./openocd-ftd2xx.exe -fconfigs/lpc2xxx_armusbocd.cfg and you should see something like the following. If you don't see something similar, something isn't working. BASH-3.00$ ./openocd-ftd2xx.exe -fconfigs/lpc2xxxarmusbocd.cfg Info: openocd.c:86 main(): Open On-Chip Debugger (2007-04-16 19:30 CEST) Info: configuration.c:50 configurationoutputhandler(): Command swbkpts not found Warning: arm79common.c:685 arm79assertreset(): srst resets test logic, too
  2. Next, type telnet localhost 4444 to telnet to port 4444 and type "flash banks" and/or "poll", and you should see something like this (yours may look different): Open On-Chip Debugger

flash banks #0: lpc2000 at 0x00000000, size 0x0007d000, buswidth 0, chipwidth 0 poll target state: halted target halted in ARM state due to debug request, current mode: Undefined cpsr: 0x800000db pc: 0x00000034

  1. Assuming you see something like this, then you have OpenOCD communicating with the programmer, which is communicating with the MCU. That's good!

Next, let's try programming an already compiled program which will blink the LEDs on the board!

  1. Grab the oocd_flash_lpc2148.script from below and put it in the scripts directory in the openocd folder.
  2. Switch the binary that the script points to in the script file (and don't forget to switch it back if you do freertos stuff later!): #flash write 0 scripts/lpc2148_freertos.bin 0x0 flash write 0 scripts/main.bin 0x0
  3. Download http://www.olimex.com/dev/soft/arm/projects_eclipse_web.rar.
  4. Extract main.bin.
  5. Edit config/lpc2xxx_armusbocd.cfg and uncomment the target_script 0 reset scripts/oocd_flash_lpc2148.script line.
  6. Startup (or restart) openOCD like above.
  7. In another terminal, startup OpenOCD (telnet localhost 4444) and type halt. In the OpenOCD terminal, you should see some stuff saying that it's erasing the flash and re-programming it. You should not see the word "error" :)
  8. Switch the DIP switch pin 1 to off (which is away from the 'dash' on the case) and hit the reset button.
  9. The MCU should reset and start blinking the lights!!!!! OMG!! OMG!!!111!

OK, you're ready to start compiling.

  1. You'll need to the GNUARM tools for Windows/Cygwin. You can get that from http://www.gnuarm.org/ or you can grab it from the ARM-USB-OCD CD.
  2. Install that and restart all your terminals so the path updates.
  3. Download FreeRTOS (attached to this page, see above) and unzip it it.
  4. Edit the Makefile and add ' $(OBJCOPY) $(PROJECT).elf -O binary $(PROJECT).bin' right below (mind the TAB!) $(OBJCOPY) $(PROJECT).elf -O ihex $(PROJECT).hex around line 93 of the makefile. This will make a .BIN out of the .HEX.
  5. Also, while you're at it, fix a Makefile bug that they left for us by changing PROJECT=lpc4148_freertos to PROJECT=lpc2148_freertos. :)
  6. Now switch the binary that the config script points to in the script file: flash write 0 path/to/lpc2148_freertos.bin 0x0
    1. Go ahead and switch the JTAG switch back to 'ON' on the DIP switch and hit reset.
    2. In another terminal, startup OpenOCD (telnet localhost 4444) and type halt. In the OpenOCD terminal, you should see some stuff saying that it's erasing the flash and re-programming it. You should not see the word "error" :)
    3. Switch the DIP switch pin 1 to off (which is away from the 'dash' on the case) and hit the reset button.
    4. The MCU should reset and start blinking the lights!!!!! Again, "OMG!! OMG!!!111!".

Final notes:

Setting up Eclipse + GDB (initial instructions, to be revised and elaborated on)

Install Necessary eclipse Gallaleo/Europa/v3.2 plugins:

Zylin Plugin: Install the Zylin plugin, using the eclipse software update functionality, per instructions given here: http://opensource.zylin.com/embeddedcdt.html

  1. startup eclipse, make sure it's version Gallaleo/v3.2/Europa
  2. create FreeRTOS eclipse project
    1. new project
    2. choose C++ Project
    3. choose "Makefile Project", and "--other toolchain--"
    4. select the directory with the FreeRTOS source code (top part of the prompt)
  3. goto project menu, make sure build automatically is unchecked
  4. select properties on newly created project

    1. select C/C++ build
    2. select "Discovery options"
    3. Find compiler invocation command and change it to arm-elf-gcc
    4. got to settings section
    5. check "GNU Elf Parser"
  5. to setup a debug config

    1. Goto debug and open debug dialog
    2. double click Embedded debug (Native)
    3. select elf file of program you want to debug
    4. goto debugger tab, remove .gdbinit reference
    5. replace debugger (gdb) with arm-elf-gdb
    6. goto commands tab and paste in the following:

SPECIAL NOTE: the following command list includes line breaks and underscores that markdown may or may not display correctly. Click on "Edit" at the top of this page, and view the source for this page, then copy and paste the following commands - with the line breaks - into the commands tab of the open debug dialog. Hint: if you see eleven lines of code here, and not one giant paragraph, and can verify that the "softresethalt" includes the underscores, then you can just copy and paste this code as-is into the commands tab.

For newer versions of openocd

target extended-remote localhost:3333
monitor reset
monitor sleep 500
monitor poll
monitor soft_reset_halt
monitor gdb_breakpoint_override enable
monitor mww 0xE01FC040 0x0001
monitor mdw 0xE01FC040
break main
load
continue

For older versions of openocd

target extended-remote localhost:3333
monitor reset
monitor sleep 500
monitor poll
monitor soft_reset_halt
monitor arm7_9 force_hw_bkpts enable
monitor mww 0xE01FC040 0x0001
monitor mdw 0xE01FC040
break main
load
continue

Hit the "Debug" button, making sure that openOCD is already running in the background.


Tested with release 260 of OpenOCD. Proably wont work with pre r189 releases.

ARM-USB-OCD Configuration File: lpc2xxx_armusbocd.cfg

#daemon configuration
telnet_port 4444
gdb_port 3333
#interface
interface ft2232
ft2232_device_desc "Olimex OpenOCD JTAG"
ft2232_layout "olimex-jtag"
ft2232_vid_pid 0x15BA 0x0003
jtag_speed 3
#use combined on interfaces or targets that can't set TRST/SRST separately
#reset_config trst_and_srst separate
reset_config trst_and_srst srst_pulls_trst
#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
jtag_device 4 0x1 0xf 0xe
#ft2232_latency 10

#target configuration
daemon_startup reset
#target <type> <startup mode>
#target arm7tdmi <reset mode> <chainpos> <endianness> <variant>

#target arm7tdmi little run_and_init 0 arm7tdmi-s_r4
target arm7tdmi little run_and_init 0
run_and_halt_time 0 30

#target_script 0 reset oocd_flash_lpc2148.script

working_area 0 0x40000000 0x80000 nobackup
#flash configuration
flash bank lpc2000 0x0 0x7D000 0 0 0 lpc2000_v2 14765 calc_checksum

#arm7_9 swbkpts enable
# For more information about the configuration files, take a look at:
# http://openfacts.berlios.de/index-en.phtml?title=Open+On-Chip+Debugger

Tested with release 260 of OpenOCD. Proably wont work with pre r189 releases.

ARM-USB OCD FLashing Script: oocd_flash_lpc2148.script

#
# The following commands will be executed on
# reset (because of run_and_init in the config-file)
# - wait for target halt
# - erase memory
# - flash content of file main.bin into target-memory
# - shutdown openocd
#
# created by Martin Thomas
# http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects
# based on information from Dominic Rath
#
halt
arm7_9 dcc_downloads enable
wait_halt
sleep 10
poll
mdh 0x0 100
flash probe 0
# erase first bank only:
flash erase 0 0 26
mdh 0x0 100
flash write 0 scripts/lpc2148_freertos.bin 0x0
#flash write 0 scripts/main.bin 0x0
mdh 0x0 100
reset run
sleep 10
#shutdown

Tested with pre release-188 of openOCD - proably won't work with r189 or later

ARM-USB-OCD Configuration File: lpc2xxx_armusbocd.cfg

#daemon configuration
telnet_port 4444
gdb_port 3333
#interface
interface ft2232
ft2232_device_desc "Olimex OpenOCD JTAG A"
ft2232_layout "olimex-jtag"
ft2232_vid_pid 0x15BA 0x0003
jtag_speed 3
#use combined on interfaces or targets that can't set TRST/SRST separately
#reset_config trst_and_srst separate
reset_config trst_and_srst srst_pulls_trst
#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
jtag_device 4 0x1 0xf 0xe
#target configuration
daemon_startup reset
#target <type> <startup mode>
#target arm7tdmi <reset mode> <chainpos> <endianness> <variant>
target arm7tdmi little run_and_init 0 arm7tdmi-s_r4
run_and_halt_time 0 30
#target_script 0 reset scripts/oocd_flash_lpc2148.script
working_area 0 0x40000000 0x40000 nobackup
#flash configuration
flash bank lpc2000 0x0 0x7D000 0 0 lpc2000_v2 0 14765 calc_checksum
arm7_9 swbkpts enable
# For more information about the configuration files, take a look at:
# http://openfacts.berlios.de/index-en.phtml?title=Open+On-Chip+Debugger

Tested with pre release-188 of openOCD - proably won't work with r189 or later

ARM-USB OCD FLashing Script: oocd_flash_lpc2148.script

#
# The following commands will be executed on
# reset (because of run_and_init in the config-file)
# - wait for target halt
# - erase memory
# - flash content of file main.bin into target-memory
# - shutdown openocd
#
# created by Martin Thomas
# http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects
# based on information from Dominic Rath
#
arm7_9 dcc_downloads enable
wait_halt
sleep 10
poll
flash probe 0
# erase first bank only:
flash erase 0 0 26
flash write 0 scripts/lpc2148_freertos.bin 0x0
#flash write 0 scripts/main.bin 0x0
reset run
sleep 10
shutdown

Attachments: