Contiki first project
From Cyber-Physical Systems Laboratory
Jump to navigationJump to searchContents
Contiki first Project
Now that you have an empty project with QtCreator (if you are using it), create 2 files:
- General Text file named: Makefile
- 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:
- Auto-complete
- Source and headers files
- 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:
- CONTIKI: relative path to contiki folder
- APPS: apps included in your project (those apps can be found in contiki/apps folder)
- CFLAGS: you can add flags here
- MODULES: for example if you need to include the tsch module:
MODULES += core/net/mac/tsch - 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
- hello-world/
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
- Projects
- Choose the build directory:
/home/user/workspace/hello-world - Remove all the build and clean steps
- Create a new Make step for the Build
- Add the Make arguments:
all TARGET=sky - Do the same thing for Clean steps
QtCreator is ready to Build the project.
Manual Build
- Open a terminal
- Go to your project directory
- 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:
- Open Putty
- Open the Serial terminal
- Reset your TelosB