1.7 Writing our first application program


2012-02-07Publicerad av Sven-Åke Andersson

Introduction


Writing a simple c-program for our LEON3 processor is a quick way to find out if the hardware system is working. It is also a good test of the software development environment. We will start by downloading and installing the cross compiler and some help tools.


Bare-C Cross Compiler BCC


BCC is a cross-compiler for LEON2 and LEON3 processors. It is based one the GNU compiler tools and the Newlib standalone C-library. The cross-compiler system allows compilation of both tasking and non-tasking C and C++ applications. It supports hard and soft floating-point operations, as well as SPARC V8 multiply and divide instructions. BCC can also be used to compile the eCos kernel. BCC consists of the following packages:

  • GNU GCC C/C++ compiler v3.4.4, v4.4.2
  • Newlib C-library v 1.13.1
  • Low-level I/O routines for LEON2 and LEON3/4, including interrupt support
  • uIP light-weight TCP/IP stack
  • GDB debugger v6.4 with DDD and Insight Graphical front-end
  • Mkprom prom-builder for LEON2/3
  • Linux and Windows (MingW) hosts

For more information read the BCC manual.

Install BCC



To download the BCC cross compiler go to the Aeroflex Gaisler download page and click the link: "BCC binaries for Linux and Windows" which will take us to the Gaisler FTP site where we can download two versions of the gcc cross compiler (3.4.4 and 4.4.2). We will use both versions.






 


 

Installation
 

BCC is provided as a bzipped tar-file. It should be unpacked in the /opt/Gaisler/compiler directory of the host:

sudo tar -C /opt/Gaisler/compiler -xjf sparc-elf-<version-number>.tar.bz2

After installation, add /opt/Gaisler(compiler/sparc-elf-<gcc-version-number>/bin to the PATH variable. This should be done by adding the following line to the file .profile in the home directory:

export PATH=/opt/Gaisler/compiler/sparc-elf-<gcc-version-number>/bin:$PATH
 




 

Installing in Ubuntu 10.10 (Maverick Meerkat) 64bits Linux
 

When we try to run the 4.4.2 verison of the gcc compiler in Ubuntu 10.10 (amd68) it complains over missing libraries. We have to find and install the i386 (32 bit) versions of the following libraries:


l


To force installation of 32bit libraries into a 64bit system we add the "--force-architecture" clause to the dpkg command. The library files will be installed in the directory /usr/lib. For safety reasons we will move the files to the /usr/lib32 directory.


Compiling our first program


We will start by creating a workspace directory in the software directory:
 

lll



We will write the simplest program of them all: Hello World. Here is the source code:

#include <stdio.h>

main()
{
printf("Hello World\n");
}


Here is the command to compile the source program:

sparc-elf-gcc-4.4.2 -O2 -msoft-float hello.c -o hello.exe
 

GRMON debug monitor


We will use the GRMON debug monitor from Aeroflex Gaisler to control the loading and running of our program. GRMON is a general debug monitor for the LEON processor, and for SOC designs based on the GRLIB IP library. GRMON includes the following functions:

  • Read/write access to all system registers and memory
  • Built-in disassembler and trace buffer management
  • Downloading and execution of LEON applications
  • Breakpoint and watchpoint management
  • Remote connection to GNU debugger (GDB)
  • Support for USB, JTAG, RS232, PCI, Ethernet and SpaceWire debug links

 



 


Installing GRMON


We will download and install the free version of GRMON called GRMON Evaluation/Academic version in the tool directory. For more information about GRMON read the user manual.

 



After adding the path to the program to the PATH variable in the .profile file we are ready to run.

export PATH=/opt/Gaisler/tool/grmon-eval/linux:$PATH
 

Loading and running our program


Here is the sequence of commands used in GRMON to load and run the Hello World program:

 


 

 

System information


The command <info sys> gives a lot of information about the system and the attached cores.




 
 
 

Ethernet debug interface



If the target system uses the EDCL ethernet communication link core, GRMON can connect to the system using ethernet. In this case, start GRMON with -eth. The default network parameters can be set through additional switches:


-emem <size>     Use size for the target system’s EDCL packet buffer. Default is 2 (kbytes)
-ip <ipnum>         Use ipnum for the target system IP number. Default is 192.168.0.51.
-udp <port>         Use port for the target systemUDP port. Default is 8000.


The IP address of the EDCL is determined at synthesis time, but can be changed using the edcl command:




The default IP address will not work in our network. We will change the IP address to 192.168.1.32.


Here is the command starting GRMON using an ethernet connection.

ll



The output from the application normally appears on the LEON UARTs and thus not in the GRMON console. However, if GRMON is started with the -u switch, the UART output is looped back to its own receiver and printed on the console by GRMON.

Changing the IP address


In IPv4 an address consists of 32 bits which limits the address space to 4294967296 (232) possible unique addresses. IPv4 reserves some addresses for special purposes such as private networks (~18 million addresses) or multicast addresses (~270 million addresses).

IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots, e.g., 172.16.254.1. Each part represents a group of 8 bits (octet) of the address. In some cases of technical writing, IPv4 addresses may be presented in various hexadecimal, octal, or binary representations.



 

To change the IP address of the SP605 board permanently we use xconfig.

cd ....../designs/leon3-xilinx-sp605
make xconfig

 

 

Changing the IP address to 192.168.1.32 gives the following MSB and LSB 16 bits:

MSB = 0xC0A8
LSB  = 0x0120

After changing the IP address we have to rerun the complete design flow using: <make ise>. When the bitgen has finished we can run the configuration <make ise-prog-fpga> and take a look at the IP address.
 


Våra medarbetare: