Difference between revisions of "Contiki first project"

From Cyber-Physical Systems Laboratory
Jump to navigationJump to search
 
(One intermediate revision by the same user not shown)
Line 96: Line 96:
  
 
QtCreator is ready to Build the project.
 
QtCreator is ready to Build the project.
 
Last you need to program the TelosB.
 
 
See next section [[#Program the target device]].
 
  
 
==== Manual Build ====
 
==== Manual Build ====
Line 120: Line 116:
 
And last program you TelosB:
 
And last program you TelosB:
  
<pre>sudo tos-bsl --telosb -c /dev/ttyUSB0 -r -e -I -p application-name.ihex</pre>
+
<pre>sudo tos-bsl --telosb -c /dev/ttyUSB0 -r -e -I -p hello-world.ihex</pre>
  
  

Latest revision as of 17:48, 16 March 2017

Contiki first Project

Now that you have an empty project with QtCreator (if you are using it), create 2 files:

  1. General Text file named: Makefile
  2. C++ Source file: hello-world.c (you can't choose a C source file so make sure to change the cpp extension to c)

Configuring the .pro file

This file is used by QtCreator to configure your project:

  1. Auto-complete
  2. Source and headers files
  3. Other files: Makefile

Here a sample .pro file for the TelosB:

# Apps included to the ContikiOS project (same value as the APP in your Makefile)
APPS=

# Adding apps folders to project PATH for the auto complete
INC_VAR=join(APPS, " /home/user/contiki/apps/", /home/user/contiki/apps/)
for(a, APPS):INCLUDEPATH+=/home/user/contiki/apps/$${a}

# Other PATHs to be added: core cpu/[cpu] /platform/[platform]
INCLUDEPATH+=/home/user/contiki/core
INCLUDEPATH+=/home/user/contiki/cpu/msp430
INCLUDEPATH+=/home/user/contiki/platform/sky


# Define for Autocomplete for the TelosB mote
# Can be foundin: contiki/platform/[your platform: here sky]/Makefile.common
# Line with the CFLAGS:
# CFLAGS += -D__MSP430F1611__=1 -e --vla -Ohz --multiplier=16s --core=430 --double=32
DEFINES+=__MSP430F1611__=1
# other DEFINES you might need to include for the auto complete.


# Added by QtCreator on adding files to the project.

SOURCES += \
    hello-world.c

HEADERS += \

OTHER_FILES += \
    Makefile


Creating the Makefile

The Contiki Makefile is very easy to create:

  1. CONTIKI: relative path to contiki folder
  2. APPS: apps included in your project (those apps can be found in contiki/apps folder)
  3. CFLAGS: you can add flags here
  4. MODULES: for example if you need to include the tsch module: MODULES += core/net/mac/tsch
  5. all: command to make the project

Here the Makefile for the hello-world project made with QtCreator:

CONTIKI_PROJECT = hello-world
all: $(CONTIKI_PROJECT)

APPS +=
MODULES += 
CFLAGS +=

CONTIKI = ../../contiki
include $(CONTIKI)/Makefile.include

My folder tree looks like that:

  • contiki/
  • workspace/
    • hello-world/
      • hello-world.c
      • Makefile

Build and program

Build

QtCreator

Last step before compiling your code if you want to compile it directly using QtCreator:

On the lest toolbar go to

  1. Projects
  2. Choose the build directory: /home/user/workspace/hello-world
  3. Remove all the build and clean steps
  4. Create a new Make step for the Build
  5. Add the Make arguments: all TARGET=sky
  6. Do the same thing for Clean steps

QtCreator is ready to Build the project.

Manual Build

  1. Open a terminal
  2. Go to your project directory
  3. Compile using make and the corresponding TARGET: TARGET:=sky (for TelosB)
cd ~/workspace/hello-world
make all TARGET=sky

Program the target device

First step is to create the .ihex file from your .sky file.

msp430-objcopy hello-world.sky -O ihex hello-world.ihex

And last program you TelosB:

sudo tos-bsl --telosb -c /dev/ttyUSB0 -r -e -I -p hello-world.ihex


Now if you want to see what the hello-world project does:

  1. Open Putty
  2. Open the Serial terminal
  3. Reset your TelosB