ToolChain Setup Ubuntu

From EdWiki

Install Sourcery CodeBench Lite - Linux

Install Eclipse

Install Java Runtime Environment (JRE)

Running Eclipse

Configuring Network Preferences

Installing C/C++ Hardware Debugging

Create a C Project called strcopy

Import mixed-c-and-asm program into the strcopy Project

Toolchain Prefix and Path

To make sure that the toolchain prefix and path are correct, Select Project > C/C++ Build > Settings > Cross Settings, prefix and Path fields are correct as entered in the Create a C Project called strcopy Tool command prefix and Tool command path.

GCC Compiler Options

Select Project > Properties. From the Properties for strcopy dialog, select Settings from the left windiw. In the Miscellaneous Sections of the Cross GCC Compiler we need to add these flags:

-c -fmessage-length=0 -c -mcpu=arm966e-s -mthumb-interwork -mapcs-frame -gdwarf-2
Cross GCC Options

GCC Assembler tool chain

Now, we need to add the assembler command for the Cross GCC assembler, as there is no Cross Assembler listed by default. We do this by selecting C/C++ Build > Settings > Cross GCC Assembler and specifying as in the command field.

Cross GCC Assembler Command

The GNU Assembler Documentation Says
as is primarily intended to assemble the output of the GNU C compiler gcc for use by the linker ld. Nevertheless, we've tried to make as assemble correctly everything that other assembelers for the same machine would assemble.

Unlike older assemblers, as is designed to assemble a source program in one pass of the source file. This has a subtle impact on the .org directive.

GCC Assembler Options

In the General Section of the Cross GCC Assembler, we need to set these Flags:

-Wall -mcpu=arm966e-s -mthumb-interwork -g3 -gdwarf-2 -adhlns="$<.lst"
Cross GCC Assembler Options

GCC Linker Options

The linker combines input files into a single output file. Each input file are in a special format known as an object file format. The output file is often called an executable. Every link is controlled by a linker script.

Before specifying the linker options, we must decide whether we are invoking the linker through GCC (arm-none-eabi-gcc) or the LD (arm-none-eabi-ld) command. In this tutorial we will invoke linker directly. To do this, we must specify the Cross GCC linker command as ld in the Command field of the C/C++ Build > Cross GCC Linker.

Cross GCC Linker Command

In the General Section of the C/C++ Build > Cross GCC Linker, Select (Check) “Do not Use Standard start files (-nostartfiles)” and “No shared libraries (-static)” options as shown in the following screen.

Cross GCC Linker Gen Options

And finally in the Miscellaneous Section of the C/C++ Build > Cross GCC Linker, we add the following linker flags:

-T"${ProjDirPath}/settings/str912flash.ld" -Map "${ProjDirPath}/Debug/"
Cross GCC Linker Misc Options

str912flash.ld is a linker script file. The main purpose of the linker script file is to describe how the sections in the input files should be mapped into the output file, and to control the memory layout of the output file.

The linker always uses a linker script. If we don't supply one ourself, the linker will use a default script that is compiled into the linker executable which may or may not be compatible to the ARM MCU used on the development board.

Here we are supplying our own linker script by using the -T command line option which will replace the default linker script and correctly maps the sections in the input files to the memory layout of the ARM MCU used on the development board (Olimex STR912 Board).

To give a required filename and extension for the final output file, Select C/C++ Build > Settings > Build Artifact and change the desired Artifact (output file) name and Artifact extension(output file).

Build Artifact Options

Building Project

Relax... We have almost configured the required settings, and it is time to Build the Project. From the main menu, Select Project > Build Project. If everything goes well, you will see in the console window something like the following:

Build Console Output

GDB, OpenOCD and Eclipse

To use OpenOCD with our development projects, we need to do more than just connecting the CEDT-USB-JTAG adapter hardware (dongle) to the development board and then starting the OpenOCD server. We need to configure OpenOCD server so that it knows about that adapter and board. We also want to connect OpenOCD to GDB using Eclipse GUI.

OpenOCD complies with the remote gdbserver protocol, and as such can be used to debug remote targets. Setting up GDB with OpenOCD involves several components:

  1. The OpenOCD server support for GDB needs to be configured.
  2. GDB's support for OpenOCD needs configurations.
  3. The Eclipse GUI environment will also needs to be configured such that both GDB and OpenOCD are integraed with in the IDE.

