Added support for the FTP standalone client to the c64 target.
[contiki-2.x.git] / doc / tutorial-raven.txt
blob44159ed91ca3b2df1239d6f009294ed684e0a405
1 /**
2 \addtogroup tutorials
3 @{
4 */
6 /**
7  * \defgroup tutorialraven Running Contiki with uIPv6 and SICSlowpan support on Atmel RAVEN hardware
8  * @{
9 This tutorial explains how to run Contiki with IPv6 and 6lowpan
10 support on Atmel RAVEN hardware.
13 \section toc Table of contents
14 \ref introduction<br>
15 \ref hardware<br>
16 \ref software<br>
17 \ref overview<br>
18 \ref installation<br>
19 \ref running<br>
20 \ref advanced<br>
21 \ref issues<br>
22 \ref annex<br>
24 <HR>
25 \section introduction Introduction
26 This tutorial explains how to run Contiki with IPv6 and 6lowpan
27 support on Atmel RAVEN evaluation kit (ATAVRRZRAVEN) hardware. We
28 present basic example system architecture and application scenarios,
29 as well as instructions to run more advanced demos.
31 <HR>
32 \section hardware Hardware requirements
34 To run the demo, you will need at least
35 \li one AVR RAVEN board, which embeds an ATmega1284P and an
36 ATmega3290P micro controller (MCU) as well as an AT86RF230 
37 802.15.4 radio chip.
38 \li one RZ USB stick, which embeds an AT90USB1287 MCU and
39 an AT86RF230 802.15.4 radio chip.
40 \li one PC running Windows to program the chips. For the demo
41 itself, a PC running Linux or Windows.
42 \li one On-chip programming platform. We recommend Atmel JTAGICE
43 mkII.
45 \note Links to detailed hardware documentation are in
46 \ref annex_hardware
48 <HR>
49 \section software Software requirements
50 To install the demo you need:
51 \li Contiki 2.3 or later source code, installed in a directory. In 
52 the rest of this tutorial we assume the directory is c:/contiki
53 \li Cygwin with "make" utility installed.
54 \li AVR Studio 4.14 or later
55 \li WinAVR20080610 or later
56 \li Windows drivers installed for the JTAGICE mkII.
58 Instructions to install these tools are in the section \ref annex_software.<br>
60 To run the demo, you need:
61 \li one PC running Linux with kernel 2.6.24 or later, with support for the
62 following kernel modules: IPv6, usbnet, cdc_ether, cdc_acm, rndis_wlan.
63 \li OR one PC running Windows with IPv6 support. If you use Windows XP,
64 you need Service Pack 3 installed.
66 \note
67 On windows XP, if ipv6 support is not enabled, enable it by typing
68 in a shell:
69 \verbatim
70 ipv6 install
71 \endverbatim
74 <HR>
75 \section overview Demo Overview
77 \subsection overview_architecture Network Architecture
78 The network comprises:
79 \li a PC acting as an IPv6 router with an 802.15.4 interface
80 and an Ethernet interface.
81 \li a RAVEN board acting as an IPv6 host.
83 In the basic demo, you can:
84 \li Ping the RAVEN Board from the router
85 \li Ping the router from the RAVEN board, using the RAVEN board
86 menu
87 \li Browse the web server running on the RAVEN board. The server
88 displays the live temperature measured from the board temperature
89 sensor
91 \image html tutorial-raven-basic.jpg
92 <HR>
93 \section installation Compiling, installing, configuring
95 \subsection installation_compiling Compiling the binaries for RAVEN and RZ USB stick
96 The binaries needed are:
97 \li c:/contiki/examples/webserver-ipv6/webserver6.elf file for the RAVEN board ATmega1284P
98 \li c:/contiki/platform/avr-ravenlcd/ravenlcd_3290.elf file for the RAVEN board ATmega3290P
99 \li c:/contiki/examples/ravenusbstick/ravenusbstick.elf file for the RZ USB Stick AT90USB1287
101 To compile each of them, type in Cygwin:
102 \verbatim
103 cd c:/contiki/examples/webserver-ipv6-raven
104 make
105 \endverbatim
106 \verbatim
107 cd c:/contiki/platform/avr-ravenlcd
108 make
109 \endverbatim
110 \verbatim
111 cd c:/contiki/examples/ravenusbstick
112 make
113 \endverbatim
116 \subsection installation_hw Installing the hardware
117 To power the RAVEN, put the EXT/BAT jumper in BAT position.
118 This will enable power on batteries. If you want to power 
119 the RAVEN externally, check instructions in 
120 \ref advanced_externalboard.
122 The RZ USB Stick needs to be plugged in the PC you will run 
123 the demo on. If you plan to run the demo on a Windows PC, you
124 will need to install drivers once contiki is loaded on the 
125 stick. Until then, you can exit any driver installation popup.
127 \subsection installation_loading Programming the boards
128 <b>What you need to do</b><br>
130 \li On the RAVEN board, program the binaries on both AVR ATmega.
131 \li On the RZ USB Stick, load the binary on the AT90USB1287
133 <b>Hardware connections</b><br>
134 \li Connect the JTAG connectors to the JTAGICE as described in 
135 the picture below.
137 \image html tutorial-raven-jtag.jpg
138 \li Connect the JTAGICE mkII to a Windows PC through USB.
139 \li To program (load) each AVR, you will need to connect the 
140 JTAGICE JTAG connector to the JTAG pins corresponding to the 
141 AVR you want to program, as shown in the picture below.
143 \image html tutorial-raven-connections.jpg 
146 <b>To load the binary on each AVR in Windows</b><br>
148 \li Launch AVR Studio and exit any popup window.
149 \li Connect the JTAG pins of the JTAGICE into the JTAG connector of
150 the target processor.
151 \li In AVR Studio, click on "Tools"->"Program AVR"->"Auto Connect"
152 \li Go to the "Main tab"
153 \li In the "Programming mode and target settings" list, select JTAG
154 \li Select the processor type in the "Device" list and click
155 "Read Signature". If the Device signature is read properly,
156 it means AVR Studio is properly connected to the AVR.
157 \li Go to the "Program" tab
158 \li In the "ELF Production file format" section,
159 browse to the binary, then click program
161 \verbatim
162 For webserver6.elf, set the processor to ATmega1284P
163 For ravenlcd_3290.elf, set the processor to ATmega3290P
164 For ravenusbstick.elf, set the processor to AT90USB1287
166 \endverbatim
168 Once the RZ USB Stick is programmed, unplug it from the PC.
169 Note this programmed the fuses, EEPROM, and FLASH all at once.
173 <HR>
174 \section running Running the basic demo
175 \subsection running_router Setting up the router
176 <b>On Linux</b><br>
177 Plug the RZ USB Stick in the PC. It should appear as a USB
178 network interface (e.g. usb0).
180 usb0 should automatically get an IPv6 link local address, i.e. 
181 fe80::0012:13ff:fe14:1516/64. Check this is the case by typing 
182 \verbatim
183 ifconfig
184 \endverbatim
185 and checking the addresses of interface usb0
187 If it does not, add it manually:
188 \verbatim
189 ip -6 address add fe80::0012:13ff:fe14:1516/64 scope link dev usb0
190 \endverbatim
192 Configure the IP addresses on usb0
193 \verbatim
194 ip -6 address add aaaa::1/64 dev usb0
195 \endverbatim
197 Install the radvd deamon and configure it so the usb0
198 interface advertises the aaaa::/64 prefix as on link
199 and usable for address autoconfiguration.
202 Radvd configuration (usually in /etc/radvd.conf)
203 \verbatim
204 interface usb0
206     AdvSendAdvert on;
207     AdvLinkMTU 1280;
208     AdvCurHopLimit 128;
209     AdvReachableTime 360000;
210     MinRtrAdvInterval 100;
211     MaxRtrAdvInterval 150;
212     AdvDefaultLifetime 200;
213     prefix AAAA::/64
214     {
215         AdvOnLink on;
216         AdvAutonomous on;
217         AdvPreferredLifetime 4294967295; 
218         AdvValidLifetime 4294967295; 
219     };
221 \endverbatim
222 \note This values have been carefuly chosen to work on platform using
223 a 16bit clock.
225 Restart the radvd daemon. Example command:
226 \verbatim
227 /etc/init.d/radvd restart
228 \endverbatim
230 If you get a message that radvd won't start as forwarding isn't enabled,
231 you can run this as root:
233 \verbatim
234 echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
235 \endverbatim
237 <b>On Windows</b><br>
239 Plug the RZ USB Stick in the PC. A "new hardware installation"
240 window should pop up. If it does not, go to "Control Panel"->
241 "Add Hardware". Choose "Install the driver manually", then
242 select the search path C:\\contiki\\cpu\\avr\\dev\\usb\\INF. Finish
243 the installation. 
245 You now need to get the "interface index" of the USB Stick 
246 interface (noted [interface index] in the following) and the 
247 Ethernet interface (noted [ethernet interface index] in the 
248 following).
250 In a DOS or Cygwin shell, type 
251 \verbatim
252 ipv6 if
253 \endverbatim
255 As an example, the output might look something like this:
257 \verbatim
259 Interface 7: Ethernet
260  ...
261  link-layer address: 02-12-13-14-15-16
262  preferred link-local fe80::12:13ff:fe14:1516, life infinite
263  ...
264 Interface 4: Ethernet: Local Area Connection
265  ...
266  link-layer address: 00-1e-37-16-5d-83
267  preferred link-local fe80::21e:37ff:fe16:5d83, life infinite
268  ...
270 \endverbatim
272 Note the link-layer address associated with interface 7 is the USB Stick. Hence
273 [interface index] is 7, [ethernet interface index] is 4 and [ethernet
274 link-local address] is fe80::21e:37ff:fe16:5d83.
276 Then you need to
277 \li Set the USB Stick interface as an advertising interface
278 \li Configure a global IP address on the USB Stick interface
279 \li Add a default route through the Ethernet interface
280 \li Set the aaaa::/64 prefix as "on link" and published on the USB Stick
281 interface.
283 To do so, type:
284 \code
285 ipv6 ifc [interface index] advertises forwards
286 ipv6 adu [interface index]/aaaa::1
287 ipv6 rtu ::/0 [ethernet interface index]/[ethernet link-local address] publish
288 ipv6 rtu aaaa::/64 [interface index] publish
289 \endcode
292 \subsection running_raven Booting the RAVEN boards
294 Reboot the RAVEN board.
295 The PC sends router advertisements and the RAVEN Board configures 
296 an IPv6 global address based on them. The PC global addresses 
297 were set above. Communication is ready.
299 \subsection running_ping1 Pinging the RAVEN board from the router
300 On Windows (Cygwin shell) or Linux, type
301 \verbatim
302 ping6 -n 5 aaaa::11:22ff:fe33:4455
303 \endverbatim
305 \verbatim
306 ping6 -s aaaa::1 aaaa::11:22ff:fe33:4455
307 \endverbatim
308 The router is sending 5 echo requests to the RAVEN board. The RAVEN board
309 answers with 5 echo replies.
311 \subsection running_ping2 Pinging the router from the RAVEN board
312 To send a ping from the RAVEN to the router you need to use the
313 RAVEN's joystick and LCD screen. Initially, the LCD screen should
314 print CONTIKI - 6LOWPAN in a loop. You can navigate the LCD menu by
315 using the small joystick just below its lower right corner. To 'ping'
316 push the joystick twice to the right. The RAVEN board sends 4 echo
317 requests to the router, which answers by 4 echo replies.<br>
318 For more information about the LCD menu, please see \ref lcdraven.
320 \subsection running_browse Browsing the RAVEN board web server
321 In a Web browser, point to http://[aaaa::0011:22ff:fe33:4455].
322 Then click on 'Sensor Readings'. If no temperature is displayed it
323 means that you need to start the temperature update %process on the
324 RAVEN. To do so you must use the RAVEN's LCD menu and
325 joystick. Starting from the CONTIKI - 6LOWPAN display navigate to TEMP
326 and then to SEND. You can pick either ONCE or AUTO, but in any
327 case you always need to reload the webpage to see the latest temperature
328 reading. <br>
329 For more information about the LCD menu, please see \ref lcdraven.
331 <HR>
332 \section advanced Advanced use
333 \subsection advanced_externalboard Using an external board for power and Debug
334 To power the RAVEN boards externally and enable debug output
335 on RS232, you can use the stk500 board together with the raven.
337 Power:
338 \li Set the 'EXT/BAT' jumper on the RAVEN board to EXT
339 \li Attach pin 2 on the bottom strip to GND of your STK500
340 \li Attach pin 1 on the bottom strip to VTG of your STK500
341 \li Power the STK500
343 Debug Connection
344 \li Attach pin 4 of the leftmost I/O header to pin 'TXD' on your STK500
345 \li Connect the STK500's "RS232SPARE" port to a RS232 port on a PC
346 \li Connect a terminal program (e.g. hyper terminal on Windows,
347 minicom on Linux) to the RS232 port on the PC at 57600 Baud,
348 with parity 8N1, no flow control
349 \li The raven board will output debug messages to the terminal
351 \note To enable specific debugging messages, edit the source
352 file you are interested in (e.g. core/net/uip-nd6-io.c for
353 Neighbor Discovery messages debug) and set the macro DEBUG to 1.
354 Then recompile the code, load the new binary on the board and
355 restart the RAVEN.
357 The following image shows this connection, with the red and black
358 being VCC and GND. The green wire is debug out:
360 \image html raven_detail.jpg
362 \note The output to the RS232 converts will only be about
363 3V, but they are expecting a signal swinging up to VTG, or by
364 default 5V. You may have to set VTG to 3.3V and power the Raven
365 from another source, making sure the GNDs of both the STK500
366 and your external source are connected together.
368 \subsection advanced_details Understanding the setup
369 There is no widely available 802.15.4 and 6lowpan stack for PCs.
370 As a temporary solution and to be able to connect IPv6 hosts
371 such as RAVEN boards to IP networks, we implemented a "bridge"
372 function on the RZ USB Stick. The RZ USB stick bridges 802.15.4
373 packets to Ethernet (The Ethernet interface is emulated on the
374 USB port).
376 As Ethernet frames and addresses are very different
377 from 802.15.4 ones, a few adjustements are needed on addresses
378 and some neighbor discovery packets. As a consequence, 802.15.4
379 MAC addresses configured on both the RAVEN boards and the RZ USB
380 stick must have the format:<br>
381 \verbatim
382 x2:xx:xx:ff:fe:xx:xx:xx
383 \endverbatim
384 where x can take any hexadecimal value.
385 Read the section below to change the MAC address on one device.
387 \subsection advanced_eeprom Change a device MAC address
389 You can change the MAC address of a RAVEN board or the RZ USB 
390 Stick by setting the 8 first bytes of the EEPROM, following 
391 the convention above. You can do this three ways. 
393 The first is to set EEPROM bytes directly in an AVR Studio project, in
394 Debug mode
396 \li compile the binary file for RAVEN, as explained in \ref installation
397 \li Connect the JTAG pins of the JTAGICE into the JTAG connector of
398 the target processor.
399 \li IN AVR Studio, go to File->open, select the binary just created
400 \li The Debug mode should start
401 \li Click on View->memory
402 \li select EEPROM in the menu, then just type in the first 8 bytes
403 the target MAC address
405 The second is to reprogram the whole EEPROM individually from the 
406 Flash and Fuses.
408 \li Connect the JTAG pins of the JTAGICE into the JTAG connector of
409 the target processor.
410 \li In AVR Studio, click on "Tools"->"Program AVR"->"Auto Connect"
411 \li Go to the "Program" tab
412 \li In the "EEPROM" section, click on "Read" and save the EEPROM 
413 content in a file (in hex format)
414 \li Edit this file with a text editor, change the value of the 
415 first 8 bytes, save
416 \li In the "EEPROM" section, check the path to the "Input Hex file"
417 is the one to the file you just modified and click on "Program". 
419 The third is to modify the default value in the code:
421 \li Edit the file contiki-raven-main.c in the directory
422 platform\avr-raven. You will see the MAC address set in a line like:
424 \code
425 /* Put default MAC address in EEPROM */
426 uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
427 \endcode
429 \li Change this value, recompile and reprogram the elf on the board.
431 \subsection advanced_fuses Setting the fuses manually
433 In case you need to reset the fuses on one AVR, do the following:
434 \li In AVR Studio, click on "Tools"->"Program AVR"->"Auto Connect"
435 \li Go to the "Fuses" tab
436 \li In the lower part of the window, set the EXTENDED,
437 HIGH, LOW fuses to the following values
438 \verbatim
439 0xFF, 0x99, 0xE2 for the ATmega1284P on the RAVEN board
440 0xFF, 0x99, 0xE2 for the ATmega3290P on the RAVEN board
441 0xFB, 0x99, 0xDE for the AT90USB1287 on the USB Stick
442 \endverbatim
443 \li In the same tab, Click on "Program"
444 \subsection advanced_capture Observing packets with Atmel Wireless Services or Wireshark
445 To view packets being sent over the air, you can use Atmel AVR
446 Wireless Services in Sniffer Mode, with the RZ USB Stick. You need
447 the software preinstalled on the RZ USB Stick to do this. Packets
448 are sent on channel 24. Links to detailed information about
449 AVR Wireless Services is provided with the RZ USB Stick.
451 See the \ref usbstick documentation for more details about using Wireshark.
453 \subsection adavanced_linux Programming Flash, Fuses, EEPROM from a Linux machine
455 One can use avrdude to load the binaries in Linux.
457 \subsection advanced_hc01 Using HC01 Header Compression Scheme
458 IETF Internet Draft draft-hui-6lowpan-hc-01 defines a stateful
459 header compression mechanism (called HC01) which will soon
460 deprecate the stateless header compression mechanism (called
461 HC1) defined in RFC4944. HC01 is much more powerfull and flexible,
462 in particular it allows compression of some multicast addresses
463 and of all global unicast addresses.
465 Contiki is compiled by default with HC1 support. To use HC01
466 instead, edit platform/xxx/contiki-conf.h (replace xxx with avr-raven,
467 then avr-ravenusb.)
468 and replace the line<BR>
469 \code
470 #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_CONF_COMPRESSION_HC1
471 \endcode
472 with
473 \code
474 #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_CONF_COMPRESSION_HC01
475 \endcode
477 Recompile and load Contiki for both the RAVEN ATmega1284P and RZ USB 
478 Stick.
480 If you capture packets being sent over the air (on the 802.15.4
481 network), you will see that much more packets are compressed than
482 when HC1 is used. Overall, packets sent are much smaller.
484 \subsection advanced_network Building a more complete network
485 You can integrate the RAVEN boards and RZ USB stick to a more
486 complete IPv6 network by connecting the PC which you plug the RZ
487 USB Stick in to any IPv6 network with correct routing configured.
489 This way, you will be able to reach the RAVEN boards (to read
490 sensor data for example) from anywhere within this IPv6 network,
491 or even any IPv4 network if v4 to v6 translation mechanisms are
492 used between both networks.
494 You can also have several RAVEN boards in your setup. If you do so,
495 be sure to configure different MAC addresses on each board.
499 <HR>
500 \subsection issues Known issues
501 <b>RZ USB Stick Link local address not created on Linux</b><br>
503 When plugging the RZ USB Stick in a Linux PC, it should
504 automatically configure a link local address
505 (fe80::0012:13ff:fe14:1516/64 with default MAC address). On some Linux
506 distributions, it seems to fail. To check this, in a terminal,
507 type
508 \verbatim
509 ifconfig
510 \endverbatim
511 If the interface usb0 does not have an IPv6 address starting
512 with fe80::, add it manually by typing:
513 \verbatim
514 ip -6 address add fe80::0012:13ff:fe14:1516/64 scope link dev usb0
515 \endverbatim
517 <b>make version issues</b><br>
518 You need to use the "make" executable from WinAVR. There 
519 are compilation issues with GNU make coming with Cygwin.
521 <HR>
522 \section annex Annex
524 \subsection annex_contikiDocs Annex - Additional Documentation
526 \li USB Stick Platform:     \ref usbstick
527 \li User interface on Raven:\ref lcdraven
528 \li Wireless libraries for Atmel Radio: \ref wireless
529 \li MAC for Atmel Radio:    \ref macdoc
530 \li IPv6 Implementation: \ref uip6 
531 \li 6lowpan Implementation: \ref sicslowpan
533 \subsection annex_hardware Annex - Atmel products detailed documentation
534 <b>RAVEN evaluation and starter kits</b><br>
535 \li ATAVRRZRAVEN evaluation kit:
536 http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4291
537 \li AVR RAVEN board:
538 http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4395
539 \li RZ USB Stick:
540 http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4396
542 <b>RAVEN AVRs and Wireless transceivers</b><br>
543 \li ATmega 1284P MegaAVR:
544 http://www.atmel.com/dyn/products/product_card.asp?part_id=4331
545 \li ATmega 3290P LCD AVR:
546 http://www.atmel.com/dyn/products/product_card.asp?part_id=4059
547 \li AT90USB1287 USB AVR:
548 http://www.atmel.com/dyn/products/product_card.asp?part_id=3875
549 \li AT86RF230 802.15.4 Transceiver:
550 http://www.atmel.com/dyn/products/product_card.asp?part_id=3941
552 <b>Additional hardware</b><br>
553 \li ATSTK500 evaluation kit
554 http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2735
555 \li ATEVK1100 evaluation kit
556 http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4114
557 \li AVR JTAGICE mkII debugging platform
558 http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3353
560 <b>Buying the hardware (part number ATAVRRZRAVEN and ATJTAGICE2)</b><br>
561 \li For the U.S. you can use http://www.atmel.com/contacts/distributor_check.asp
562 \li Digikey http://www.digikey.com/
563 \li Spoerle http://www.spoerle.com/en/products 
564 \li Lawicel http://www.lawicel-shop.se
567 \subsection annex_software Software setup details
568 <b>Contiki</b><br>
569 Download Contiki code from http://www.sics.se/contiki and
570 extract the source code. We assume the directory you extract 
571 to is c:/contiki.
573 <b>Cygwin</b><br>
574 \li Download Cygwin from http://www.cygwin.com
575 \li Launch the setup executable
576 \li Follow the instructions until you reach the Window "Cygwin 
577 Setup - Select Packages"
578 \li In this window, expand the "Devel" item and 
580 <b>AVR Studio</b><br>
581 Download and install AVR Studio from
582 http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725
584 <b>WinAVR</b><br>
585 WinAVR which contains a number of AVR tools
586 such as the avr-gcc compiler.
588 Download and install WinAVR latest version from
589 http://winavr.sourceforge.net/ 
591 <b>JTAGICE mkII Drivers</b><br>
592 Plug the JTAGICE mkII in a USB port of a windows PC. Follow the
593 indications to install the Windows drivers automatically.
597 /** @} */
598 /** @} */