Creating a New EMAC OE SDK Project

From EMAC Wiki
Jump to: navigation, search
TODO: {{#todo:SEOKWREV (11.26.13-20:35->MD+);(11.27.13-15:20-KY+);(12.5.13-18:20-MG+);(03.04.14-16:20->BS-);(03.20.14-15:45->BS+);(04.14.14-14:40->BS+)|Mike Dean|oe 4,oe 5,md,SEOKWREV,ky,mg,bs}}

Table 1: Conventions
/download/directory/ The directory to which the SDK archive will be downloaded.
/path/to/sdk/ The directory to which the SDK will be extracted.
XX - the SDK major version
YY - the SDK minor version
ZZ - the SDK current revision
target_program The program executable created to run on the target device.
Prompt and commands to be run on a development machine that will run compliation tasks.
Prompt and commands to be run on a target machine.

The EMAC OE SDK is a complete development kit for creating C/C++ applications for EMAC products. The SDK can be used to compile code anywhere in the development system. This procedure explains the process of creating and building a new project within the SDK.

New Project Procedure

This guide assumes that the EMAC OE SDK has been installed and configured. It also assumes a basic familiarity with the C programming language and that a basic text editor is available. The example code calculates the perimeter of a right triangle given the length of its longest edge and the angle between that edge and one of the other edges.

Set Up the Project

The first step is to create a project directory in /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects directory.

developer@ldc:~$ mkdir /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example

Write the C Code

The C code for this example is listed below. Copy the code into a blank document and save as example.c in the project directory created above.

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define HYP 10.0
#define DEG 30.0
int main(void)
	float opp, adj;
	opp = HYP * sin(DEG);
	adj = HYP * cos(DEG);
	printf("Hypotenuse: \t%3.2f\n", HYP);
	printf("Angle: \t\t%3.2f\n", DEG);
	printf("Opposite Side: \t%3.2f\n", opp);
	printf("Adjacent Side: \t%3.2f\n", adj);
	printf("%3.2f + %3.2f + %3.2f = %3.2f \n", HYP, opp, adj, (HYP + opp + adj));

Listing 1. example.c

Modify the Makefile

Makefiles are used to tell the compiler what actions to perform. Makefiles are useful so that the developer does not have to remember a long list of compile options and source files that need to be compiled.

Create the New Makefile

The EMAC OE SDK provides a very basic Makefile that can be used for new projects and extended as needed. Navigate to the hello project in the SDK projects and copy the Makefile file to the current project directory. Or from the command line type:

developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example/
developer@ldc:~$ cp ../hello/Makefile ./

Configure What Source Files to Compile

Open the Makefile in a text editor and modify the CFILES and TARGET variables as follows:

  • CFILES=example.c instead of CFILES=hello.c
  • TARGET=example instead of TARGET=hello

This tells the Makefile that the source file used is example.c and the resulting executable will be called example. The CFILES variable can be assigned a space-delimited list of C files for larger projects.

Configure Libraries to Link

In order to use the trigonometric functions present in the source file, the math library must be included. To include the math library in the compilation process, add it to the LIBFLAGS variable on the line below CFILES.

  • LIBFLAGS+=-lm

The math library is Other libraries may need to be included in custom projects that make use of advanced functions.

Listing 2 shows the complete modified makefile for the example.c project.

include ../
all: $(TARGET)
$(TARGET): $(OBJS) Makefile
%.o: %.c
  $(CC) $(VERBOSE) $(CFLAGS) -o $@ -c $<
  $(RM) *.o *.gdb $(TARGET) $(DEPS)
upload: all
  $(WPUT) $(TARGET) ftp://$(LOGIN):$(PASSWORD)@$(TARGET_IP)/../../tmp/$(TARGET)
-include $(DEPS)

Listing 2. Modified Example Makefile

Cross-Compile with the EMAC OE SDK

Using the Makefile created above, the GNU make utility will be used to compile the example source code into an application that can be run on the target machine. Change into the example project directory then execute the make targets as shown in Listing 3. For a description of each make target, read the bullet items below.

developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example/
#### Target 1 ####
developer@ldc:~$ make clean 
rm -f *.o *.gdb example example.d

#### Target 2 ####
developer@ldc:~$ make all 
../../gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc  -Wall -MMD -g -march=armv5te -mtune=arm926ej-s -o example.o -c example.c\
../../gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc  example.o  -lm  -o example

#### Target 3 ####
developer@ldc:~$ make upload 
wput --reupload --dont-continue sentence ftp://root:emac_inc@
--16:52:48-- `app_name'
    => ftp://root:xxxxx@
Connecting to connected!
Logging in as root ... Logged in!
Length: 13,774
16:52:48 (example) - `350.6K/s' [13774]
FINISHED --16:52:48--
Transfered 13,774 bytes in 1 file at 107.3K/s

Listing 3. Example Make Target Invocation

  • make clean removes all object, dependency, and executable files generated by previous invocations of make.
  • make all resolves dependencies for the source code necessary to cross-compile the target file and creates the target program provided there are no errors in the source code. The gcc and g++ compilers used are specified in
  • make upload uses ftp to transfer the executable file to the target device. The username and password used to connect to the target device are stored in

Optional Modifications

In order to debug applications effectively, the -g debug flag must be specified when running the compiler. This is set up to occur automatically by its inclusion in the CFLAGS variable.

For release builds, however, this can be harmful to the application's performance. In a typical general-purpose computer this may not be noticeable, but for embedded systems there are typically memory and disk limitations. For production or release versions of an application it is recommended to replace -g with -g0 which tells the compiler not to include debug information in the executable.

To get information about a particular file, use the file command:

developer@ldc:~$ file myexecutable
myexecutable: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped

The stripped/not stripped field of the output tells weather the executable contains debugging symbols. Debugging symbols can be removed from an executable without recompiling using the strip command:

developer@ldc:~$ strip myexecutable

To verify that the executable was stripped, run file again:

developer@ldc:~$ file myexecutable
myexecutable: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, stripped

Alternate Project Locations

If the project is created outside of the /path/to/sdk/projects directory, the paths present in the Makefile and the path to the SDK in the files will need to be modified as below.

  1. Copy the correct file from the SDK/projects directory to the current project directory

    developer@ldc:~$ cp -L /path/to/sdk/projects/ /path/to/project/hello
  2. Modify the include line at the top of the make file to refer to the new file

  3. Change the value of SDKBASE in to point to the location of the SDK installation.

Next Steps

Once the target binary has been compiled, the project is ready to be executed and debugged.

Remote Debugging with gdbserver

Navigation menu