Eclipse

Version 2 (Joe Gaudet -, 01/28/2010 03:58 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 2 Joe Gaudet -
[[Image(newProject.png)]]
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 2 Joe Gaudet -
[[Image(emptyMakeProject.png)]]
50 2 Joe Gaudet -
51 1 Joe Gaudet -
''' Makefile and nrk_cfg.h '''
52 1 Joe Gaudet -
53 1 Joe Gaudet -
Create a make file (called makefile) in the root of your project and copy in the following:
54 1 Joe Gaudet -
55 1 Joe Gaudet -
{{{
56 1 Joe Gaudet -
# Platform name  cc2420DK, firefly, micaZ, firefly2_1, firefly2_2, firefly2_3
57 1 Joe Gaudet -
PLATFORM = micaZ
58 1 Joe Gaudet -
59 1 Joe Gaudet -
60 1 Joe Gaudet -
# Target file name (without extension).
61 1 Joe Gaudet -
TARGET = main
62 1 Joe Gaudet -
63 1 Joe Gaudet -
# Set the Port that you programmer is connected to 
64 1 Joe Gaudet -
PROGRAMMING_PORT = /dev/ttyUSB0
65 1 Joe Gaudet -
66 1 Joe Gaudet -
67 1 Joe Gaudet -
# PROGRAMMING_PORT = `ls /dev/tty.* | grep usb | head -n 1` # programmer connected to serial device
68 1 Joe Gaudet -
69 1 Joe Gaudet -
# Set platform specific defines 
70 1 Joe Gaudet -
# The following will be defined based on the PLATFORM variable:
71 1 Joe Gaudet -
# PROG_TYPE  (e.g. avrdude, or uisp)
72 1 Joe Gaudet -
# MCU (e.g. atmega32, atmega128, atmega1281) 
73 1 Joe Gaudet -
# RADIO (e.g. cc2420)
74 1 Joe Gaudet -
include $(NANO_HOME)/include/platform.mk
75 1 Joe Gaudet -
76 1 Joe Gaudet -
77 1 Joe Gaudet -
SRC = $(TARGET).c
78 1 Joe Gaudet -
79 1 Joe Gaudet -
# Add extra source files. 
80 1 Joe Gaudet -
# For example:
81 1 Joe Gaudet -
# SRC += $(NANO_HOME)/src/platform/$(PLATFORM_TYPE)/source/my_src1.c 
82 1 Joe Gaudet -
# SRC += $(NANO_HOME)/src/platform/$(PLATFORM_TYPE)/source/my_src2.c 
83 1 Joe Gaudet -
84 1 Joe Gaudet -
# Add extra includes files. 
85 1 Joe Gaudet -
# For example:
86 1 Joe Gaudet -
# EXTRAINCDIRS += $(NANO_HOME)/src/platform/include
87 1 Joe Gaudet -
EXTRAINCDIRS =
88 1 Joe Gaudet -
89 1 Joe Gaudet -
90 1 Joe Gaudet -
#  This is where the final compile and download happens
91 1 Joe Gaudet -
include $(NANO_HOME)/include/platform/$(PLATFORM)/common.mk
92 1 Joe Gaudet -
93 1 Joe Gaudet -
}}}
94 1 Joe Gaudet -
95 1 Joe Gaudet -
Create a nrk_cfg.h file with the following:
96 1 Joe Gaudet -
97 1 Joe Gaudet -
{{{
98 1 Joe Gaudet -
/***************************************************************
99 1 Joe Gaudet -
*                            NanoRK CONFIG                     *
100 1 Joe Gaudet -
***************************************************************/
101 1 Joe Gaudet -
#ifndef __nrk_cfg_h
102 1 Joe Gaudet -
#define __nrk_cfg_h
103 1 Joe Gaudet -
104 1 Joe Gaudet -
// NRK_REPORT_ERRORS will cause the kernel to print out information about
105 1 Joe Gaudet -
// missed deadlines or reserve violations
106 1 Joe Gaudet -
107 1 Joe Gaudet -
#define NRK_LOG_ERRORS
108 1 Joe Gaudet -
#define NRK_ERROR_EEPROM_INDEX  0x200
109 1 Joe Gaudet -
110 1 Joe Gaudet -
#define NRK_REPORT_ERRORS
111 1 Joe Gaudet -
// NRK_HALT_ON_ERRORS will cause the kernel to freeze on errors so that
112 1 Joe Gaudet -
// it is easier to see debugging messages.
113 1 Joe Gaudet -
//#define NRK_HALT_AND_LOOP_ON_ERROR
114 1 Joe Gaudet -
//#define NRK_HALT_ON_ERROR
115 1 Joe Gaudet -
#define IGNORE_BROWN_OUT_ERROR
116 1 Joe Gaudet -
#define IGNORE_EXT_RST_ERROR
117 1 Joe Gaudet -
118 1 Joe Gaudet -
// Disable a few common errors when connected to programmer
119 1 Joe Gaudet -
//#define IGNORE_EXT_RST_ERROR
120 1 Joe Gaudet -
//#define IGNORE_BROWN_OUT_ERROR
121 1 Joe Gaudet -
122 1 Joe Gaudet -
// Enable the watchdog as a protective measure
123 1 Joe Gaudet -
// This will only activate if the scheduler fails.
124 1 Joe Gaudet -
#define NRK_WATCHDOG
125 1 Joe Gaudet -
#define NRK_REBOOT_ON_ERROR
126 1 Joe Gaudet -
//#define NRK_SOFT_REBOOT_ON_ERROR
127 1 Joe Gaudet -
128 1 Joe Gaudet -
129 1 Joe Gaudet -
#define NRK_STATS_TRACKER
130 1 Joe Gaudet -
131 1 Joe Gaudet -
#define NRK_SW_WDT
132 1 Joe Gaudet -
#define NRK_MAX_SW_WDT  3
133 1 Joe Gaudet -
134 1 Joe Gaudet -
// If you want to disable the looping kernel error message when the system
135 1 Joe Gaudet -
// halts, then include the following define.  This will automatically
136 1 Joe Gaudet -
// halt the error as well.
137 1 Joe Gaudet -
//#define NRK_HALT_ON_ERROR
138 1 Joe Gaudet -
139 1 Joe Gaudet -
// NRK_STACK_CHECK adds a little check to see if the bottom of the stack
140 1 Joe Gaudet -
// has been over written on all suspend calls
141 1 Joe Gaudet -
#define NRK_STACK_CHECK
142 1 Joe Gaudet -
143 1 Joe Gaudet -
//#define KERNEL_STK_ARRAY
144 1 Joe Gaudet -
// Leave NRK_NO_POWER_DOWN define in if the target can not wake up from sleep
145 1 Joe Gaudet -
// because it has no asynchronously clocked
146 1 Joe Gaudet -
// #define NRK_NO_POWER_DOWN
147 1 Joe Gaudet -
148 1 Joe Gaudet -
// Max number of tasks in your application
149 1 Joe Gaudet -
// Be sure to include the idle task
150 1 Joe Gaudet -
// Making this the correct size will save on BSS memory which
151 1 Joe Gaudet -
// is both RAM and ROM...
152 1 Joe Gaudet -
#define NRK_MAX_TASKS                   5
153 1 Joe Gaudet -
154 1 Joe Gaudet -
155 1 Joe Gaudet -
156 1 Joe Gaudet -
#define NRK_TASK_IDLE_STK_SIZE         128 // Idle task stack size min=32
157 1 Joe Gaudet -
#define NRK_APP_STACKSIZE              128
158 1 Joe Gaudet -
#define NRK_KERNEL_STACKSIZE           128
159 1 Joe Gaudet -
#define NRK_MAX_RESOURCE_CNT           1
160 1 Joe Gaudet -
161 1 Joe Gaudet -
162 1 Joe Gaudet -
#endif
163 1 Joe Gaudet -
164 1 Joe Gaudet -
}}}
165 1 Joe Gaudet -
166 1 Joe Gaudet -
''' main.c '''
167 1 Joe Gaudet -
168 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).
169 1 Joe Gaudet -
170 1 Joe Gaudet -
''' Make Targets '''
171 1 Joe Gaudet -
172 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.
173 1 Joe Gaudet -
174 2 Joe Gaudet -
[[Image(makeTarget.png)]]
175 1 Joe Gaudet -
176 2 Joe Gaudet -
[[Image(newMakeTarget.png]]
177 2 Joe Gaudet -
178 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.
179 2 Joe Gaudet -
180 2 Joe Gaudet -
[[Image(eclipseProject.png)]]
181 2 Joe Gaudet -
Screenshot of the working IDE.