Setting Up Development Environments – part 2

4 Linux Toolchain

In this chapter you will learn how to set up a free toolchain on Linux. The Operating System (OS) of choice when writing this guide was Ubuntu 11.04, but the tools should be distribution independent. The Tiny Gecko (TG) Starter Kit (STK) with the TG840F32 MCU was used as the target device, but the process is similar for other EFM32s.

Table 4.1. Software Versions (Linux)

14.1 J-Link

First we will install the J-Link software, which establish the connection between the PC and the STK. Get the beta software version for Linux from http://www.segger.com/cms/jlink-software.html

Extract it into e.g /opt/jlink/JLink_Linux_V422a and follow the instructions provided in the README file. (The syntax on Ubuntu is slightly different: $ sudo apt-get install libusb-1.0-0 was used for this tutorial.) To see if the installation was successful connect the STK and run the GDB server (version 422a was used for this tutorial).

opt/jlink/JLink_Linux_V422a/JLinkGDBServer -if SWD

The –if SWD option sets the server to use Single Wire Debug (SWD) rather than the default (JTAG). Instead of writing the full path the server every time, the JLink directory can be added to the PATH by adding

export PATH=$PATH:/opt/jlink/JLink_Linux_V422a

to your ~/.bashrc file and running

$ source ~/.bashrc

in order to update the settings for the current terminal, the server can now be run with

$ JLinkGDBServer -if SWD

If you want to reduce the required typing further, you can add an alias to your ~/.bashrc file

jlgdbs=’JLinkGDBServer -if SWD’

after updating using source again, you can run the server with

$ jlgdbs

The output should be something like the following

Example 4.1. JLinkGDBServer output when connected to a Tiny Gecko STK

SEGGER J-Link GDB Server V4.22

JLinkARM.dll V4.22 (DLL compiled Apr 5 2011 13:54:52)

Listening on TCP/IP port 2331
J-Link connected
Firmware: Energy Micro EFM32 compiled May 12 2011 10:25:44
Hardware: V7.00
S/N: 440000008
Feature(s): GDB

4.2 energyAware Commander

Now that we have established a connection with the kit, it is time to get the energyAware Commander from http://www.energymicro.com/downloads/software. The energyAware Commander will be used to flash the STK with the binaries we compile. The STK can only communicate with one program at the time, so the GDB server has to be shut down before running the eACommander with

$ ./eACommander

Connect to the STK by pressing the connect button in the upper left corner.
Figure 4.1. Connecting to the kit

2When connected, information about STK will be displayed.

Figure 4.2. Information about the kit.

3

Navigate to Demos (menu on the left) and run the Blink demo. The LED marked USER LED should be blinking. Binaries can be downloaded to the EFM32 through the Flash interface in the menu on the left.

4.3 Codesourcery WorkBench Lite Edition

Now that we can download binaries to the STK, it is time to try and compile our own. For this we will use the Codesourcery WorkBench Lite Edition, which is a command line interface based on the GNU tool chain. In particular, it has the GCC compiler and the GDB debugger. Get the software from http://www.codesourcery.com/sgpp/lite/arm/portal/subscription3053

version 2011.03 was used for this tutorial. Get the TAR archive – extract it to e.g. /opt/codesourcery/ and create the following alias in your ~/.bashrc file.

export PATH=$PATH:/opt/codesourcery/arm-2011.03/bin’

To check if we are able to compile, download the energyAware Starter Kit (STK) Board Support Library and Example Code as well as EFM32 CMSIS from http://www.energymicro.com/downloads/software. Extract the files to ~/efm/. You should now have three folders called boards, CMSIS and emlib in your ~/efm folder. Move to the Codesourcery version of the blink example

$ cd ~/efm/boards/EFM32GG_STK3300/examples/blink/codesourcery

In the Makefile, change the LINUXCS to point to where you placed Codesourcery

LINUXCS = /opt/codesourcery/arm-2011.03/

Compile using the linux program make, which executes the tasks specified in the Makefile

$ make -f Makefile.blink

Upload the resulting binary ~/efm/boards/EFM32GG_STK3300/examples/blink/codesourcery/exe/

blink.bin with the energyAware Commander.

Figure 4.3. Flashing the MCU

4

4.4 Debugging using GDB

Close eACommander if it is running and start the GDB server

$ JLinkGDBServer

In order to start GDB correctly create the file ~/efm/gdbinit which should contain

target remote :2331
set tdesc filename ../CortexCpuRegs/target.xml
set mem inaccessible-by-default off
set remote memory-read-packet-size 1200
set remote memory-read-packet-size fixed
mon speed 4000
mon endian little
mon reset 1
tbreak main
cont

Edit ~/.bashrc to include the alias

alias agdb=’arm-none-eabi-gdb -x ~/efm/gdbinit’

arm-none-eabi-gdb is in the same directory as arm-none-eabi-gcc and was therefore made available by extending the PATH above. The -x ~/efm/gdbinit is to initialize the debugger correctly. Open a new terminal and move to the blink exe folder

$ cd ~/efm/boards/EFM32GG_STK3300/examples/blink/codesourcery/exe

Run GDB

$ agdb blink.out

Figure 4.4. A GDB session with GDB on the right and the server on the left

5

Now you can use GDB as usual, for instance, try to continue
(gdb) c
To break press Ctrl+c. To single step
(gdb) s
Execute next statement
(gdb) n
To see the content of the CPU registers
(gdb) info registers
To see the source code for upcoming instructions
(gdb) list
To see the disassembly for recent and upcoming instructions
(gdb) disassemble
To see the stack
(gdb) info stack
Get help
(gdb) help

4.5 Eclipse (Optional)

If an IDE is preferred over a text editor, makefiles and GDB, then Eclipse is a good alternative. Application Note 23 from http://www.energymicro.com/downloads/application-notes explains how to set up Eclipse on Windows. The process is similar on Linux, but some tips will be outlined here. Get Eclipse IDE for C/ C++ Linux Developers from eclips.org or, in Ubuntu, type

Start Eclipse (version 3.5.2 used here)

$ eclipse

Set ~/efm/boards/EFM32GG_STK3300/examples/ as your workspace when prompted. To find out where to copy the contents of EmbSys and Zylin (from the zip file of an0023) type

$ whereis eclipse

Ubuntu 11.04 gave the following result

eclipse: /usr/bin/eclipse /etc/eclipse.ini /usr/lib/eclipse
/usr/share/eclipse /usr/share/man/man1/eclipse.1.gz

/usr/share/eclipse is the folder of interest. Follow an0023 to complete the setup of Eclipse. It is not necessary to change make into cs-make, the usual GNU Make will suffice. Since we have already used the Makefile to compile a project, no further changes has to be made to it. If Eclipse cannot find programs that should be available in the PATH or by aliases, try to use full paths instead like

/opt/codesourcery/arm-2011.03/bin/arm-none-eabi-gdb 

and add the initialize command as explained in an0023. Versions does not seem to be a problem on Linux. Both the versions used in an0023 and the easiest to get hold of on Ubuntu 11.04 at the time of writing (listed in Table 4.1 ) worked fine.

Energy Micro University is a program developed by Energy Micro to encourage learning and to help institutions develop their own programs for teaching microcontroller development. To download learning materials in pdf, please click here: Energy Micro University Program

For technical questions about this project, please use our support forum

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s