Saturday, May 28, 2011

Eclipse compatible Makefile for IAR embedded workbench C project

Well here we come to the trickiest bit.
I enclose a sample self designed makefile for a HelloWorld type C program, which consists of multiple files, namely HelloWorld and HelloNextWorld...



###############################################################################
# Makefile for the C versions on windows
#
#
# NOTES : the CC and LD must be on the PATH environment variable
# this is because of a bug in the IAR EW 2.3x
# that does not allow whitespace in windows paths
# define the C_INCLUDE and XLINK_DFLTDIR environment variables as well
#
#set path=%PATH%;C:/Program Files/IAR Systems/ew23/430/bin
#set C_INCLUDE =C:/Program Files/IAR Systems/ew23/430/inc
#set XLINK_DFLTDIR=C:/Program Files/IAR Systems/ew23/430/lib

## General Flags
PROJECT = hellomsp430std
MCU = msp430
TARGET = $(PROJECT).d43

CC = icc430.exe
LD = xlink.exe

SRCS = $(wildcard *.c)
OBJECTS= $(patsubst %.c,%.r43, $(SRCS))

## Compile options
CFLAGS = -e -K -gA -s0 -RCODE -r0 -t8

## Linker flags
LDFLAGS = -rt -I"C:/Program Files/IAR Systems/ew23/430/lib" -f lnk430F1611.xcl
##

## Objects to be built


## Build
all: $(TARGET)

## compile

##$(PROJECT).r43: $(PROJECT).c
%.r43: %.c
$(CC) $(INCLUDES) $(CFLAGS) $<

##Link
$(TARGET): $(OBJECTS)
$(LD) $(LDFLAGS) $(OBJECTS) -o $(TARGET)

## Clean target
.PHONY: distclean
distclean: clean
@rm -f $(TARGET) $(PROJECT).lst $(PROJECT).map

.PHONY: clean
clean:
@rm -f $(OBJECTS)

###############################################################################

Tuesday, May 24, 2011

How to manually import an existing IAR Embedded Workbench project (.ewp)

Eclipse does not currently include a project import or export functionality for projects created with the Embedded Workbench .
Here are some steps that you might want to execute on a tried and tested project.

  1. Switch to the C/C++ perspective, and use File → New → C Project (use "C++ Project" if your project uses C++ in the compiler language settings).
  2. Project name: enter your project name here
  3. Un-check: Use default location. This will re-use existing files in your source folder.
  4. Location: enter your project location
  5. Project type: Executable: Empty Project
  6. Toolchains: IAR Toolchain for ARM - 6.x
  7. Click Next
  8. (optional) Modify the available build configurations to match the ones available in the EW project. By default, Eclipse will create a Debug and Release configuration.
  9. Click Next
  10. If your project is running on a device which is supported by Embedded Workbench, you can choose it now so that the project settings will be adjusted to fit. Otherwise, use the default settings.
  11. Finish

Adjusting project settings

  1. By defaults, Eclipse project options can be set per-configuration. Select "All configurations" in the project properties before the options are set to avoid setting them twice.
  2. Setup include paths: Project → Properties → IAR ARM C/C++ Compiler → Preprocessor → Additional include directories.
  3. Define preprocessor symbols, for example: IAR_LPC_1343_SK for some examples. Project → Properties → IAR ARM C/C++ Compiler → Preprocessor → Defined symbols.
  4. Set linker configuration file to match the EW project: Project → Properties → IAR ARM Linker → Configuration
  5. Manually set other build options (library configuration, etc.)
  6. Change between J-Link and Simulator, setup macro files: Run → Debug Configurations..
  7. Click OK
Note that unlike IAR Embedded Workbench, all of the build artifacts (list files, etc) will end up in the build output folder, which is in the project location and has the name of the currently-selected build configuration (e.g. "Debug"). Also, it could be necessary to manually refresh the build output folder to be able to see list and map files.

IAR Embedded workbench for MSP430 architecture and its integration with Eclipse

Well, this post will be first in a series to document the way to integrate IAR compiler and the Eclipse CDT environment.

IAR has already done this for many other architectures already, but how hard can it be anyway to integrate the most popular open source IDE with the World's best compiler/debugger and proceeded to make a fairly quick hash out of it(meaning I took triple the time I expected).

However their tried and tested beta plugin is already available on request provided you have the corresponding software and firmware. If like me however you don't have the requisite cross compilers and platforms but are working on the humble IAR EW MSP43. It can be done.

The steps shown here do not depend on any plugin. The end result will not allow debugging with the stand alone (or integrated- how lucky can you get?) C-spy debugger, but only the integration of projects into Eclipse for static analysis and use of 3rd party plugins like the super cool Unit and Integration tester Eclipse plugin I developed. Available for a measly $2500 dollars . This of course are my primary reasons for marrying the two software together.

Have a good time ! Remember back up all your work and if you mess up, its at your own risk !