OpenOCD Project Setup

Download OpenOCD for CEDT-USB-JTAG (32-bit version only) and save it in the ~/Downloads directory. Once the download is completes, extract in your home directory.

To configure OpenOCD, select Run > External Tools > External Tools Configurations... from the main menu.

External Tools Configurations...

In the External Tools Configurations window, enter (browse to the) openocd executable as

Configuring OpenOCD

  • /home/USERNAME/openocd-0.5.0-linux/bin/openocd in the Location,
  • /home/USERNAME/openocd-0.5.0-linux in the Working Directory, and
  • -f interface/cedt-arm-jtag.cfg -f target/str912.cfg in the Arguments fields.

Next, Select Common tab in the same External Tools Configurations window and Select Externals Tools to Display in favourite menu as shown in the following screen.

Configuring OpenOCD

Make sure that Launch in background option is checked.

Next, select Apply followed by Close button.

Accessing OpenOCD without Sudo

On Linux, OpenOCD requires superuser privileges to communicate with your USB drivers. Please, follow the link Accessing Devices without Sudo to allow OpenOCD to access USB dongles with out superuser privileges.

Configuring the Debugger

To configure the Debugger, select Run > Debug Configurations... from the main menu.

Debug Configurations Menu

In the Debug Configurations window, select GDB Hardware Debugging from the left pane, and make sure that C/C++ Application, Project and Build Configuration fields are selected properly from the main tab as shown in the following screen.

Debug Configurations

In the same Debug Configurations window, select Debugger tab. In this window tab, specify :

Debugger Configurations
  • /home/USERNAME/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-gdb as GDB Command,
  • Check Use remote target option
  • Select Generic TCP/IP for JTAG Device,
  • localhost for Host Name and
  • 3333 for Port Number as shown in the screen.

Next, Select the Startup tab and enter the following Commands in the text window:

Debugger Startup Commands
monitor reset init
monitor halt
monitor arm7_9 dcc_downloads enable
monitor arm7_9 fast_memory_access enable
monitor sleep 500
monitor poll on
monitor flash protect 0 0 7 off
monitor flash erase_sector 0 0 7

Next, Select the Common tab and check Debug to Display in favourites menu as shown in the following screen.

Debugger Startup Commands

That’s it. We have completed the Debug Configurations. Click on Apply followed by Close button to complete the Debug Configurations.

Hooking up CEDT-USB-JTAG adapter and Development board

CEDT-USB-JTAG is a Dongle with a JTAG cable on one side (ribbon cable with 20-pin IDC connector) and a USB cable on the other.

  1. Connect the JTAG 20-pin ribbon cable to the CEDT-USB-JTAG Dongle and to the development board such as OLIMEX STR-E912. Be sure it is properly oriented and firmly connected.
  2. Connect a USB B-Type cable to the adapter's other end. The other end of the USB B-Type cable will go to the host which we are using to run OpenOCD and Eclipse.
  3. Connect a proper power (Voltage and Current rating) adapter cable to the development board.
  4. Power up the target board.

Unless you just let magic smoke escape, you are now ready to run the OpenOCD server so you can use CEDT-USB-JTAG to work with that development board.

Running OpenOCD

We have already configured OpenOCD, just select OpenOCD from the External Tools Tool Bar.

Run OpenOCD

OpenOCD Output

Note: OpenOCD will be running in the background, don’t terminate.

Launching the Debugger

To launch the debugger, select the Debug icon from the tool bar.

Configuring OpenOCD

When we launch the Debugger for the first time, eclipse tries to switch the Perspective from C/C++ to debug, select Remember my decision and click YES.

Configuring OpenOCD

The Debugger should break at C main function as we have configured it.

Configuring OpenOCD

Now you can use all the debugging commands like, single step, examine registers, examine data etc.

Resources and References


  1. STR91x Sample Projects
  2. CodeSourcery EABI toolchain
  3. Eclipse IDE for C/C++ Developers
  4. Mixed ARM C and Assembly Program


  1. CodeSourcery G++ Lite -- Getting Started Guide
  2. GNU Assembler Manual
  3. GNU GCC Manual
  4. GNU LINKER Manual
  5. Debugging with GDB
  6. An Introduction to GCC
  7. GNU Make
  8. OpenOCD User's Guide