Table of Contents

1. Introduction
2. Compiling and executing the example
3. Converting and interpreting the traces
4. Debugging using WSim and Insight/GDB

1. Introduction

This chapter presents the LEDs (Light Emitting Diodes) example. It is a very simple application written for the WSN430 hardware platform, in which LEDs are turned on and off at variable time intervals. The purpose of this example is to show you how to execute a program using WSim, how to convert the traces generated by the simulator into a human readable format and how to debug your program using Insight/GDB.

2. Compiling and executing the example

If you are using the Worldsens Live CD, go to /opt/worldsens/examples/wsn430-leds. If not, go to $WSIM_FOLDER/examples/wsn430/wsn430-leds and type:

[wsn430-leds]$ make

You should see:

msp430-gcc -mmcu=msp430x1611 -O2 -Wall -g   -c -o main.o main.c
msp430-gcc -mmcu=msp430x1611 -o wsn430-leds.elf main.o
msp430-objcopy -O ihex wsn430-leds.elf wsn430-leds.a43
msp430-objdump -dSt wsn430-leds.elf >wsn430-leds.lst

If you are not using the Worldsens Live CD and you see an error, make sure all the tools are in your $PATH.

Once the example is compiled, you can execute it using WSim with the following options:

  • ui: to show the user interface (i.e. the LEDs blinking).
  • trace: write simulator traces in a file (wsim.trc).
  • mode: WSim mode (time, insn or gdb); if this is not specified, WSim will run forever.
  • modearg: if mode is time or insn, then this option will specify the simulation time in nanoseconds or number of instructions.

The command to type is therefore the following (expected output is included below):

[wsn430-leds]$ wsim-wsn430 --ui --trace --mode=time --modearg=100000000000 wsn430-leds.elf
WSim 0.82cvs, copyright 2005, 2006, 2007 Worldsens
[Note]The mode option

As explained above, when the mode option is not used, simulation time is unlimited. It is important to note that, in this case, trace data are kept in a buffer of relatively large size (approx. 4 MB). Therefore, should the user interrupt the simulation (killall -USR1 wsim-wsn430), they should expect the trace files to be empty.

Snapshot of the execution of the LEDs example

Figure III.1. Snapshot of the execution of the LEDs example

3. Converting and interpreting the traces

Simulation traces are written in a file called wsim.trc, if the trace option was used. The trace file records interruptions, blinking frequency for each of the three LEDs, clock frequencies, power mode changes, serial port information etc. However, this information is not readily available, since it is recorded in binary format. This is why it first needs to be converted to a human readable form. To do so, we will use a tool called WTracer, which is part of the Worldsens tool suite. After having executed the LEDs example, type the following:

[wsn430-leds]$ wtracer --in=wsim.trc --format=gplot

You should now have a new file, in Gnuplot format. The Gnuplot utility will use this file to generate nice plots of the recorded information (one EPS file per type of data). To do so, type the command:

[wsn430-leds]$ cat | gnuplot

The files resulting from this procedure are:,,,,,,,,,,,, However, since this simple example only makes use of LEDs, the LED files are the only ones relevant. They show the LED blinking frequency during the entire simultation time. The file for LED 1 is included below, in Figure III.2, “Trace of LED 1”.

Trace of LED 1

Figure III.2. Trace of LED 1

4. Debugging using WSim and Insight/GDB

WSim understands the GDB remote protocol to drive the simulation engine. The simulator can be started using the --mode=gdb parameter to use this functionality. The following steps should be followed in order to debug an application using WSim and Insight/GDB:

  1. Start a simulation in debug mode. WSim will stop right after machine creation and will wait on the default port (TCP 2159) until a connexion is made from a remote debugger that implements the same target architecture (GDB must be compiled as a cross-debugger for the target architecture):

    [wsn430-leds]$ wsim-wsn430 --ui --trace --mode=gdb wsn430-leds.elf
  2. Launch Insight/GDB and load the ELF file as shown below (File menu --> Open):

    First debugging snapshot

    Figure III.3. First debugging snapshot

  3. Connect to the WSim simulation as shown below (Run menu --> Connect to target):

    Second debugging snapshot

    Figure III.4. Second debugging snapshot

    Once you click OK, you should see the following:

    Third debugging snapshot

    Figure III.5. Third debugging snapshot

  4. Start the execution by pressing the "Run" button (upper left corner). Don't worry about breakpoints, two of them are automatically set for you: one in the beginning of the main function and a second one at the end of the function. You should see this:

    Fourth debugging snapshot

    Figure III.6. Fourth debugging snapshot

  5. Now you can start setting your breakpoints and debugging!

    Fifth debugging snapshot

    Figure III.7. Fifth debugging snapshot

  6. Stop debugging and close the file: File menu --> Close.