Autor: sadman

~ 31/12/08

Setting programming and debugging enviroment in Linux is frequently a serious problem to new linux/embedded programming users. So I decided to write a little HOWTO. I write this also for me, to not forget how to do this :).

I am very begging in embedded world so some my suggestions could be stupid. I Will try to explain some settings and describe some configuration possibilities. To more sophisticated configrations I send You to documentation.

Hardware

First we need some hardware. Programming without hardware I will describe in my next comming soon text :). I hope. I have OLIMEX ARM-USB-OCD JTAG and board with STM32 Cortex-M3 microcontroller.

This JTAG is quite cheap and good decision solution, becouse we only need an USB port to connect to our computer. This is important if we have laptop without serial port – my case. He has inself FTDI2232 chipset to connect to full RS232 port over our USB port. Note that connecting this input directly to UARTs outputs from STM32 will not be working, becouse RS232 is +-15V level, and we need something like MAX3232 to convert this levels to 3.3V. Both devices JTAG and RS232 converter are seened like composite device on USB bus.

Software

Needed software. We will use GNU Toolchain. Only available GNU Tollchain with support to Cortex-M3 is toolchain from here codesourcery. So we go to link download, then choose EABI, then IA32 GNU/Linux Installer. I recomended also download all the documentation, becouse it can be helpfull.

Second needed software will be OPENOCD. Openocd needs some library to speak with hardware connected through USB bus. We have two choices:
- libftdi
- libftd2xx

I prefere to use libftdi, becouse libfd2xx comes in binary form, and it is ugly to use black boxes :). So we need to make package with libftdi.

mkdir /home/sadman/src
wget http://www.intra2net.com/de/produkte/opensource/ftdi/TGZ/libftdi-0.15.tar.gz
gunzip -c libftdi-0.15.tar.gz | tar xopf -
cd libftdi-0.15
./configure --prefix=/usr
make
mkdir /home/sadman/tmp
make install DESTDIR=/home/sadman/tmp
cd /home/sadman/tmp
makepkg -l y -c n /home/sadman/pkg/libftdi-0.15-i686-1.tgz
installpkg /home/sadman/pkg/libftdi-0.15-i686-1.tgz

Next we need to download openocd from svn repository. To recover my configuration:

cd /home/sadman/src
mkdir openocd
svn co -r 1293 http://svn.berlios.de/svnroot/repos/openocd/trunk openocd
cd openocd
./bootstrap
./configure --enable-ft2232_libftdi --enable-usbprog
make
rm -r /home/sadman/tmp/*
make install DESTDIR=/home/sadman/tmp
makepkg -l y -c n /home/sadman/pkg/openocd-SVN1183-i686-1.tgz
installpkg /home/sadman/pkg/openocd-SVN1183-i686-1.tgz

To run openocd without root priviledges we need to add udev rule and add our username to new created group jtag.

echo "SYSFS{idProduct}==\"0003\", SYSFS{idVendor}==\"15ba\", MODE=\"666\",
 GROUP=\"jtag\"" >> /etc/udev/rules.d/45-ftdi2232-libftdi.rules
groupadd jtag
mcedit /etc/groups

After this we need logout. Now we can check that openocd sees our jtag. From few versions of openocd it goes with prepered config files. Those files are sperated to interface and target parts. This very simplifies configuration of openocd to our needs and safe us a lot of time. For example when something changes in configuration options with newer version, our call will be probably working:

openocd -f interface/olimex-arm-usb-ocd.cfg -f target/stm32.cfg -c init -c reset

In this case we want to connect with stm32 processor using Olimex ARM JTAG. Default configuration files are installed at OPENOCD_DESTDIR/lib/openocd/target and OPENOCD_DESTDIR/lib/openocd/interface directory. We can find there many interfaces and many microcontrollers. To get the most out-date documentation to openocd we need to do:

cd /home/sadman/src/openocd/doc
make pdf

Our documentation is in file openocd.pdf.

So now in our project Makefile we can add something like that:

flash_new: simple_io.bin
        $(OPENOCD) --file openocd_cm3.cfg -c "init" \
        -c "script openocd_cm3_flash.script"

where script schould contain:

## file openocd_cm3_flash.script

#hardware reset processor with halt
reset halt
#check target state
poll
#unprotect flash for writing
flash protect_check 0
#erasing all flash
stm32x mass_erase 0
#write simple_io.bin file to flash number 0
flash write_bank 0 simple_io.bin 0
#hardware processor restet with run
reset run
#shutdown openocd daemon
shutdown

Configuring debug

Before starting debugging we need make sure that openocd deamon is running and is accepting connections.  The simplest way to debug is run openocd like in the first time and run gdb.

openocd -f interface/olimex-arm-usb-ocd.cfg -f target/stm32.cfg -c init -c reset
arm-none-eabi-gdb

In new command prompt we need to write „target remote localhost 3333″. In this way we connect to openocd gdb server running on ours localhost interface on default  3333 port. We can use text version of gdb, but this not convinient. I recommended to use Insight or Embeded CDT Plugin to Eclipse. Below I will show correct configration of debugging under Eclipse.

First we need configure external tool which will start openocd.

external

Next we open Debug Configuration and fill all the fields like in this screenshots.

debug1

debug2

debug3

debug4

debug5

We can click Apply and Run. After this we should see screen like this (note: we need to click resume button in Eclipse):

debug_perspective

I hope that this text will be helpfull to somebody. I know that some things are missing. I plan to update this HOWTO with some Makefiles and .c sources. Any suggestions will be pleased.

Post tags:

4 komentarzy »

  1. Hey,
    Thanks for the tutorial: it’s very useful.

    We cannot click (zoom) on two images: the ones just before „We can click Apply and Run.” text.

    Thanks,
    Mike

    Comment by Mike — Listopad 10, 2009 @ 7:32 pm

  2. Fixed.

    Greetings.

    Comment by sadman — Listopad 16, 2009 @ 8:25 pm

  3. Thank you – this guide was very helpful getting Eclipse CDT debugging my Leaf Labs Maple board. (http://leaflabs.com)

    -adam

    Comment by Adam — Grudzień 11, 2010 @ 7:25 am

  4. Very nice inline explanation, very easy to understand. Thank Dude..

    Comment by Nubielab — Październik 15, 2011 @ 6:48 am

Kanał RSS z komentarzami do tego wpisu. TrackBack URL

Dodaj komentarz