Eclipse

Version 5 (Joe Gaudet -, 01/28/2010 04:37 pm)

1 5 Joe Gaudet -
2 5 Joe Gaudet -
h2. Using Eclipse
3 5 Joe Gaudet -
4 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.
5 1 Joe Gaudet -
6 5 Joe Gaudet -
* Install Eclipse *
7 1 Joe Gaudet -
8 1 Joe Gaudet -
First things first you should head on over to http://www.eclipse.org and get the latest version of eclipse. 
9 1 Joe Gaudet -
10 1 Joe Gaudet -
If you are using linux it can be installed via the package manager.
11 1 Joe Gaudet -
12 5 Joe Gaudet -
* Install Eclipse CDT *
13 1 Joe Gaudet -
14 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/.
15 1 Joe Gaudet -
16 5 Joe Gaudet -
* Get the current revision of Nano-RK *
17 1 Joe Gaudet -
18 1 Joe Gaudet -
Users can checkout a development copy of the code from subversion by typing:
19 1 Joe Gaudet -
20 5 Joe Gaudet -
<pre>
21 1 Joe Gaudet -
svn checkout svn://nanork.org/srv/svn/repos/nano-RK
22 5 Joe Gaudet -
</pre>
23 1 Joe Gaudet -
24 5 Joe Gaudet -
or go to our [[releases]] page for code snapshots. Make note of where you are putting this, as it will become relevant later.
25 1 Joe Gaudet -
26 5 Joe Gaudet -
* Create a NANO_HOME environment variable *
27 1 Joe Gaudet -
28 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).
29 1 Joe Gaudet -
30 5 Joe Gaudet -
<pre>
31 1 Joe Gaudet -
NANO_HOME=<Path to Nano-RK>
32 1 Joe Gaudet -
export NANO_HOME
33 5 Joe Gaudet -
</pre>
34 1 Joe Gaudet -
35 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:
36 1 Joe Gaudet -
37 5 Joe Gaudet -
<pre>
38 1 Joe Gaudet -
echo $NANO_HOME
39 5 Joe Gaudet -
</pre>
40 1 Joe Gaudet -
41 1 Joe Gaudet -
Which should print the location of your nano-rk working copy.
42 1 Joe Gaudet -
43 5 Joe Gaudet -
* Creating a new project * 
44 1 Joe Gaudet -
45 1 Joe Gaudet -
Create a new C project in eclipse using the new project wizard.
46 1 Joe Gaudet -
47 2 Joe Gaudet -
[[Image(newProject.png)]]
48 1 Joe Gaudet -
49 1 Joe Gaudet -
Select the project type as an empty makefile project, this should leave you with an empty folder looking something like:
50 1 Joe Gaudet -
51 2 Joe Gaudet -
[[Image(emptyMakeProject.png)]]
52 1 Joe Gaudet -
53 5 Joe Gaudet -
* Makefile and nrk_cfg.h *
54 1 Joe Gaudet -
55 1 Joe Gaudet -
Create a make file (called makefile) in the root of your project and copy in the following:
56 1 Joe Gaudet -
57 5 Joe Gaudet -
<pre>
58 1 Joe Gaudet -
# Platform name  cc2420DK, firefly, micaZ, firefly2_1, firefly2_2, firefly2_3
59 1 Joe Gaudet -
PLATFORM = micaZ
60 1 Joe Gaudet -
61 1 Joe Gaudet -
62 1 Joe Gaudet -
# Target file name (without extension).
63 1 Joe Gaudet -
TARGET = main
64 1 Joe Gaudet -
65 1 Joe Gaudet -
# Set the Port that you programmer is connected to 
66 1 Joe Gaudet -
PROGRAMMING_PORT = /dev/ttyUSB0
67 1 Joe Gaudet -
68 1 Joe Gaudet -
69 5 Joe Gaudet -
# PROGRAMMING_PORT = @ls /dev/tty.* | grep usb | head -n 1@ # programmer connected to serial device
70 1 Joe Gaudet -
71 1 Joe Gaudet -
# Set platform specific defines 
72 1 Joe Gaudet -
# The following will be defined based on the PLATFORM variable:
73 1 Joe Gaudet -
# PROG_TYPE  (e.g. avrdude, or uisp)
74 1 Joe Gaudet -
# MCU (e.g. atmega32, atmega128, atmega1281) 
75 1 Joe Gaudet -
# RADIO (e.g. cc2420)
76 1 Joe Gaudet -
include $(NANO_HOME)/include/platform.mk
77 1 Joe Gaudet -
78 1 Joe Gaudet -
ROOT_DIR - $(NANO_HOME)
79 1 Joe Gaudet -
80 1 Joe Gaudet -
SRC = $(TARGET).c
81 1 Joe Gaudet -
82 1 Joe Gaudet -
# Add extra source files. 
83 1 Joe Gaudet -
# For example:
84 1 Joe Gaudet -
# SRC += $(ROOT_DIR)/src/platform/$(PLATFORM_TYPE)/source/my_src1.c 
85 1 Joe Gaudet -
# SRC += $(ROOT_DIR)/src/platform/$(PLATFORM_TYPE)/source/my_src2.c 
86 1 Joe Gaudet -
87 1 Joe Gaudet -
# Add extra includes files. 
88 1 Joe Gaudet -
# For example:
89 1 Joe Gaudet -
# EXTRAINCDIRS += $(NANO_HOME)/src/platform/include
90 1 Joe Gaudet -
EXTRAINCDIRS =
91 1 Joe Gaudet -
92 1 Joe Gaudet -
93 4 Joe Gaudet -
#  This is where the final compile and download happens
94 1 Joe Gaudet -
include $(ROOT_DIR)/include/platform/$(PLATFORM)/common.mk
95 1 Joe Gaudet -
96 5 Joe Gaudet -
</pre>
97 1 Joe Gaudet -
98 1 Joe Gaudet -
Create a nrk_cfg.h file with the following:
99 1 Joe Gaudet -
100 5 Joe Gaudet -
<pre>
101 1 Joe Gaudet -
/***************************************************************
102 5 Joe Gaudet -
*                            [[NanoRK]] CONFIG                     *
103 1 Joe Gaudet -
***************************************************************/
104 5 Joe Gaudet -
#ifndef +nrk_cfg_h
105 5 Joe Gaudet -
#define +nrk_cfg_h
106 1 Joe Gaudet -
107 1 Joe Gaudet -
// NRK_REPORT_ERRORS will cause the kernel to print out information about
108 1 Joe Gaudet -
// missed deadlines or reserve violations
109 1 Joe Gaudet -
110 1 Joe Gaudet -
#define NRK_LOG_ERRORS
111 1 Joe Gaudet -
#define NRK_ERROR_EEPROM_INDEX  0x200
112 1 Joe Gaudet -
113 1 Joe Gaudet -
#define NRK_REPORT_ERRORS
114 1 Joe Gaudet -
// NRK_HALT_ON_ERRORS will cause the kernel to freeze on errors so that
115 1 Joe Gaudet -
// it is easier to see debugging messages.
116 1 Joe Gaudet -
//#define NRK_HALT_AND_LOOP_ON_ERROR
117 1 Joe Gaudet -
//#define NRK_HALT_ON_ERROR
118 1 Joe Gaudet -
#define IGNORE_BROWN_OUT_ERROR
119 1 Joe Gaudet -
#define IGNORE_EXT_RST_ERROR
120 1 Joe Gaudet -
121 1 Joe Gaudet -
// Disable a few common errors when connected to programmer
122 1 Joe Gaudet -
//#define IGNORE_EXT_RST_ERROR
123 1 Joe Gaudet -
//#define IGNORE_BROWN_OUT_ERROR
124 1 Joe Gaudet -
125 1 Joe Gaudet -
// Enable the watchdog as a protective measure
126 1 Joe Gaudet -
// This will only activate if the scheduler fails.
127 1 Joe Gaudet -
#define NRK_WATCHDOG
128 1 Joe Gaudet -
#define NRK_REBOOT_ON_ERROR
129 1 Joe Gaudet -
//#define NRK_SOFT_REBOOT_ON_ERROR
130 1 Joe Gaudet -
131 1 Joe Gaudet -
132 1 Joe Gaudet -
#define NRK_STATS_TRACKER
133 1 Joe Gaudet -
134 1 Joe Gaudet -
#define NRK_SW_WDT
135 1 Joe Gaudet -
#define NRK_MAX_SW_WDT  3
136 1 Joe Gaudet -
137 1 Joe Gaudet -
// If you want to disable the looping kernel error message when the system
138 1 Joe Gaudet -
// halts, then include the following define.  This will automatically
139 1 Joe Gaudet -
// halt the error as well.
140 1 Joe Gaudet -
//#define NRK_HALT_ON_ERROR
141 1 Joe Gaudet -
142 1 Joe Gaudet -
// NRK_STACK_CHECK adds a little check to see if the bottom of the stack
143 1 Joe Gaudet -
// has been over written on all suspend calls
144 1 Joe Gaudet -
#define NRK_STACK_CHECK
145 1 Joe Gaudet -
146 1 Joe Gaudet -
//#define KERNEL_STK_ARRAY
147 1 Joe Gaudet -
// Leave NRK_NO_POWER_DOWN define in if the target can not wake up from sleep
148 1 Joe Gaudet -
// because it has no asynchronously clocked
149 1 Joe Gaudet -
// #define NRK_NO_POWER_DOWN
150 1 Joe Gaudet -
151 1 Joe Gaudet -
// Max number of tasks in your application
152 1 Joe Gaudet -
// Be sure to include the idle task
153 1 Joe Gaudet -
// Making this the correct size will save on BSS memory which
154 1 Joe Gaudet -
// is both RAM and ROM...
155 1 Joe Gaudet -
#define NRK_MAX_TASKS                   5
156 1 Joe Gaudet -
157 1 Joe Gaudet -
158 1 Joe Gaudet -
159 1 Joe Gaudet -
#define NRK_TASK_IDLE_STK_SIZE         128 // Idle task stack size min=32
160 1 Joe Gaudet -
#define NRK_APP_STACKSIZE              128
161 1 Joe Gaudet -
#define NRK_KERNEL_STACKSIZE           128
162 1 Joe Gaudet -
#define NRK_MAX_RESOURCE_CNT           1
163 1 Joe Gaudet -
164 1 Joe Gaudet -
165 1 Joe Gaudet -
#endif
166 1 Joe Gaudet -
167 5 Joe Gaudet -
</pre>
168 1 Joe Gaudet -
169 5 Joe Gaudet -
* main.c *
170 1 Joe Gaudet -
171 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).
172 1 Joe Gaudet -
173 5 Joe Gaudet -
* Make Targets *
174 1 Joe Gaudet -
175 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.
176 2 Joe Gaudet -
177 1 Joe Gaudet -
[[Image(makeTarget.png)]]
178 2 Joe Gaudet -
179 2 Joe Gaudet -
[[Image(newMakeTarget.png]]
180 1 Joe Gaudet -
181 2 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.
182 2 Joe Gaudet -
183 3 Joe Gaudet -
[[Image(eclipseProject.png)]]
184 2 Joe Gaudet -
185 1 Joe Gaudet -
Screenshot of the working IDE.