Eclipse

Version 1 (Joe Gaudet -, 01/28/2010 03:42 pm)

1 1 Joe Gaudet -
== Using Eclipse ==
2 1 Joe Gaudet -
Eclipse is a powerful IDE, though it's primary use is for the development of Java applications it's various plugins allow it to find use in many areas, including C development. This page will describe the process by which you can get eclipse setup for developing with Nano-RK.
3 1 Joe Gaudet -
4 1 Joe Gaudet -
''' Install Eclipse '''
5 1 Joe Gaudet -
6 1 Joe Gaudet -
First things first you should head on over to http://www.eclipse.org and get the latest version of eclipse. 
7 1 Joe Gaudet -
8 1 Joe Gaudet -
If you are using linux it can be installed via the package manager.
9 1 Joe Gaudet -
10 1 Joe Gaudet -
''' Install Eclipse CDT '''
11 1 Joe Gaudet -
12 1 Joe Gaudet -
Once more if you are using eclipse you can install the CDT plugin via the package manager, however if you aren't it can be installed via the software update system in eclipse. More extensive instructions can be found at http://www.eclipse.org/cdt/.
13 1 Joe Gaudet -
14 1 Joe Gaudet -
''' Get the current revision of Nano-RK '''
15 1 Joe Gaudet -
16 1 Joe Gaudet -
Users can checkout a development copy of the code from subversion by typing:
17 1 Joe Gaudet -
18 1 Joe Gaudet -
{{{
19 1 Joe Gaudet -
svn checkout svn://nanork.org/srv/svn/repos/nano-RK
20 1 Joe Gaudet -
}}}
21 1 Joe Gaudet -
22 1 Joe Gaudet -
or go to our [wiki:releases] page for code snapshots. Make note of where you are putting this, as it will become relevant later.
23 1 Joe Gaudet -
24 1 Joe Gaudet -
''' Create a NANO_HOME environment variable '''
25 1 Joe Gaudet -
26 1 Joe Gaudet -
In order for builds and so forth to work nicely in eclipse, we need an environment variable that points to the location where you have checked out nano-RK. The process is quite simple, add the following lines to your .bash_login (or google adding environment variables for your particular shell).
27 1 Joe Gaudet -
28 1 Joe Gaudet -
{{{
29 1 Joe Gaudet -
NANO_HOME=<Path to Nano-RK>
30 1 Joe Gaudet -
export NANO_HOME
31 1 Joe Gaudet -
}}}
32 1 Joe Gaudet -
33 1 Joe Gaudet -
You will have to re-open your shell for this to take effect, you can verify that you've done this properly with the following command:
34 1 Joe Gaudet -
35 1 Joe Gaudet -
{{{
36 1 Joe Gaudet -
echo $NANO_HOME
37 1 Joe Gaudet -
}}}
38 1 Joe Gaudet -
39 1 Joe Gaudet -
Which should print the location of your nano-rk working copy.
40 1 Joe Gaudet -
41 1 Joe Gaudet -
''' Creating a new project ''' 
42 1 Joe Gaudet -
43 1 Joe Gaudet -
Create a new C project in eclipse using the new project wizard.
44 1 Joe Gaudet -
45 1 Joe Gaudet -
// a screen shot will go here
46 1 Joe Gaudet -
47 1 Joe Gaudet -
Select the project type as an empty makefile project, this should leave you with an empty folder looking something like:
48 1 Joe Gaudet -
49 1 Joe Gaudet -
''' Makefile and nrk_cfg.h '''
50 1 Joe Gaudet -
51 1 Joe Gaudet -
Create a make file (called makefile) in the root of your project and copy in the following:
52 1 Joe Gaudet -
53 1 Joe Gaudet -
{{{
54 1 Joe Gaudet -
# Platform name  cc2420DK, firefly, micaZ, firefly2_1, firefly2_2, firefly2_3
55 1 Joe Gaudet -
PLATFORM = micaZ
56 1 Joe Gaudet -
57 1 Joe Gaudet -
58 1 Joe Gaudet -
# Target file name (without extension).
59 1 Joe Gaudet -
TARGET = main
60 1 Joe Gaudet -
61 1 Joe Gaudet -
# Set the Port that you programmer is connected to 
62 1 Joe Gaudet -
PROGRAMMING_PORT = /dev/ttyUSB0
63 1 Joe Gaudet -
64 1 Joe Gaudet -
65 1 Joe Gaudet -
# PROGRAMMING_PORT = `ls /dev/tty.* | grep usb | head -n 1` # programmer connected to serial device
66 1 Joe Gaudet -
67 1 Joe Gaudet -
# Set platform specific defines 
68 1 Joe Gaudet -
# The following will be defined based on the PLATFORM variable:
69 1 Joe Gaudet -
# PROG_TYPE  (e.g. avrdude, or uisp)
70 1 Joe Gaudet -
# MCU (e.g. atmega32, atmega128, atmega1281) 
71 1 Joe Gaudet -
# RADIO (e.g. cc2420)
72 1 Joe Gaudet -
include $(NANO_HOME)/include/platform.mk
73 1 Joe Gaudet -
74 1 Joe Gaudet -
75 1 Joe Gaudet -
SRC = $(TARGET).c
76 1 Joe Gaudet -
77 1 Joe Gaudet -
# Add extra source files. 
78 1 Joe Gaudet -
# For example:
79 1 Joe Gaudet -
# SRC += $(NANO_HOME)/src/platform/$(PLATFORM_TYPE)/source/my_src1.c 
80 1 Joe Gaudet -
# SRC += $(NANO_HOME)/src/platform/$(PLATFORM_TYPE)/source/my_src2.c 
81 1 Joe Gaudet -
82 1 Joe Gaudet -
# Add extra includes files. 
83 1 Joe Gaudet -
# For example:
84 1 Joe Gaudet -
# EXTRAINCDIRS += $(NANO_HOME)/src/platform/include
85 1 Joe Gaudet -
EXTRAINCDIRS =
86 1 Joe Gaudet -
87 1 Joe Gaudet -
88 1 Joe Gaudet -
#  This is where the final compile and download happens
89 1 Joe Gaudet -
include $(NANO_HOME)/include/platform/$(PLATFORM)/common.mk
90 1 Joe Gaudet -
91 1 Joe Gaudet -
}}}
92 1 Joe Gaudet -
93 1 Joe Gaudet -
Create a nrk_cfg.h file with the following:
94 1 Joe Gaudet -
95 1 Joe Gaudet -
{{{
96 1 Joe Gaudet -
/***************************************************************
97 1 Joe Gaudet -
*                            NanoRK CONFIG                     *
98 1 Joe Gaudet -
***************************************************************/
99 1 Joe Gaudet -
#ifndef __nrk_cfg_h
100 1 Joe Gaudet -
#define __nrk_cfg_h
101 1 Joe Gaudet -
102 1 Joe Gaudet -
// NRK_REPORT_ERRORS will cause the kernel to print out information about
103 1 Joe Gaudet -
// missed deadlines or reserve violations
104 1 Joe Gaudet -
105 1 Joe Gaudet -
#define NRK_LOG_ERRORS
106 1 Joe Gaudet -
#define NRK_ERROR_EEPROM_INDEX  0x200
107 1 Joe Gaudet -
108 1 Joe Gaudet -
#define NRK_REPORT_ERRORS
109 1 Joe Gaudet -
// NRK_HALT_ON_ERRORS will cause the kernel to freeze on errors so that
110 1 Joe Gaudet -
// it is easier to see debugging messages.
111 1 Joe Gaudet -
//#define NRK_HALT_AND_LOOP_ON_ERROR
112 1 Joe Gaudet -
//#define NRK_HALT_ON_ERROR
113 1 Joe Gaudet -
#define IGNORE_BROWN_OUT_ERROR
114 1 Joe Gaudet -
#define IGNORE_EXT_RST_ERROR
115 1 Joe Gaudet -
116 1 Joe Gaudet -
// Disable a few common errors when connected to programmer
117 1 Joe Gaudet -
//#define IGNORE_EXT_RST_ERROR
118 1 Joe Gaudet -
//#define IGNORE_BROWN_OUT_ERROR
119 1 Joe Gaudet -
120 1 Joe Gaudet -
// Enable the watchdog as a protective measure
121 1 Joe Gaudet -
// This will only activate if the scheduler fails.
122 1 Joe Gaudet -
#define NRK_WATCHDOG
123 1 Joe Gaudet -
#define NRK_REBOOT_ON_ERROR
124 1 Joe Gaudet -
//#define NRK_SOFT_REBOOT_ON_ERROR
125 1 Joe Gaudet -
126 1 Joe Gaudet -
127 1 Joe Gaudet -
#define NRK_STATS_TRACKER
128 1 Joe Gaudet -
129 1 Joe Gaudet -
#define NRK_SW_WDT
130 1 Joe Gaudet -
#define NRK_MAX_SW_WDT  3
131 1 Joe Gaudet -
132 1 Joe Gaudet -
// If you want to disable the looping kernel error message when the system
133 1 Joe Gaudet -
// halts, then include the following define.  This will automatically
134 1 Joe Gaudet -
// halt the error as well.
135 1 Joe Gaudet -
//#define NRK_HALT_ON_ERROR
136 1 Joe Gaudet -
137 1 Joe Gaudet -
// NRK_STACK_CHECK adds a little check to see if the bottom of the stack
138 1 Joe Gaudet -
// has been over written on all suspend calls
139 1 Joe Gaudet -
#define NRK_STACK_CHECK
140 1 Joe Gaudet -
141 1 Joe Gaudet -
//#define KERNEL_STK_ARRAY
142 1 Joe Gaudet -
// Leave NRK_NO_POWER_DOWN define in if the target can not wake up from sleep
143 1 Joe Gaudet -
// because it has no asynchronously clocked
144 1 Joe Gaudet -
// #define NRK_NO_POWER_DOWN
145 1 Joe Gaudet -
146 1 Joe Gaudet -
// Max number of tasks in your application
147 1 Joe Gaudet -
// Be sure to include the idle task
148 1 Joe Gaudet -
// Making this the correct size will save on BSS memory which
149 1 Joe Gaudet -
// is both RAM and ROM...
150 1 Joe Gaudet -
#define NRK_MAX_TASKS                   5
151 1 Joe Gaudet -
152 1 Joe Gaudet -
153 1 Joe Gaudet -
154 1 Joe Gaudet -
#define NRK_TASK_IDLE_STK_SIZE         128 // Idle task stack size min=32
155 1 Joe Gaudet -
#define NRK_APP_STACKSIZE              128
156 1 Joe Gaudet -
#define NRK_KERNEL_STACKSIZE           128
157 1 Joe Gaudet -
#define NRK_MAX_RESOURCE_CNT           1
158 1 Joe Gaudet -
159 1 Joe Gaudet -
160 1 Joe Gaudet -
#endif
161 1 Joe Gaudet -
162 1 Joe Gaudet -
}}}
163 1 Joe Gaudet -
164 1 Joe Gaudet -
''' main.c '''
165 1 Joe Gaudet -
166 1 Joe Gaudet -
Write what ever code you need in a file called main.c. (Presumably as your project increases in complexity you will use additional files, I will leave that to you).
167 1 Joe Gaudet -
168 1 Joe Gaudet -
''' Make Targets '''
169 1 Joe Gaudet -
170 1 Joe Gaudet -
By default clicking the build default button will run the make file without any arguments, however we want to be able to run both 'make clean' and 'make program' this can be done by simply adding two make targets in the make target panel.
171 1 Joe Gaudet -
172 1 Joe Gaudet -
// screen shots
173 1 Joe Gaudet -
174 1 Joe Gaudet -
If you've followed all of the steps correctly you should be able to see the same effects as running make, make clean, and make program from the console, but now you will be able to leverage the refactoring / syntax highlighting / awesomeness capabilities of eclipse.