Home

Nut/OS Software Manual

image

Contents

1. Configuration File Target Hardware arthernet1 conf Arthernet AVR Ethernet Modul open source project by Guido Fischer at91eb40a conf Atmel AT91EB40A evaluation board with AT91R40008 CPU at91sam s conf Generic AT91SAM 7S board at91sam se ek conf Atmel AT91SAM 7SE EK evaluation board at91sam x ek conf Atmel AT91SAM7X EK evaluation board at91sam9260 ek conf Atmel AT91SAM9260 EK evaluation board charon2 conf HW group Charon II module eir1Oc conf Elektor Internet Radio 1 0 Rev C ethernut103 conf Ethernut 1 reference design with Atmega103 CPU ethernut1 3f conf Ethernut 1 3 Rev F reference design ethernut1 3g conf Ethernut 1 3 Rev G reference design ethernut1 Sh conf Ethernut 1 3 Rev H reference design ethernut20a conf Ethernut 2 0 Rev A reference design ethernut21b conf Ethernut 2 1 Rev B reference design ethernut30d conf Ethernut 3 0 Rev D reference design ethernut30e conf Ethernut 3 0 Rev E reference design ethernut5Oc conf Ethernut 5 0 Rev C reference design gbaxport2 conf Gameboy Advance with CharmedLabs Xport 2 mmnetO1 conf Propox MMnetO1 Ethernet Module 20 Using the GUI Configurator Configuration File Target Hardware mmnetO2 03 O04 conf Propox MMnetO1 Ethernet Module mmnet101 conf Propox MMnetO1 Ethernet Module mmnet102 103 104 conf Propox MMnetO1 Ethernet Module olimex sam ex256 conf Olimex SAM EX256 board stk501 conf Atmel STK501 evaluation board xnut 100 conf pro
2. EEPROM Options Program with project file C Preserve existing content Manual select gt Manual Program NOW I FLASH Options Program with project output files ITa Manual select Program FLASH EEPROM Verify FLASH EEPROM Manual Selection Files Select hex file for FLASH Select eep file for EEPROM 33 Nut OS Software Manual Running the Embedded Webserver In the previous chapters we compiled the binary for our first Nut OS application an embedded webserver and uploaded it to the target board Most application samples use the serial port to provide some feedback about program progress or any kind of errors that may occur Connect the serial port of your target board to one of the serial ports on your PC If available you can use the cable that came with your Ethernut Starter Kit a 1 1 DB 9 cable for AVR boards or a so called null modem cable for ARM based Ethernuts There s no need to switch off the target board serial ports are quite safe and protected against shortcuts or electrical discharge But remember not to touch any bare contacts on the board before taking some pre cautions Dissipate static electricity by touching a grounded metal object Tera Term Serial port setup x Port COMI Baud rate fi 15200 Now start your terminal emulator on the PC Windows users may use the standard Hyperterm but we recommend Teralerm It is more stable and freely
3. configure target STARGET prefix SPREFIX enable interwork enable multilib disable nls disable shared disable threads wLth qcce wlth qnu as with gnu ld make sudo make install Cd eke oe Now an intermediate bootstrap compiler is required which enables us to create the runtime library cd 9C0C 4 3 5 mkdir build STARGET cd build STARGET sudo configure target STARGET prefix SPREFIX disable nls disable shared disable threads with gcc with gnu ld with gnu as with dwarf2 enable languages c ct enable interwork 13 Nut OS Software Manual enable multilib with newlib with headers newlib 1 16 0 newlib libc include disable libssp disable libstdcxx pch A disable libmudflap disable libgomp v mkdir p libiberty libcpp fixincludes make all gcc sudo make install gcc CG dst With this compiler you can create the runtime library We need to tell sudo to use our PATH because make install requires our fresh installed arm elf ranlib cd newlib 1 16 0 mkdir build Starget cd build Starget configure target Starget prefix Sprefix enable interwork enab beamuadec 1b make sudo PATH SPATH make install CCl RE 3 UUM V MMM NH Finally build and install the cross compiler cd gcc 4 3 3 build STARGET make sudo make install eLo EE PE aoe In an additional step we may strip the installed binaries to save disk space and
4. disable nls disable libssp with dwarf2 make sudo make install O ae ae To build and install the runtime library use cd avr libc 1 6 7 mkdir build STARGET cd build STARGET configure prefix SPREFIX build config guess host STARGET make sudo make install CO Se Finally AVRDUDE can be installed with the following commands ed avrdude 5 star gz mkdir build STARGET cd build STARGET configure prefix SPREFIX make sudo make install In an additional step we may strip the installed binaries to save disk space and decrease load times sudo strip Sprefix bin sudo strip Sprefix Starget bin sudo strip Sprefix libexec gcec Starget 4 3 3 Installing AVR GCC on OS X Apple s Xcode package contains all the tools we need to build the cross toolchain Open Terminal and enter GEG Version If the response is similar to powerpc apple darwin9 gcec 4 0 1 GCC 4 0 1 Apple Inc build 5465 Copyright C 2005 Free Software Foundation Inc then GCC is already available and probably there is no need to install it again However if the response is bash gcc command not found then you need to download Xcode from developer apple com tools xcode A registration is required but this is free of charge Leave the Terminal window open while installing Xcode After having installed Xcode go back to the terminal to download the source packages curl 0 ftp gcc gnu org pub
5. Clean Output Directory Manual Sort Browser Window Close Save As No Open File Ba ImageCraft IDE for ICCAYR Advanced C ethemut 4 8 3 Jof x File Edit Search View Project Tools Terminal Help httpsery c for Nutsleep 60000 return 0 NutThreadsetPriority 254 amp HTTPD amp Files uom c lt p hittpserv c Headers Documents index html torn html C icevvavr bin imakew f HTTPD mak iccavr c IC ethernut 4 8 3 nutbld includ iccavr c IC ethernut 4 8 3 nutbld includ Device 76 full Done Mon Jul 13 20 16 46 2009 IW C ethernut 4 8 3 nutapp httpd httpserv c 89 iccavr o HTTPD LC ethernut 4 8 3 nutbld 895 1 C ethernut 4 8 3 nutappshttpd httpsery c C ethernut 4 8 3 Building Applications with ImageCraft Unless debugging is required you can directly use the ICCAVR IDE to program the ATmega flash memory with an ISP Adapter like the one you received with your Ethernut Starter Kit For debugging you need a JTAG Adapter with debugging capabilities for example the ATJTAGICE from Atmel The JTAG interface of the SP Duo doesn t support debugging If not already done connect the ISP Adapter to the Ethernut Board and the PC While doing this you must have switched off the Ethernut s power supply Switch the Ethernut power supply
6. Cancel Nut OS Software Manual In the following window click Agree if you aes 1s accept the displayed licenses Please review the license terms before installing WinA YR 20090313 D Press Page Down to see the rest of the agreement WinAYR Licensing Information GNU Binutils is distributed under the GNU GPL License GNU Compiler Collection GCC is distributed under the GNU GPL License avr libe is distributed under a BSD License avrdude is distributed under the GNU GPL License GNU Debugger GDB is distributed under the GNU GPL License Insight is distributed under the GNU GPL License SimulA R is distributed under the GNU GPL License AVARICE is distributed under the the GNU GPL License hd If you accept the terms of the agreement click I Agree to continue You must accept the agreement to install WinAVR 20090313 WinA R 20090313 Setup i Ea Now choose the installation folder You Can either choose install Location Choose the folder in which to install WindVR 20090313 D enter the path manually or press the Browse button to use a folder selection dialog Make sure eses imisaed ather teier eh karato camme ent that the directory name doesn t contain spaces If possible you should stick with the default d Win A VR Wh n n lj k N Destination Folder C Wi en done click Next rr Space required 122 6MB Space available 185 566 i 7 WinAYR 20090313 Setup i Es In the f
7. Installing a Cross Toolchain Unpack the packages Gai Soy ibaa hee el Ore ai Az tar lt 1r GoC Ccore 4 3734 barwbaZ tar xot OCO gti Aroel tar xz2 f newlib 1 bo 0 tar gz Now we set two useful environment variables and create a bin folder in advance which we add to the PATH variable TARGET arm elf export TARGET PREFIX usr local STARGET export PREFIX mkdir p PREFIX bin PATH SPATH SPREFIX bin export PATH Start with building and installing the binutils cd binutils 2 19 1 mkdir build STARGET cd build STARGET configure target STARGET prefix SPREFIX enable interwork enable multilib disable nls disable shared disable threads S WLeEh Gec N iti gnu aS With gnu Lad make make install CG E Gd Now an intermediate bootstrap compiler is required which enables us to create the runtime library Cd GCA ra mkdir build STARGET cd build STARGET configure target STARGET prefix SPREFIX disable nls disable shared disable threads with gcec with gnu ld with gnu as with dwarf2 enable languages c ct enable interwork enable multilib with newlib with headers newlib 1 16 0 newlib libc include disable libssp disable libstdcxx pch disable libmudflap disable libgomp v mkdir p libiberty libcpp fixincludes make all gcc make install gcc oc ar are E With this compiler you can create the runtime library Gd mew la bak 16 20
8. Nut OS Software Manual Manual Revision 2 8 Issue date July 2009 Copyright 2001 2009 by egnite GmbH All rights reserved Redistribution and use in source OpenDocument format and compiled forms HTML PDF PostScript RTF and so forth with or without modification are permitted provided that the following conditions are met 1 Redistributions of source code OpenDocument format must retain the above copyright notice this list of conditions and the following disclaimer as the first lines of this file unmodified 2 Redistributions in compiled form converted to PDF PostScript RTF and other formats must reproduce the above copyright notice this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution THIS DOCUMENTATION IS PROVIDED BY THE CONTRIBUTORS AND COPYRIGHT HOLDERS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT INDIRECT INCIDENTAL SPECIAL EXEMPLARY OR CONSEQUENTIAL DAMAGES INCLUDING BUT NOT LIMITED TO PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE DATA OR PROFITS OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN CONTRACT STRICT LIABILITY OR TORT INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY
9. Nut OS doesn t provide non blocking I O A minimum timeout of 1ms must be specified To disable time outs set the time value to NUT WAIT INFINITE 38 Nut OS Event Management Threads may wait for events from other threads or interrupts or may post or broadcast events to other threads Waiting threads line up in priority ordered queues so more than one thread may wait for the same event Events are posted to a wait queue moving the thread from waiting sleeping state to the ready to run state A running thread may also broadcast an event to a specified queue waking up all threads on that queue Usually a woken up thread takes over the CPU if it s priority is equal or higher than the currently running thread However events can be posted asynchronously in which case the posting thread continues to run Interrupt routines must always post events asynchronously by calling the macro NutEventPostFromirg volatile HANDLE qhp The event API provides the following functions int NutEventPost HANDLE qhp posts an event to the specified queue If no thread is currently waiting the queue is marked signaled int NutEventPostAsync HANDLE qhp is the same as NutEventPost but keeps the current thread running int NutEventBroadcast HANDLE ghp wakes up all threads waiting on the specified queue In opposite to NutEventPost and NutEventPostAsync an empty queue will not be marked signaled If already signaled the mark will be remove
10. ffnen The prepared project file contains most required settings Later on you will create your own projects and refer to the following steps to configure it If the project files in your Nut OS distribution had been created for a different version of the ImageCraft compiler you will see a warning message reminding you to select the correct target You can ignore this for now we will get to this step anyway Select Options from the project menu and click on the tab named Paths Two additional paths were added PEE PRC ctrernu 4 8 3 rbkhinciude C ethere fl AEN to the nclude Paths c ethernut 4 amp 3 nutbld include Asmincude Paths Jo T El and c lethernut 4 8 3 nut include This way ICCAVR e will search C header files in the Nut OS build directory NOTE The conpler driver automaticaly adds lt instal rood include as the l l ia l Brad include path and crete 000 Wb asthe default Beary path You do not first then in the original Nut OS source directory and EA A D E E finally in its own include directory which doesn t need Eee ee eee eee to be specified ox i _SetAs Defaut LosdDefeut Hep In other words the files located in the build tree will override the original header files in the source tree which in turn will override the original ICC header files The entry marked Library Path points to the directory which contains our readily built Nut OS libraries 30 Building Applications with Imag
11. Coc Network i Abbrechen 25 Nut OS Software Manual Using the Command Line Configurator Typically the Configurator is used occasionally in which case the GUI version ts a good choice However there are at least two cases where the command line version is the better choice v Building the command line version from the source is much easier and fails less likely than the GUI version v The command line version can be used in batch processing The name of the executable is nutconfigure To run it open a command line shell and change to the parent directory of the source directory nut cd ethernut on Linux and OS X or cd c ethernut 4 8 3 on Windows When called with option a short usage help is displayed nucconfigure 7 Usage nutconfigure OPTIONS ACTIONS OPTIONS a lt dir gt application directory nutapp b lt dir gt build directory nutbld c lt file gt configuration file nut conf ethernut21b conf i lt dir gt first include path lt diLr gt last include path l lt dir gt library directory m lt type gt target platform avr gcc p lt type gt programming adapter avr dude Cj quiet verbose s lt dir gt source directory nut r lt file gt repository nut conft reposi tory nut ACTIONS create buildtree create apptree If this fails check that your PATH environment is set The most important parameter is c which specifies the conf
12. Most checks have to be done in application code anyway This doesn t mean that the application programmer will be left alone Nut OS offers a number of plausibility checks at run time but they must be explicitly enabled and will be disabled again later when the system had been fully tested Two of these features had been discussed with heap management Heap dump and memory guards Another one is NUTASSERT This preprocessor macro is expanded only when NUTDEBUG USE ASSERT is defined At the time of this writing this option is not available in the Configurator but can be manually set in UserConf mk HWDEF DNUTDEBUG USE ASSERT Add this line to both files the one located in the system build directory nutbld and the one in the application directory nutapp Then rebuild the system libraries and your application code The NUTASSERT macro is usually located at the API function entries and will check the plausibility of the parameters passed from application code If something is wrong NUTFATAL will be called which in turn calls NUTPANIC to print out a detailed error message on stdout For example assume that an application misses to check the result of fopen fp f open UROM CONF IxT TEDT tfseek fp L100 SEEK SET If the file doesn t exist or if UROM wasn t registered fseek will be called with a NULL pointer Not checking this may result in all kind of problems typically not directly related to this code When NU
13. Simply enter make clean all to build the target binaries from the source code This will at least create an Intel hex file httpserv hex in the current directory which is typically required by your programming software Most bootloaders like BootMon for Ethernut 3 0 need the raw binary Attoserv bin while debuggers need loadable object files Attoserv e f or httpserv cof If the required format is not created automatically just call make again with the missing file make httpserv elf The procedure for uploading the file to your target board depends on the programming adapter or bootloader as well as the tool used on the PC Refer to the related manuals Most programming tools can run on the command line in which case a single command can re build the binary and upload it to the target 28 Building Applications on the Command Line make clean all burn This requires that you selected the correct Programmer on the last page in the Configurator settings notebook It may be further required to modify the related file nut app Makeburn Most bootloader tools like TFTPD32 and SAM BA expect the binary in a previously specified directory Use make clean all install to automatically copy the binaries to nut bin target where target will be replaced by the CPU family like avr arm tdmi arm9 etc If your board supports boot loading over Ethernet like Ethernut 3 then configure your TFTP server to use this directory for requeste
14. TCP IP Illustrated Vol 1 Addison Wesley One of if not the most recommended introduction to the entire TCP IP protocol suite covering all the major protocols and several important applications Stevens W TCP IP Illustrated Vol 2 Addison Wesley Discusses the internals of TCP IP based on the Net 2 release of the Berkeley System Stevens W TCP IP Illustrated Vol 3 Addison Wesley Covers some special topics of TCP IP RFCs RFCs Request For Comment are documents that define the protocols used in the Internet Some are standards others are suggestions or even jokes Many Internet sites offer them for download via http or ftp Postel Jon RFC 768 User Datagram Protocol Postel Jon RFC 91 Internet Protocol Postel Jon RFC 92 Internet Control Message Protocol Postel Jon RFC793 Transmission Control Protocol Plummer D C RFC826 Ethernet Address Resolution Protocol Braden R T RFC1122 Requirements for Internet Hosts Communication Layers T Berners Lee R Fielding and H Frystyk RFC1945 Hypertext Transfer Protocol Web Links http www ethernut de Ethernut project page http www egnite de Ethernut hardware vendor 54 Reference Material 55 egnite GmbH Phone 49 0 23 05 44 12 56 Eg n ite Erinstrasse 9 Fax 49 0 23 05 44 14 87 44575 Castrop Rauxel Germany E Mail info egnite de http www egnite de http www ethernut de
15. below If you do not want to use the default folder you can either type a new name or select an existing folder from the list On the next dialog you are able to change the start menu entry Simply click Next to keep the default Shortcut folder ImageCraft Development Tools Ready to Install Setup now has enough information to start installing the software If you would like to make any changes before continuing click Back To abort the installation click Cancel When you are ready to start installing the files click Install Clicking the nsta button will start the installation Cancel The Status of the installation Progress Extracting wwhelp wwhimpl common scripts Extracting wwhelp wwhimpl common scripts bklistis js Extracting wwhelp wwhimpl common scripts bookgrps j is displayed A command line window Extract ing wwhe lp wwhimpl common scripts booklist j wwhe lp wwhinmpl common scripts browseri j lt Back wwhe lp wwhimpl common scripts controls j may temporarily appear whe lp wwhimpl common scripts docuntis is wwhe lp wwhim onno ng s s Updating system wwhe lp wwhin A SS Ck EPG Ste el pte wwhe lp wwhinpl java wwhe lp wwhinpl java htnl wwhe lp wwhinpl java html ie66uin htm wwhe lp wwhinpl javaN html iemac htm wwhe lp wwhinmpl java html iewindow htm wwhe lp wwhinmpl java html netscape htm wwhe lp wwhinpl java html nosecie htm Extracting wwhelp wwhimpl java
16. decrease load times sudo strip SPREFIX bin sudo strip SPREFIX STARGET bin sudo strip SPREFIX libexec gcc STARGET 4 3 3 Installing YAGARTO on OS X Ready built binaries of the GCC ARM ELF toolchain are available at http www yagarto de Installing ARM ELF GCC on OS X If YAGARTO fails to install or if you want to try a different version of any of the utilities included in the YAGARTO distribution you can install the toolchain from the source code Apple s Xcode package contains all the tools we need to build the cross toolchain Open Terminal and enter gee version If the response is similar to powerpc apple darwin9 gcec 4 0 1 GCC 4 0 1 Apple Inc build 5465 Copyright C 2005 Free Software Foundation Inc then GCC is already available and probably there is no need to install it again However if the response is bash gcc command not found then you need to download Xcode from http developer apple com tools xcode A registration is required but this is free of charge Leave the Terminal window open while installing Xcode After having installed Xcode go back to the terminal to download the source packages curl 0 ftp gcc gnu org pub binutils releases binutils 2 19 1 tar bz2 curl 0 ftp gcc gnu org pub gcc releases gcc 4 3 3 gcc core 4 3 3 tar bz2 curl 0 ftp gcc gnu org pub gcc releases gcc 4 3 3 gcc gt t 4 3 3 tar bz2 curl 0 ftp sources redhat com pub newlib newlib 1 16 0 tar gz 14
17. imme A dev read NUIFILE 7g void Int int rdev WILte NUTRI 7 CONSE vold 74 Tnb ifdef HARVARD ARCH _ int dev_write P NUTFILE PGM P int endif NUTEI EE dev OPen NUTDEVICE Za CONST Char Ay Inty Ini re dey lose NU LEER 7 long dev Size NUTR EGE be The most important members of this structure are the 7 or 8 function pointers at its end Each device driver instance provides a global variable of this structure where at least some of the function pointers point to the related device driver functions Note that the dev_write P member is available on targets with Harvard Architecture only 43 Nut OS Software Manual Ethernut 3 offers two UARTs USARTO and USART1 Both can be used with the debug device driver The driver instance that uses USARTO provides the following global NUTDEVICE structure NUTDEVICE devDebugO 0 f Gey inex Fy beste aa Sa ye Mg SO Oe Og a hg a Cem name 7 oF fe Gey type T7 USARTO BASE dev base OF Gey Trg NUL rodey CO E7 amp dbgfiled derv dch DebugOInit FECT Ai 7 D buguTOCrl dey OCEL Ny NULL dey ready DebugWrite f GET WEES 77 DebugOpen ev open DebugClose dev close NULL LX GOI SiZe Wy be When an application calls NutRegisterDevice amp devDebugO 0 0 then Nut OS calls the function that dev init points to DebugO nit in this case On success the driver is added to the linked list
18. int TOUES CONST ehar String FILE Stream size t tread voOLd DULIer SIze t Suze S126 Count ELLE T Sr ream FILE freopen CONST char name CONST char mode FILE stream int fscanf FILE stream CONST char fmt rat FSeek PILE lt stream long offset int origin long ftell FILE stream Size tt TWrire CONS void data Size ck Size Size C Count PILLE stream y int getc FILE stream int getchar vor int kbhit void char gets char buffer ine Prine CONG Ghan ASEME une 3p Ine puUCCUNnt FILLE stream 40 Nut OS int p tchar int cJ Int DUES CONST obhar string int scanf CONST char fmt int SPLINE char burrer CONST char SIME 22 3 Inet sacan CONST char suring CONST char TEME sawt i e UNGe ec int Cc FILE Srream Ht VEpErNcr CE Lon Stream CONST Chat Simo Ve viSt ap Dt Viscant A ELLE stream CONST chat stmt Ve cst sap s inte ysprinti enar Spur hers CONS Char imt vedas ap yy Int vssecant CONS char string CONSI char imt va 11Sst ap In addition the following low level I O functions are available Ine 26 OSe ime Cy Ine Openr CONS char name 2nt mode int read int Tdr woud OurLer Size C Count Ine WrreeGint Tdp CONST Voids pUre Size C COUN HE LOCHIN Tay Int Cmd vord bur rei 7 long fibelengen ine Td This set of functions allows to port many existing PC applications
19. mkdir build Starg t cd build Starget configure target Starget prefix Sprefix enable interwork enable multilib make make install Cd teu as Finally build and install the cross compiler cd gcec 4 3 3 build STARGET make make install GO athe In an additional step we may strip the installed binaries to save disk space and decrease load times strip PREFIX bin strip PREFIX STARGET bin strip SPREFIX libexec gqcc STARGET 4 3 3 15 Nut OS Software Manual Installing AVR32 GCC on Windows and Linux Support for the AVR32 platform is available since Nut OS 4 9 and still experimental Readily built binaries of the AVR32 GNU toolchain are available for download at http www atmel com Installing Nut OS Installing Nut OS This chapter explains how to install the Nut OS distribution either from the source code or the binary package Installing Nut OS on Windows The installation for Windows is packed into a self extracting executable installer named ethernut X Y Z exe where X Y Z has to be replaced with the version number The file contains the complete code some Nut OS tools and the API reference Not much has to be done for the Windows distribution Simply download the latest version from the Ethernut project website or run it directly from the Starterkit CD if available After starting the installer you can choose the language The selected language is used during the installation only
20. Configurator and restart it from the parent directory of nut If you are concurrently developing for multiple target boards tick Enable multiple configurations This will link all settings to the configuration file and they don t need to be re entered when changing the target M Configurations NutConf Settings CBE Settings x Usually only the Platform entry needs to be adjusted on sas Toe Sa the second page see table below The entries for include Tabada fut Browse Platform eer directories are used when adding custom modules Header files in the First directory can replace existing files those in the Last entry will be added if not found elsewhere The mu oresanes Build Directory will be created when building Nut OS and ae the resulting libraries will be placed in the nsta Directory which when left blank is named lib and located in the Build Directory build directory If developing for multiple targets you may Ezy use a more specific name for the Build Directory e g a ______ a nutb ld enut27b6 or nutbld eir10c 7 cancel Selected Platform Use with arm gcc GNU ARM ELF Toolchain including YAGARTO recommended for ARM targets arm gccdbg Same as arm gcc but includes debug information avr gCC GNU AVR Toolchain including WinAVR recommended for AVR targets avr gccdbg Same as avr gcc but includes debug information
21. MMCO 1 PHATO where WMCO is the name of the block device driver 7 specifies the number of the partition to mount and PHATO is the name of the file system driver instance Device Drivers As opposed to desktop computers tiny embedded systems do not provide a memory management hardware unit to protect memory areas or I O port access As a result there is no special kernel mode for device drivers to run in Thus there is no requirement for a device driver at all To phrase it favorably application code can freely use any kind of resource One advantage of device drivers is still left for Nut OS Abstraction If a device driver exists for let s say an LCD display it may be used with stdio streams like other devices Device usage can be switched easily by changing a few lines of code Look at our Hello world output going to an LCD include lt stdio h gt include lt dev hd44780 h gt include lt dev term h gt int main void Register the device we want to use NutRegisterDevice amp devLcd 0 0 Assign the device to stdout freopen led w stdout prine Hello world in y All device drivers are based on the NUTDEVICE structure struct NUTDEVICE NUTDEVICE GeV next char dev name 9 uint dey type ULn Cp ir dev Dace Hato T dev Ird void dev cb void dev Geb Int dev Init NUTDEVICE Lae dev Voce ANUIDEVICE Sy TAC VOLA TI
22. Nut OS Software Manual As stated earlier the main application thread is already running as a thread together with the background idle thread which ts not visible to the application Creating a new thread is done by calling NutThreadCreate The code running as a thread is nothing else than another C routine To hide platform specific details applications should use the THREAD macro to declare those routines THREAD Threadl arg FOR AF A NutSleep 125 int main void NutThreadCreate t1 Thread i 0 512 for NutSleep 125 In this example the main thread creates a new thread before entering an endless loop The new thread will run in a similarly senseless loop It is important to keep the cooperative nature of Nut OS in mind NutSleep which will be explained next stops execution for a specified number of milliseconds If one of the loops would not call this or any other blocking function like reading from a device or waiting for an event then the other threads would never gain CPU control However there is an pre emptive component too because threads may be interrupted by hardware interrupt signals Thus special care is required when writing interrupt handlers and almost all API calls are forbidden when executing in interrupt context except NutEventPostFromlIrq Heap Management Dynamic memory allocations are made from the heap The heap is a global resource containing all of the free me
23. a button to use a folder selection dialog Make sure caiete srther fader CNet ts garena n ATT dek that the directory name doesn t contain spaces On English language systems you should always avoid Program Files when using tools that have fisa E a c programmelyagarto 00000 Browse been derived from Unix like systems When done click Next Se Hh ee VEGERIO 4 3 Z0090S11 lt Back Next gt Cancel YAGARTO 4 3 3 Setup X Click nsta to start the installation Choose Start Menu Folder Choose a Start Menu folder For the YAGARTO 4 3 3 shortcuts p W Select the Start Menu Folder in which you would like to create the program s shortcuts You can also enter a name to create a new folder Advanced Port Scanner andLinux Asus Atmel AYR Tools ATMEL Corporation aTunes Autostart Avidemux Avisynth 2 5 ComLink_Oasis C SNT zl I Do not create shortcuts PAGERE 4 313 ZUUSUS1T lt Back Install Cancel YAGARTO 4 3 3 Setup lel EG The status of the installation progress is Ep Installing displayed When completed click the Next 2 Please wait while YAGARTO 4 3 3 is being installed b u tt on Extract redboot syscalls o VAGHHIG 4 39 2uusual1 12 Installing a Cross Toolchain YAGARTO 4 3 3 Setup iOi x Clicking the Finish button will close the installer Completing the YAGARTO 4 3 3 Setup Wizard YAGARTO 4 3 3 has been inst
24. a specific port number on which they listen for connection requests The port number of clients are automatically selected by Nut Net Nut Net provides a socket API for the TCP protocol as well as the UDP protocol The first step is to create a socket by calling Nut cpCreateSocket or NutUdpCreateSocket TCP server applications will then call NutTcpAccept with a specific port number This call blocks until a TCP client application tries to connect to that port number After a connection has been established both partners exchange data by calling Nut cpSend and NutT cpReceive A simple TCP client looks like this TCPSOCKET sock NutTcpCreateSocket NutrepConnect Sock Tnet ddr 7192 bos 102 2 yy 30 NutTcpSend sock Hello r n 7 NutToepRecet ve sock buff Sizeof puff NutTcpCloseSocket sock A Nut Net TCP server looks similar TCPSOCKET sock NutTcpCreateSocket NutTcpAccept sock 80 NutTcpReceive sock buff sizeof buff NutPeosend sock 2ZU2 rin D NutTcpCloseSocket sock Furthermore Nut OS allows to attach TCP sockets to standard I O streams which makes our code look more familiar The following line is used to attach a connected socket to a Nut OS stream Stream gt fdopen IntI UDE LI OC ky TETI The code can use fprintf fouts fscanf fgets and other stdio functions to talk TCP 50 Nut Net UDP server applications will provide their port number when calling NutUdpCr
25. back on and select n System Programmer from the Tools menu Then select the file httpserv hex for the FLASH by clicking on the Browse button We do not need to program the EEPROM Now press the button labeled Program FLASH EEPROM to start in system programming This takes some seconds Some versions of ICCAVR display an error message on empty EEPROM entries You can ignore this Finally press the OK button to close the n System Programming window Your Ethernut Board will immediately start the webserver application waiting for a web browser to connect In System Programming Programmer Interface NOTE NT 2K users must C STK 200 300 have administrative privilege to use the parallel port I Prog interface STK SOO AVRISP STK500 requires AYR Studio C DT 006 to be installed C STAVER STAVER is for the Lawicel s st4VeR bootloading mode It does not support EEPROM or come z verify function ISP Options Additional STK500 exe command line arguments I NO Erase Auto Program After Compile with Flash from project and selected EEPROM option M Verify After Programming gt Advanced Manual Mode 0x for HEX Lock Bits R w Fuse Bits m w aS Use Projects Gptons gt Device setna Chip Erase NB 1 unprogrammed 0 programmed Please refer to the device specific datasheet for lock bits and fuse bits descriptions M Target Device Setting f Perom laget sianature when
26. binutils releases binutils 2 19 1 tar bz2 curl 0 ftp gcc gnu org pub gcc releases gcc 4 3 3 gcc core 4 3 3 tar bz2 curl 0 ftp gcec gnu org pub gcc releases gcc 4 3 3 gec gt 4 3 3 tar bz2 curl 0 http download savannah gnu org releases noredirect avr libc avr libc 1 6 7 tar bz2 curl 0 http download savannah gnu org releases noredirect avrdude avrdude 5 7 tar gz Unpack the packages tar Ky tT DINU t LLS A rLla e Dz tar x Gec Core 4 33 3 ban bZ2 tar x GCC t Ae 3 58 tarco7Z tel Kur Grea Dea lata a DAA tat xzf avrdude 5 lt starsgz 10 Installing a Cross Toolchain Now we set two useful environment variables and create a bin folder in advance which we add to the PATH variable TARGET avr export TARGET PREFIX usr local STARGET export PREP IX sudo mkdir p SPREFIX bin PATH SPATH SPREFIX bin export PATH Start with building and installing the binutils od binutrle 2 19 1 mkdir build STARGET cd build STARGET configure target STARGET prefix SPREFIX enable languages c c disable nls disable libssp with dwarf2 make sudo make install Cd aa au Next build and install the compiler ed g C6 44 3 3 mkdir build S TARGET cd build STARGET configure target STARGET prefix SPREFIX enable languages c c disable nis disable libssp with dwarfz2 make sudo make install ed 267 ma To build and install the runtime library use cd avr libc 1 6 7 mkdir buil
27. consistently Driver instances may have the same name if they refer to the same hardware For example instead of limited devDebugO instance the Ethernut 3 application may register devUartO which is fully interrupt driven and also provides a dev read routine for data input Both instances have the same name because both use the same USARTO hardware Only one of them can be used because NutRegisterDevice will reject a device instance if one with the same name is already registered Not every hardware device fits well though For example SPI is very special In order to receive a byte one byte has to be sent out Even worse this interface may run in master or slave mode may change the mode dynamically and multiple different devices may be attached to SPI A similar situation exists with I2C or in general with all devices that implement busses Especially for SPI a special device driver type named NUTSPIBUS has been implemented which completely differs from the NUTDEVICE type However white bread device driver instances may be attached to it using int NutRegisterSpiDevice NUTDEVICE dev NUTSPIBUS bus int cs The following code fragment attaches the MP3 decoder driver devSpiVsCodecO to the first SPI bus on an AT91 CPU and sends a buffer with encoded MP3 data to the decoder NutRegisterSpiDevice devSpiVsCodecO spiBusOAt9l1 0 more code int 2d open audio0 O WRONEY O BINARY WweEce ad bur Leni clo
28. implement specific functions Usage of the remaining entries dev base dev _ irq dev_icb and dev dcb is typically up to the driver code Specifically the last two are often used to store pointers to some local data This way the driver is also able to use the same function for all of its instances For example the second debug device instance for USART1 on Ethernut 3 IS NUTDEVICE devDebugl Oy GE Me 2 Ay te ge tee ey ERS es Oe Og TON Wigs ale ext name y Oy E GET type 7 44 Nut OS USART1 BASE dev base oF i Gey irg NULL Pe GST CS amp dbgfilel fr dev deb DebuglIinit LE OGY Aa 7 DebugliOCily JA dero OCEL Ny NULL i GET roada DebugWrite GEN MEICS DebugOpen f Gov open 7 DebugClose dev close NULL rE dey S297 by Here the same routines are used for dev open dev write and dev close In some cases the system will verify dev_type to make sure that the right device driver is used Currently known types are RAM device ROM device Stream device Net device TCP socket Character stream device CAN device Block I O device File system device define IFTYP RAM define IFTYP ROM define IFTYP STREAM define IFTYP NET define IFTYP TCPSOCK define IFTYP CHAR define IFTYP CAN define IFTYP BLKIO define IFTYP FS NwAYnDoaRPWNEF OO H but as you can see in the devDebug structures above they are not used
29. loop of sleeps The main thread waits for an event posted to an event queue Event queues are specified by variables of tyoe HANDLE The endless loop of the main thread is blocked in NutEventWait and woken up each time an event is posted by Thread1 Btw it had not been very smart to introduce the variable tyoe HANDLE But it s there since the very early releases of Nut OS and most people don t care much Stream I O Typical C applications make extensive use of the standard I O library In most cases the runtime library that comes with your compiler provides the related API However only very simple devices are typically supported or in case of newlib a Linux like kernel is expected Therefore Nut OS provides its own library nutcrt which replaces almost all related functions of the compiler s runtime library For a tiny operating system like Nut OS the list of available functions is quite impressive void clearerr FILE stream int fclose FILE stream void fcloseall void EILE fdopen int fd CONST Char mode 7 int feof FILE stream int terror FILE stream int fflush FILE stream int fgetc FILE stream char Egets char burtrers 10t counts FILE stream int Trleno FILE Stream void lt Fiushall void FILE fopen CONST char name CONST char mode ine forinti FTLE lt orreem CONST Char imi 2 int fpurge FILE stream int TpuUte int Cp PILE Stream
30. more files containing specific settings As a special highlight the GUI version even creates project files for ImageCraft Except for the demo version building applications with the ImageCraft compiler on the command line is still supported and may have its advantages but users of this tool may not worry to skip this chapter Running make As usual open a shell window aka DOS box on Windows or terminal on OS X and change to the directory httpd in the application sample directory we created with the Configurator On Linux and OS X something like this should work cd ethernut nutapp httpd Windows users may enter something like Gi cd ethernut X Y Z nutapp httpd and additionally need to set the PATH environment for ARM targets set PATH c ethernut X Y Z tools win32 C Program Files yagarto bin SPATH or AVR targets with WinAVR set PATH c ethernut X Y 2Z tools win32 C WinAVR bin C WinAVR utils bin PATHS or AVR targets with ICCV7AVR set PATH c ethernut X Y Z2 tools win32 C iccv7avr bin PATHS Note that these are just examples You may have installed Nut OS or your toolchain in different locations and need to adjust the paths accordingly The PATH setting is valid for the current window only and must be entered each time you open a new command line window Thus it is a good idea to store it in a batch file e g setenv cmd and call this instead The following commands are the same for all operating systems and targets
31. of registered drivers sooner or later the application will call FILE fp fopen uart0O w or similar to open the device Nut OS will now retrieve the NUTDEVICE structure from the linked list of which dev_name contains the string uartO and then call the function the dev open member points at Hence DebugOpen is called which returns a pointer to a NUTFILE structure Among other things this structure contains a pointer to the NUTDEVICE structure The system will now create a stream variable of type FILE store the NUTFILE pointer in it and return the FILE pointer back to the application When the application calls forint rt ip Hello worlal ya then the system is able to retrieve the both the NUTFILE pointer and the NUTDEVICE pointer The latter is used to call DebugWrite via the dev_write member passing the NUTFILE pointer and the string to print to the driver The driver will then do the required work to send out character by character using the USARTO hardware registers You may have noticed that two function pointers contain NULL The debug device is write only thus no dev_read function exists The system will return an error when an application tries to read from this device The dev size entry is a legacy item It had been used in early days to retrieve the size of a file and was re used later to query the number of bytes available in the input buffer In general drivers should use ioctl commands instead to
32. that step The Nut OS configure script will detect missing parts automatically Make sure that the latest build tools available sudo apt get install build essential automake autoconf 18 Installing Nut OS The Nut OS Configurator s GUI is based on wxWidgets which uses GTK on Linux systems wxWidgets is a C class library which allows to create GUI applications that look and feel native If available you can simply install the binary packages sudo apt get install libwxgtk2 8 0 libwxgtk2 8 dev wx2 8 headers wx common If binaries are not available you can build wxWidgets libraries from source code sudo apt get install libgtk2 0 dev wget http ovh dl sourceforge net sourceforge wxwindows wxGTK 2 8 10 tar gz tar XZ wxGiKe2 gs10 taisg cd wxGTK 2 8 10 mkdir purld gtk2 ansi static cd build gtk2 ansi static configure disable shared make sudo make install In the next step we are going to install the Lua language which is used later by the Nut OS Configurator to parse the configuration files Binaries should be available for most Linux distributions sudo apt get install lua5O liblua5O liblua5O dev liblualib5O liblualib50 dev Note that version 5 0 is required version 5 1 will not work Again this package can be built from source code Download lua 5 0 3 tar gz from www lua org and gzip d downloads lua 5 0 3 tar gz tar xf downloads lua 5 0 3 tar ed Lua 5s 0 137 The Lua source archive doesn t provi
33. the driver creates a network buffer with all data stored in the datalink substructure The Ethernet layer will then split this buffer by simply setting the pointer of the network buffer substructure beyond the Ethernet header and adjusting the buffer lengths before passing the packet to the IP or ARP layer This procedure is repeated by each layer and avoids copying data between buffers by simple pointer arithmetic When application data is passed from the top layer down to the driver each layer allocates and fills only its specific part of the network buffer leaving buffers of upper layers untouched There is no need to move a single data byte of an upper layer to put a lower level header in front of it 53 Nut OS Software Manual Reference Material Books Comer D Internetworking with TCP IP Vol I Principles Protocols and Architecture Prentice Hall Covers many protocols including IP UDP TCP and gateway protocols It also includes discussions of higher level protocols such as FTP TELNET and NFS Comer D Stevens D Internetworking with TCP IP Vol Il Design Implementation and Internals Prentice Hall Discusses the implementation of the protocols with many code examples Comer D Stevens D Internetworking with TCP IP Vol lll Client Server Programming and Applications Prentice Hall Discusses application programming using the internet protocols It includes examples of telnet ftp clients and servers Stevens W
34. 21b bnutbld 21b cnut conf ethernut21b conf lnutbld 21b lib mavr gcc create apptree cd nutapp 21b events make clean all Of course we need to call nutconfigure for the first time only and each time the configuration is changed But how to change the configuration without GUI A simple text editor will do All configuration items of the module tree in the GUI version are stored in the conf files in human readable format Configuration items which are modified in the setting dialogs of the GUI version are provided as command line options For example in the nutconfigure given above we did not specify the programming adapter If you check the usage help you will notice that this means to stay with the default avr dude bracketed value More details about creating Nut OS applications are presented in the next chapter 2 Nut OS Software Manual Building Applications on the Command Line In this chapter we will build the web server application that is included in the Nut OS distribution It is assumed that you built and installed the Nut OS libraries and that you already created an application sample directory with the Configurator Basically Nut OS applications are built on the command line This is even true when using an IDE like the ImageCraft IDE or Eclipse where the command lines are executed internally When creating a sample directory the Configurator copies all samples from the source tree to this directory and adds a few
35. 3 Press Page Down to see the rest of the agreement GNU GENERAL PUBLIC LICENSE Version 3 29 June 2007 Copyright C 2007 Free Software Foundation Inc lt httpif FsF ora gt Everyone is permitted to copy and distribute verbatim copies of this license document but changing it is not allowed Preamble gt vv If you accept the terms of the agreement select the First option below You must accept the agreement to install YAGARTO 4 3 3 Click Next to continue Ido not accept the terms in the License Agreement VEGERTO 4 3 3 20090311 lt Back Next gt Cancel YAGARTO 4 3 3 Setup ii gs Although checked by default you may prefer not to have YAGARTO directories added to your Choose Components Choose which features of YAGARTO 4 3 3 you want to install p 7 P AT H e n vi r O n m e n t N u t i O S a l O W S to a d d t h e m E pd eee ae to install and uncheck the components you don t want to to the settings later This provides more control x Select components to install inutils 2 19 especially when switching platforms Novi 17 0 GCC 4 3 3 GDB 6 8 50 Add YAGARTO to the PATH variable Space required 288 4MB VEGERTO 4 3 3 20090311 lt Back Next gt Cancel YAGARTO 4 3 3 Setup 1x Now choose the installation folder You can either gt Choose Install Location 5 hoose the Folder in which to install i Bo enter the path manually or press the Browse 2 is
36. All other parts and the Nut OS documentation are available in English only After selecting the installer language and clicking OK a welcome screen appears Click Next to continue Welcome to the Nut OS Setup Wizard Nut OS 4 4 0 0 The next dialog lists all Nut OS components which are included in the installation If unsure leave Full selected and click Next to continue amp Y Nutjos F Nut Net E Z Manual anuals 8 Development Tools acd Application Sample Ethernut Bootloaders You can now select the installation directory By default all files will be installed in C ethernut xX Y Z It is recommended to leave it that way In any case avoid directory names containing spaces Click nstal to start the installation Sel sel tup will install Nut OS in the Following folder To install in a different Folder click Browse and lect another folder Click Install to start the installation The next dialog will show the installation progress This will take a few seconds You can click Show details to view the list of files being installed Nut OS 4 4 00 17 Nut OS Software Manual When all files have been copied to the installation directory a final dialog appears Leave the checkbox to Start Nut OS Configurator unchecked Click Finish to close the installation wizard Installing Nut OS on Debian Linux Unfortunately there is no binary package available yet The installation for Linux i
37. Data emn z Cancel available For Linux minicom and gtkterm are good seid new alternatives OS X users may use the build in screen ee SJ i command The required settings for the serial port are eatery on 115200 Baud eight data bits no parity and one stop bit o aeo e All handshakes must be disabled W Tera Term COM1 YT File Edit Setup Control Window Help Make sure that the target board is connected to your local network Resetting your target by pressing the reset button will produce some text output in the terminal emulator s window The text on your system may differ depending on your network configuration ut 0 4 8 2 0 HTTP Daenon Conf igure ethO 0K 92 168 192 146 ready D Mozilla Firefox Datei Bearbeiten Ansicht Chronik Lesezeichen Extras Hilfe Start a web browser on your PC The URL to request is the IP address which has been C printed on the terminal emulator If everything went well you will see the main index page of the Ethernut webserver Welcome to Ethernut HTTP Flash demo Congratulations your embedded webserver is Server side inciude demo working ASP demo CGI Samples The following chapters will introduce Nut OS and Nut Net in more detail Some of you may not be able to follow every part Don t worry CGlIs may be placed in different directories and may have different access controle Login for the paramter and form demo Login user Try to code a fe
38. Ethernet to resolve IP and MAC address relations PPP The Point to Point is as an alternative to the Ethernet protocol and can be used with serial ports modems GPRS etc Nut Net provides PPP client mode only That means other nodes can be actively connected but Nut Net can t listen to incoming connection attempts This is related to establishing PPP connections and should not be confused with TCP UDP client and server capabilities which are fully available over PPP 52 Nut Net Network Buffers Nut Net uses a special internal representation of TCP IP packets which is designed for minimal memory allocation and minimal copying when packets are passed between layers Application programmers don t need to care about this internal stuff It is included here in case you might become interested in looking into the Nut Net source code Network buffers are one of the central data structures within Nut Net A network buffer structure contains four equal substructures each of which contains a pointer to a data buffer and the length of that buffer Each substructure is associated to a specific protocol layer datalink network transport and application layer An additional flag field in the network buffer structure indicates if the associated buffer has been dynamically allocated Network buffers are created and extended by calling NutNetBufAlloc and destroyed by calling NutNetBufFree When a new packet arrives at the network interface
39. I N EANA er eT ETEN TETA A re Te Tree 48 Network COonfiguration cccccccceeseeeeeeeeeeeeseeeeeeeeeeeseeeeeesetageesegeessageetauenseages 48 DOCKCE PAP Neca seers tanieinerias E E EE 5O BU ccna E E E A E A E aan A 51 LO NIP aer I E E E 52 PRP E E EE E E EE E E E PE EE EE ins E EE EE tans 52 PEP eea E E E E E E EEEE 52 NOTWOTK BUTTO errre arr EE EEEE E E E 53 vet ee ee Maternal eran ratiainereos nau neanennens manana EE Eeri 54 BOOK a E E AE O E sare eaeaeneriadeks 54 pE A EEE EEEE AE E EEE E EE E E en nT re 54 Nut OS Software Manual About Nut OS and Nut Net Nut OS Features Nut OS is a very simple Realtime Operating System RTOS providing the following features Open Source Modular design Highly portable AVR and ARM available more to come s Cooperative multithreading Event queues Dynamic memory management Timer support a Stream I O functions Expandable device driver interface File system support Nut Net Features Nut Net is a TCP IP stack providing Open Source ARP IP UDP ICMP and TCP protocol over Ethernet and PPP Automatic configuration via DHCP HTTP API with file system access CGI SSI and ASP functions SNTP DNS Syslog TFTP FTP and more TCP and UDP socket API for other protocols What to do first Installing the Nut OS development environment is done in three steps We will first install the cross compiler and related tools also known as the toolchain T
40. RegisterDevice The include file board h defines the default network device for all supported boards so the following code should work on most targets include lt dev board h gt NutRegisterDevice amp DEV ETHER 0 0 In a next step the IP interface must be configured To do this the following information is needed v Hardware address of the interface Ethernet uses a 6 byte MAC address v Local IP address and a related network mask v Optional routing information typically the IP address of a default gateway Nut Net supports IPv4 where IP addresses fit into 4 bytes Thus the 32 bit type uint32 t is used for the binary representation The conversion functions inet _ntoa and inet_addr are provided to convert the binary version into human readable format and vice versa The following code fragment may be used as a template to configure an Ethernet interface including a default gateway 0x00 Ox06 0x98 0x00 0x00 0x00 inet addr 192 168 0257 Inet addr V29 nce Inet adar 192 168 0 1 3 uint8 t mac 6 UiInNtS2 ip addr uint32 t ip mask int2 t ip gate Noo Il as NutNetlfConfig DEV ETHER NAME mac 1p addr 1p mask NutIpRouteAdd 0 0 ip gate amp DEV ETHER For real world applications hard coded IP addresses are not practical though We can use non volatile memory to have these settings available on each reboot Nut OS offers standard routines to store and load the basic network configuratio
41. SP utility with STK500 compatible adapter not recommended avr32 jtagicemkii Atmel s AVR JTAGICE MKII and AVR32 targets 22 Programmer Using the GUI Configurator Use with gba xport2 CharmedLabs xpcomm utility for GameBoy Advance In most cases it will be necessary to edit the related command file You can find them in the directory nut app with Makeburn as their base name and the programmer as their extension e g Makeburn avr dude If unsure just leave everything as It is There are many alternative ways to upload the binaries to the target Check your hardware manual for additional informations If an error message window pops up after clicking OX a path may have been incorrectly entered or a directory does not exist Please check your paths and directories again especially in the Tools entry Look for unintended spaces or any extra characters typed by mistake as well The paths and directories containing spaces like the default Program Files directory in several language versions of Windows have to be enclosed in quotes Back in the Configurator s main window it may be required to adjust the compiler selection in the module tree specifically when using ImageCraft When building for ARM targets and using newlib 1 17 or later it is further required to select the option Posix compatible unsetenv This is annoying because the newlib maintainers reject to provide a version entry that can be processe
42. TDEBUG USE ASSERT is enabled the following message is displayed fseek c 72 Fatal Expected stream NULL in fseek It is also possible to implement NUTFATAL directly in the application and use other methods to report errors The function prototype is vord NUDPATAL CONST char fune CONST Char raive mE ime CONST char expecred One of the most subtle challenges for application programmers is to determine the proper stack size of threads The typical approach is trial and error Adding HWDEET DNUTDEBUG CHECK STACK 46 Nut OS to UserConf mk allows to list the maximum stack usage of all threads by using a simple loop NUTTHREADINFO tdp tor tdp Nutihreadbisty tdp tdp tapeta next printr sst clu bytes stack available n tdp gt td name unsigned long NutThreadStackAvailable tdp gt td_name Internally the system fills the stack on thread creation with a specific pattern The NutThreadStackAvailable then walks from the stack s bottom until it finds the first location that no longer contains the original pattern to determine the number of unused stack bytes If you try to make sure that all parts of your application had been executed and that the application was running long enough you can use the values with a certain safety margin to fine tune your stack sizes More advance debugging capabilities are offered for target platforms which at least offer a minimal protection such as hardware exceptions Currentl
43. TO TEST TXT w Lf p d fprintf fp HelloFile fclose fp else File open failed Like other devices the system will not include any file system support by default Though UROM and PNUT file systems are immediately available after the file system driver has been registered Use include lt dev urom h gt NutRegisterDevice amp devUrom 0 0 for UROM and include lt dev pnut h gt NutRegisterDevice amp devPnut 0 0 for the PNUT file system PHAT volumes must be explicitly mounted include lt dev board h gt include lt fs phatfs h gt more code RIV AVOL Register the file system driver NutRegisterDevice amp devPhat0O 0 0 Register the Drock device driver NutRegisterDevice amp DEV MMCARD 0 0 Mount the file system on the specified device hvol _open DEV_MMCARD NAME 1 PHATO _O RDWR _O BINARY more code Unmount the file system if no longer used JGlLose aved 7 42 Nut OS Different block device drivers are available on different target platforms The example above makes use of the header file board h which defines the default DEV MMCARD and its related DEV MMCARD NAME for the currently used target hardware This ensures that the code will compile on all supported targets without change For the Ethernut 3 board devNp MmcO is the block device used to access the MMC socket The mount name for this board will be
44. WAY OUT OF THE USE OF THIS DOCUMENTATION EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE Table of Contents Para Nut Oc and Nec dnniacia iiine irssteciautdany EENS 4 NOT OS Fea OS ares a E E E EE E E 4 Nut Net FeatureS nussnnsnsrensnnrrrrnrrrrrrerrrrrrnrerrrrnrnrerrrrnrnrrrrnrnrrrrnrnrnrrnrnrrrrnrn 4 aeS Ee eE a TEE E E EE E EE E E E AE EE 4 Aang a CoS WONG all eA AEE EERE EEEIEE RARIS 5 Moala YIA YR aeree N EE FEEN 5 nstaling MADSCI Ale AV Ressssrricierrerseriso nabr ee riere EErEE EEEE eE ETRE 7 Installing AVR GCC on Debian LINUX ccccc eee e cece cece eeeeeeeeeeenesteueeesaueetaneenees 9 Installing AVR GCC on other Linux CIStrIDUTIONS cccccceee ee eee eee eeeeeenneeeeeeeeeeas 9 Installing AVR GCC on OS X s nasasssnsarennnrrrnrrnrrrrrrrrrrrrrrrrrrrrrerrrrrrnrerrrrrrrrnrnrnne 10 Installing YAGARTO orn WINdOW Siw iss vaeesieerisevavicstuaadaveurigtieeneoiniiemer sia tiaans 11 Installing ARM ELF GCC on LINUX ines riisseesites iceseaseriniesp ieee neeenineenierineni 13 Installing YAGARTO on OS X cece cccccceeee eee e eee eeeeeeeeee eee eeeeeeneeeeeeeeeteeagenstaeeetags 14 Installing ARM ELF GCC on OS XX ccc cccccc cece cee ceeeee eee e ee eaeeeseneeseneeesanensegenseages 14 Installing AVR32 GCC on Windows and LINUX cccccceee eee e ee eeeeeeeeeeesaeeeeanees 16 daere ae a0 216 Serre eee ee ee E een ee ore ere ener re ore eee 17 Installing NUt OS ON WINKGOWS cccccecceceeeeeeeeeeeeneeeeeeee
45. alled on your computer Click Finish to close this wizard Visit the YAGARTO site For the latest news lt Back Finish Installing ARM ELF GCC on Linux If no binary package is available for your specific Linux distribution you can build the toolchain from the source code In a first step we need to make sure that all required build tools are available The following shell command will install any missing parts sudo apt get install build essential autoconf automake Next create a directory where we will build the toolchain and change to this directory mkdir toolchain avr cd toolchain avr Get the source packages wget f tp occ qnu org pub binutils releases binutils 2 19 1 tar bz2 wget ftp gcec gnu org pub gcc releases gcc 4 3 3 gcec core 4 3 3 tar bz2 wget ftp gcec gnu org pub gcec releases gcc 4 3 3 gcec gt 4 3 3 tar bz2 wget ftp sources redhat com pub newlib newlib 1 16 0 tar gz Unpack the packages tar x Dinu utils 2 19 l tar D22 tar XJi CC COrS lajao etare D22 tar x OCCHO7r 4 345 lt tar bz tar xzf newlib 1 16 0 tar gz Now we set two useful environment variables and create a bin folder in advance which we add to the PATH variable TARGET arm elf export TARGET PREFIX usr local STARGET export PREFIX sudo mkdir p SPREFIX bin PATH SPATH SPREFIX bin export PATH Start with building and installing the binutils ed binutils 2 19 1 mkdir build STARGET cd build STARGET
46. ary with possibly incompatible licenses libnutcpp a C runtime extension library libnutcrt a Target specific C runtime library libnutdev a Device driver library libnutfs a File system library libnutgorp a Snippet collection library libnutlua a Lua language support library libnutnet a Network library libnutos a RTOS kernel library libnutpro a Application protocol library If this fails check your settings again The log output at the bottom should provide additional hints If you still can t determine the problem try the command line to get a more detailed error report Open a command line shell on Linux DOS box on Windows or Terminal on OS X and change to the build directory On Windows you must set the PATH environment each time you open a new DOS box set PATH lt tools path gt sPATH Replace lt tools path gt with the entry in the Tools settings For example with WinAVR you would enter something like set PATH C ethernut 4 8 3 nut tools win32 C WinAVR bin C WinAVR utils bin PATHS On Linux and OS X this is typically not required To manually build the libraries enter make clean all install At the end you should see some kind of error message If you need further help check http www ethernut de en support index html about how to get further support 24 Using the GUI Configurator When the libraries have been successfully installed the last task to be done in the C
47. as amp Recursive strtok void Function This will help to avoid lunseteny Newlib since version 1 17 0 declares unseteny returning unseteny was here make 1 seteny o Error 1 make all Error 2 make all Failed with error 2 Nut OS Configurator eir10c OF Xx File Edit View Build Help Build Nut OS Property Value Create Sample Directory E Architecture H ATOS Kernel H Device Drivers _ E C runtime tool specific E C runtime target specific 5 amp Gorp Code snipped library H Network general i he L ic filu RUT Ul UUW Server CUUS UUIU of fu DE VILE FALK lt 12 27 10 Working in C ethernut 4 8 3 12 30 39 Loading nut conf repository nut 12 30 39 Loading C fethernut 4 8 3 nut conf feir10c conf 12 30 39 OK Builds Nut 0S libraries Nut OS Configurator eir10c Oy x File Edit View Build Help Ben Nut OS Components Nut OS 4 8 3 C Generate Build x H Tools Architecture i H ATOS Kemel 4 Source directory nut HE Roe ma E neues C runtime tool itd ales H C runtime targe Do you like to generate this build tree E Gorp Code snil H Network genei IEE T i2f iU RUN OT v 12 27 10 Working in C jeererree rrere 12 30 39 Loading nut conf repository nut 12 30 39 Loading C fethernut 4 8 3 nut conf eir10c co
48. avr ICc ImageCraft V6 for AVR do not use this for new projects avr icc ImageCraft V7 for AVR recommended for ATmega128 and ICCAVR compiler avr iccext Same as avr icc but for ATmega256 targets not for new projects 21 Nut OS Software Manual Selected Platform Use with avr icc ext Same as avr icc recommended for ATmega256 and ICCAVR compiler avr32 gcc GNU AVR32 Toolchain requires Nut OS 4 9 or later avr32 gccdbg Same as avr32 gcc but includes debug information h8 gcc Lack of maintenance may no longer work UNIX gCC Nut OS emulation on Linux poorly maintained but may work The entry on the third page is required on Windows only and should contain the path to the Nut OS tools directory If you deselected the PATH update during compiler installation then add these paths here All paths must be separated by semicolons and must not contain spaces Make sure that the path to the Ethernut tools directory comes first While based on Linux tools path components in the Nut OS configuration are typically separated by slashes However in the Tools Path you must use backslashes On Linux and OS X you should leave this entry empty The actual tool path depends on the toolchain and its installation directory For WinAVR the complete entry may look like this C ethernut 4 8 3 nut tools win32 C WinAVR bin C WinAVR utils bin For YAGARTO something like the following should work C ethern
49. conX XNUT 100 Programmable Gateway xnut 105c conf proconX XNUT 105 Programmable Gateway Rev C xnut 105d conf proconX XNUT 105 Programmable Gateway Rev D i i a i M Nut onfigurator eir10c Iof x The Configurator s main window is divided into Melee Von Bad Hee four parts The Nut OS module tree on the left Settings Ciel H Nut 0S 4 8 3 0 H Tools H Architecture E amp RTOS Kernel E Device Drivers H C runtime tool specific E amp C runtime target specific 5 amp Gorp Code snipped library Network general i z a JerviLe FALK lt side allows to modify the configuration The upper part on the right side shows specific properties of the currently selected tree item while additional help is provided in the lower Oc a part A log window available at the bottom may 4 tei ao oo become helpful if things go wrong 12 30 39 OK Shows the settings dialog Select Settings in the Edit menu to enter the Configurator s settings dialog which is divided into four pages Repository Build Tools and Samples The first page shows the relative path to the repository eae Sa cea Sa file If the main window didn t show the module tree you pace 3 fut confirepository nut may correct this path here and then reload the configuration file However most probably you started the Configurator from the wrong directory and this may introduce further problems Thus the best way is to exit the
50. d int NutEventBroadcastAsync HANDLE qhp is the same as NutEventBroadcast but similar to NutEventPostAsync the current thread continues running All posting functions return the number of woken up threads int NutEventWait HANDLE qghp uint32 t ms waits for an event If the queue is marked signaled the thread will remain ready to run and the signal mark will be removed from the queue However if any other thread with equal or higher priority is ready to run then the calling thread will lose the CPU int NutEventWaitNext HANDLE qghp uint32 t ms is the same as NutEventWait but any signal mark is ignored and silently removed All waiting functions return zero when an event has been posted within the specified number of milliseconds If no event is received within this time then the thread is woken up by the timer management and the event wait function returns 1 A time out value of zero means to wait forever which is often misinterpreted You may better use the macro NUT WAIT INFINITE instead Nut OS currently doesn t provide non blocking calls 39 Nut OS Software Manual For using events a modified version of our simple threading example will look like this HANDLE evt_h THREAD Threadl arg for Fr A NutSleep 125 NutPostEvent evth int main void NutThreadCreate t1 Thread i 0 192 tor 747 A NutEventWait amp evt_h NUT WAIT INFINITE Thread1 is running an endless
51. d again and upload the binary to the target hardware If you change any items in the Configurator later it is recommended to create the sample directory again Fortunately the Configurator will not overwrite your modified source file The easiest way to create your own applications is to create a copy of an existing sample within the same application directory If you change any source file names or add new ones you must also update the Makefile This can be done with any text editor However note that tabs have a special meaning in Makefiles and must be preserved 29 Nut OS Software Manual Building Applications with ImageCraft This chapter will be of use only if you are developing with the ImageCraft IDE It is assumed that you have built the Nut OS libraries and created a sample directory with the GUI version of the Configurator ImageCraft Configuration Launch the ImageCraft IDE If started for ar er in or a ae PIES the first time the IDE will appear without Do bl te mmi E GE ek Project Browser Itt NO PROJECT OPEN any active project Coe Al Fie Reopen gt No Open File No Open Projec Select Open from the project menu navigate to the Open Project ee ES newly created Nut OS sample directory and load the ai CECE project file httpd prj which is located in the amem subdirectory httpd Dateityp Project Files prj z Abbrechen M Schreibgeschiitzt
52. d by the compiler We have to maintain backward compatibility manually Notice the log window on the left which shows the related compile error We are finally ready to build Nut OS Select Build Nut OS in the Build menu or click the tree symbol in the toolbar After confirming the message box by clicking OK the Configurator prepares a new build directory or modifies an already existing one It creates a set of files including some C language header files in a subdirectory named include cfg These files are included into the Nut OS source code to tailor the system to your specific target hardware Nut O0S Configurator eir10c OF x File Edit Yiew Build Help Benz Tools Propery Value GCC for SRM GCC for ARM no lit GCC for AVR 4 gt GCC for Linux ImageCratt for AVR ImageCraft for ARM H GCC Settings H A i b p l 16 37 24 Nut OS Configurator Version 2 0 8 16 37 24 Linked to wxWidgets 2 8 9 16 37 24 Running on Windows Server 2003 build 3790 Service Pack 2 16 37 24 Working in C ethernut 4 8 3 16 37 33 Loading nut conf repository nut Laaa Lasdina akharmuk A O 2imuklannt inii Ne anmf Nut OS Configurator eir10c Iof Xx File Edit View Build Help EPE iz amp Formatted String 1 0 PGI Time and date W Global errno W Heap memory W Library Heap Support H Environment fag Location 256 T Fosi compatible uns int Older versions are declared
53. d STARGET cd build STARGET configure prefix SPREFIX build config guess host STARGET make sudo make install Cd an 6s Finally AVRDUDE can be installed with the following commands cd avrdude 5 7 tar gz mkdir build STARGET cd build S STARGET configure prefix SPREFIX make sudo make install In an additional step we may strip the installed binaries to save disk space and decrease load times sudo strip SPREFIX bin sudo strip SPREFIX STARGET bin sudo strip SPREFIX libexec gcc STARGET 4 3 3 Installing YAGARTO on Windows YAGARTO Yet Another Gnu ARm TOolchain is a GNU compiler toolchain for ARM CPUs Being based on MinGW Minimalist GNU for Windows it runs efficiently and without hassle on a Windows PC YAGARTO 4 3 3 Setup Setup Wizard This wizard will quide you through the installation of YAGARTO 4 3 3 relevant system files without having to reboot your computer Click Next to continue The first dialog displays some general information Click Next to continue Welcome to the YAGARTO 4 3 3 It is recommended that you close all other applications before starting Setup This will make it possible to update Bm El Next gt Cancel 11 Nut OS Software Manual YAGARTO 4 3 3 Setup X In the following window you need to accept the license Click the Next button when done License Agreement Please review the license terms before installing YAGARTO 4 3
54. d files A simple click on the target s reset button is required to upload and start the newly built binary Modifying Nut OS Samples By default most Nut OS samples use DHCP to automatically determine TCP IP settings Even without DHCP typical applications will store these settings in the on chip EEPROM and use them if DHCP is not available How this is done in detail depends on your target hardware In order to not overload this tutorial we will show how to use hard coded addresses which will work on any target Please check your hardware manual for further information about your board s configuration capabilities Open the file httpserv c in directory nutapp httod in your favorite text editor or your IDE if available The interesting entries are at the top define MY MAC x00 x06 x98 x30 x00 x35 define Mx IPADDR WO Gos 2oo derine MY LPMASK UZO0 A904 2 SOO FOC T Ine MY LPGATE 197 1664 Loar You probably have to change the IP address and may also modify the IP mask to fit your network environment Otherwise your web browser won t be able to talk to your board later on If unsure what to do better ask someone with IP network experience You can change the MAC Address to the one which you received with your board If this is not available you need to at least make sure that the address is unique in your local network When done run make clean all install or make clean all burn in this application s directory nutapp http
55. de a configure script Instead it comes with a prepared Makefile which includes a file named config This file allows to modify several build options On our system the original file worked fine but you may at least have a look at the contents To build and install the Lua tools and libraries run make sudo make install If everything worked so far almost all requirements are fulfilled The remaining packages are only needed to create the API documentation and can be left out To install them use apt get install doxygen doxygen doc graphviz Now get the latest Nut OS source code package from the Ethernut development CD or download it from http www ethernut de en download In this example we use ethernut 4 8 3 tar bz2 To keep things simple and similar with Windows installations create a folder ethernut in your home directory In the following chapters it is assumed that you did so Copy the package to this directory then unpack configure and install it It s highly recommended to use a symbolic link to the source code directory as shown below tar xj f ethernut 4 3 3 tar bz2 ln s ethernut 4 8 3 nut CA cu Oh wy configure make sudo make install UMMM MMH 19 Nut OS Software Manual Using the GUI Configurator On Windows launch the Configurator from the Windows Start Menu However if you are using the ImageCraft Demo then the Configurator must be started from the IDE Check the accompanying documentation about
56. dn_ip_ addr cdn ip mask and cdn gateway will be updated and stored in non volatile memory The function returns zero to indicate success If the DHCP query fails and if cdn ip addr is not zero then the interface will be configured to this IP address and the function will return zero to indicate success 49 Nut OS Software Manual Finally if DHCP fails and cdn ip addr is zero then NutDhcplfConfig will give up and return 1 to indicate and error As you can see NutDhcplfConfig will automatically work correctly in most environments and is the preferred way to configure the Ethernet interface Socket API On top of the protocol stack Nut Net provides an easy to use API based on sockets A socket can be thought of as a plug socket where applications can be attached to in order to transfer data between them Two items are used to establish a connection between applications the IP address to determine the host to connect to and a port number to determine the specific application on that host Because Nut Net is specifically designed for low end embedded systems its socket API is a subset of what is typically available on traditional computers and differs in some aspects from the standard Berkeley interface However programmers used to develop TCP IP applications for desktop systems will soon become familiar with the Nut Net socket API TCP IP applications take over one of two possible roles the server or the client role Servers use
57. e initial window size may become useful when you need the maximum TCP throughput The 8 bit AVR CPU running at 14 7 MHz on the Ethernut easily reaches 2 MBit with the default values One last note to a frequently asked question The number of concurrent connections is limited by memory space only It is generally no problem to run several TCP and or UDP server and or client connections on a single Ethernut The application may even use the same socket in more than one thread HTTP The Hypertext Transfer Protocol HTTP is based on TCP Nut Net offers a set of helper APIs to simplify writing Embedded Webservers which are described in detail in the Nut OS API Reference Just a few lines of code are sufficient to implement a simple webserver FILE stream TCPSOCKET sock NutTcpCreateSocket NutTcpAccept sock 80 Stream JFdopem ant GUPTE E SGCkly PETOT NutHttpProcessRequest stream fclose stream NutTcpCloseSocket sock Almost all the work is done by the Nut Net library function NutHttpProcessRequest The file system is an essential part of a webserver By default UROM is used because it is fully hardware independent and available for all targets Other file systems may be used as well by registering a different HTTP root directory Here is an example for PHAT NutRegisterHttpRoot PHATO Make sure that the file system is properly mounted 51 Nut OS Software Manual Basic CGI support is avai
58. eCraft Click the Compiler tab and verify that all options are Project Paths Compiler Target Config Salvo correctly set specifically the Macro Define s All T Stiet Chega Tea a ortability Conformance Checking Macro Define s must be separated by Spaces Note IV Accept Extensions C comments binary constants P Tint size enum for backward compatibility that CONST must not contain spaces This macro Macro Defines Undefnes a VARD_ARCH_ ATMEGS CONST together with the option Treat const as _ flash So maintains backward compatibility with ICCAVR Version T Enable 64 bit double Optimizations 6 However support for this version may be abandoned f casecanpesion in the next Nut OS release Check the following table e ee for valid entries Code Compression is only active for ADY or PRO versions MIO Global Optimizations is active only for the PRO versions 164 bits double is only active in the PRO version Cancel Set As Default Load Default Help HARVARD ARCH _ Mandatory for AVR targets ETHERNUTL Ethernut 1 x targets ETHERNUT2 Ethernut 2 x targets MCU enheticea Target boards with ATmega128 CPUs ATMEGA Mandatory for AVR targets CO For backward compatibility Click the Target tab Again make sure that the right Es nS seo i options are set Specifically check
59. eateSocket while UDP client applications pass a zero to this call in which case Nut Net selects a currently unused port number greater than 1023 Data is transferred by calling NutUdpSendTo and NutUdpReceiveFrom quite similar to the well known BSD functions sendto and recvfrom NutUdpDestroySocket may be called to release all memory occupied by the UDP socket structure While UDP read provides a timeout parameter TCP read doesn t At least not directly but some special ioctrls are available including one to set the read timeout BSD calls them socket options and so does Nut Net unsigned long to 1000 millisecs NutlepeetsockOpt Sock SO RCVIIMEO bo SILIZEO TON Like with most TCP IP stacks there is no provision to set any connection timeout value and NutTcpConnect may block for half a minute or more That s how TCP IP is designed Most people experience this from the webbrowser on the desktop PC when trying to connect a webserver that doesn t respond Nevertheless this seems to be unacceptable for embedded systems and may be changed in later Nut Net releases Another socket option allows to modify the TCP maximum segment size unsigned long to 1024 NUE TCpsetsockOpEe sock ICP MAXSHG lt mss SEZEOE mss gt It is also possible to define an initial TCP window size unsigned long win 8192 NutTepsetsockOpt sock SO RCVBUF lt winy SIZOT win 7 The maximum segment size MSS and th
60. eeeeeeeteeeeagggaaeetetagentegs 17 Installing Nut OS on Debian LInNUX ccc cece ee ceeseee scene eeeeseneeeeeeeeeesanenseuneesags 18 Jono the CBI Grea ilelll ec ile arene ts ne eer een ee ane ne rae eer ee nee rer 20 Using the Command Line Configurator s sssssssrsrsrrrrererrrrererrrrerrrrerrrrnrnrrernrn 26 Building Applications on the Command LING cccccceeeeeeeeeeeeeeeeeeesaneenetageenaenes 28 KanN TAK Oaar AE E EE EATE 28 Modifying Nut OS Samples cccccccceseeeeeeeeeeeeeeeeeeeeeeeeeeeeggeeesegueeseuueteuunteages 29 Building Applications with INVGOCCI Al sk csvacsiiineccesnatoninnnks pakiessdeeeenatwaivermsueawor russ 30 ImageCraft Configuration sessssessrsrrrrerrrrrrrrrrrrrrrnrrrrrrnrrrrrrnrrrrrrnrrrrrrrrrnrnne 30 Running the Embedded WeDSEIrVelL ccccceecceeeeeeeeeteeeeeeeesaeeeeeeetaneteeeseunetanegs 34 U ai EEE E EE E E E EEEE 35 System INIMIANZATION sssnsccawsscaveasetesvedestoasecws ceatacuncarathalesbanevsesddwtsanisendiegesecel ses 35 Tread Managemen eect enn ee ne er ee 35 picts Saiclatclel Ac ett ht nt ee ee rT tr 36 Timer Management eee eee en neat eee en eer eee te eer re 37 Event Manageme nt cccceccccceeceesseeeeeeeeeeeegeeeeeeeeeeeageeeeesteteeggaeeetsaetetannetees 39 Sites te On ee et er re 40 WERE SNS peed arse sean eee eee oe ee cece cae eon erase ea eee E 41 Device DUVE cen ee nn en rn ne ae eee eee 43 EG OF TQ MOM esae a E REE A A EA AS 46 SS 2 Ce eee AAEN ET
61. f you do not agree to the terms of A C C ep t t O a g re e z We lo this Agreement please promptly return the package 9 for a full refund GRANT OF LICENSE This ImageCraft Software License Agreement permits you to use one copy of the ImageCraft software product SOFT WARE on a single computer COPYRIGHT The SOFTWARE is owned by ImageCraft and is protected by United States copyright laws and international treaty provisions You must treat the SOFTWARE like any other copyrighted material e g a book You may not copy written materials accompanying the SOFTWARE OTHER RESTRICTIONS You may not rent or lease x IADE bukusu msu kesnakar uar rnlska tho COCTY Now choose the installation folder You can either tube Setup will install the software to the directory listed in the r amp na box below To install to a different directory either type in enter the path manually or press the Bro WSeE button he Yor a the new path or click Browse to select another directory When you are ready click Next to continue to use a folder selection dialog Make sure that the directory name doesn t contain spaces If possible ak you should stick with the default C icc7avr When P Bowe done click Next T ora ena Space available on selected drive 189757 MB Install files to this location lt Back Cancel Nut OS Software Manual Shortcut Folder Setup will add shortcut icons to the folder indicated
62. his cross toolchain allows us to create program binaries for our target CPU Windows users developing for AVR targets may choose between the commercially supported ImageCraft IDE or the free GNU Compiler Collection For all other hosts and targets the GNU Compiler is the only choice In a second step we will install the Nut OS distribution For Linux we use the source code package which requires a few more tools This should work as well for Mac OS X Windows users will directly install the binaries In a last step we will configure and build the Nut OS libraries using the tools we installed in the first two steps After all three steps have been successfully passed we are ready to create Nut OS applications Installing a Cross Toolchain Installing a Cross Toolchain A cross compiler allows to create executable code on one computer platform host which ts different from the computer target that will finally run the code In our case we will use a desktop computer under Linux Mac OS X or Windows to create binaries for running on an embedded system under Nut OS Although the compiler is the main tool more is actually required like a preprocessor an assembler a linker a librarian and several other utilities Such a collection of tools is also called a toolchain or when including a cross compiler a cross toolchain Nut OS applications may be built with almost any cross toolchain that offers ISO C compatibility The free GNU Com
63. how to configure an external tool use C ethernut xX Y Z nutconf exe as the Program C ethernut X Y Z as the nitial Directory Linux and OS X users should open a shell OS X terminal change to the parent directory of the Nut OS installation and execute nutconf e g cd ethernut nutconf When started the Configurator s splash window appears Due egnite nut os configurator to incompatibilities between Windows and GTK the window pen will not go away automatically This is usually no big deal unless you are upgrading from a previous Nut OS version In this case the splash window may cover an underlying message box which is waiting for an input Path Change Click on the splash window to close it and confirm any path Z taasen pah ras ch change message by clicking Yes Old path was C ethermut 4 8 2 nut conf New path is C ethernut 4 8 3 nut conf Switch to new path Select a file In the following dialog select the aca a configuration file that is most similar to your A board After clicking Open the selected file E will be loaded and the hardware related tenets r Deskto i configuration for this board will be i ne g automatically set by the Configurator a Eaei ea Dateiname fein Oc cont v ree Dateityp Nut OS Configuration conf Abbrechen The following table lists the configuration files and the related target hardware
64. html nosecie6 htm Important Information To view the readme file select Help gt View Readme in the IDE or open the file c SicevfavrireadmeAVR tet When the installation process is completed another dialog displays additional information about the current version lt Back On the final dialog simply click the Finish button Setup is complete and your software is now installed Congratulations on choosing ICCV for AVA Click Finish to end the Setup lt Back Cancel Installing a Cross Toolchain Installing AVR GCC on Debian Linux Binary packages are available on Debian Linux including Ubuntu To install simply enter the following command in a shell window sudo apt get install binutils avr gec avr avr libe avrdude The following packages are required to build and install an AVR cross compiler toolchain on Linux GNU AVR Binutils GNU AVR Compiler Collection AVR Libc avrdude Detailed information is available at www nongnu org avr libc user manual install tools html Installing AVR GCC on other Linux distributions If no binary package is available for your specific Linux distribution you can build the toolchain from the source code In a first step we need to make sure that all required build tools are available The following shell command will install any missing parts sudo apt get install build essential autoconf automake Next create a directory where we
65. id The size of the largest free block is returned by size t NutHeapRegionAvailable void sooner or later every C software developer will face dynamic memory issues Nut OS offers a set of useful functions to track down such problems When enabling Heap Debugging in the Configurator the standard routines will be replaced by debug versions which are slower and produce larger code The advantage is that heap management will track memory allocation Calling void NutHeapDump void stream will then send a detailed list of all memory blocks to the given stream e g stdout For each allocated block the name of the source file and the line within this file where the allocation took place is listed This is especially useful to located memory holes When Guard Bytes are enabled in the Configurator the heap manager will add extra bytes to each allocation The application may later call int NutHeapCheck void to check that these guard bytes are still valid This helps to track down buffer overwrites Timer Management On most platforms Nut OS uses the first on chip hardware timer of the CPU Though there are exceptions to this rule On several AVR devices timer 2 is used because this is timer that runs in low power mode allowing the OS to periodically wake up the system Most AT91 CPUs provide a periodic timer specifically designed for generating system ticks The Configurator allows to select this one as a system timer All remaining
66. iguration file of the target board These files are located in nut conf Below are the commands to set up a build tree for our four reference boards Ethernut 1 3 Ethernut 2 1 Ethernut 3 0 and Ethernut 5 0 nutconfigure bnutbld 13h cnut conf ethernut1l3h conf lnutbld 13h lib mavr gcec create buildtree nutconfigure bnutbld 21b cnut conf ethernut21b conf lnutbld 21b lib mavr gec create buildtree nutconfigure bnutbld 30e cnut conf ethernut30e conf lnutbld 30e lib marm gcec create buildtree nutconfigure bnutbld 50c cnut conf ethernut50c conf lnutbld 50c lib marm gcec create buildtree Note that the trailing backslash line break will only work on Linux and OS X On Windows you need to enter each command in one go and let the command line interpreter do an automatic break at the end of the line e g nutconfigure bnutbld 13h cnut conf ethernut13h conf lnutbld 13h lib mavr gcec crea te buildtree Each command will create a build directory for the related target board To build Nut OS for a specific board change into the related directory and run make clean all install For Ethernut 2 1 we would enter cd nutbld 21b make clean all install cd 26 Using the Command Line Configurator In a similar way we create board specific application directories with the command line Configurator Building the sample application events for Ethernut 2 1 can be done with the following commands nutconfigure anutapp
67. imple read only file system named UROM where files are located in flash memory A special tool crurom create UROM is needed to convert the complete contents of a directory on your PC into a C source file which is then compiled and linked to your target code 41 Nut OS Software Manual Two other low level file systems are available The PNUT file system is a volatile RAM file system where the contents is lost on reboot The lately introduced RAWFS doesn t support directories It assigns a complete storage device to a single file It may be used to access an external Flash memory chip with high level I O functions Both PNUT and RAWEFS support read and write access More advanced application may need to exchange data with other systems using removable media like MultiMedia or SD cards where FAT is the quasi standard file system to which the Nut OS PHAT file system is compatible Applications can use standard C functions for file system access With PHAT and PNUT the following functions are provided to access directory entries DIR opendir CONST char struct dirent readdir DIR int closedir DIR While directories and subdirectories are supported with UROM PNUT and PHAT there is no current working directory Files must be specified with their full path prefixed with the name of the file system driver instance The following code fragment opens a file writes to it and finally closes the file FILE fpo fop n PHA
68. iseconds 60 seconds in this case Instead of a hard coded IP address a NULL pointer may be passed a the second parameter The function will then internally call NutNetLoadConfig to fill the global confnet variable It then decides about further actions An overview about the CONFNET structure elements and their meaning is given by the following table Default Description cd size Byte value 31 Total size of the configuration structure Used to check validity cd name Character array eth0 Name of the network interface Maximum size is 8 characters cdn mac Byte array 0Ox000698000000 6 bytes unique MAC address cdn ip addr LP address 0 0 0 0 Last used IP address cdn ip mask IP address 299a 292I 0 Configured IP mask cdn _ gateway IP address 0 0 0 0 Default gateway IP cdn cip addr IP address 0 0 0 0 Configured IP address The contents is accepted by NutDhcplfConfig if v cd size is valid v cd name matches the name given as the first parameter v cdn mac is a unicast address If the contents is not accepted the function will immediately return 1 to indicate an error If the contents of confnet is accepted and if cdn cip addr is not zero then the network interface will be configured to this local IP address and the function returns Zero If cdn_cip addr is zero then NutDhcplfConfig will start a DHCP client thread to query the network configuration from a DHCP server On success c
69. lable too It allows to call C functions to create dynamic HTML content Here is a simple CGI routine int ShowParms FILE stream REQUEST req NutHttpSendHeaderTop stream reg 200 Ok NutHttpSendHeaderBottom stream req text html 1 fputs lt HTML gt lt BODY gt lt H1 gt Show Parameters lt H1 gt stream if re gt reg query y char name char value int i int count count NutHttpGetParameterCount req for i O0 i lt count i name NutHttpGetParameterName req i value NutHttpGetParameterValue req i Wo fprintf stream s S lt BR gt r n name value fputs lt BODY gt lt HTML gt stream fflush stream return 0 To activate this function for CGI it must be registered NutRegisterCgi showparms cgi ShowParms The function ShowParms will be executed when cgi bin showparms cgi is requested by the webbrowser Furthermore basic support is available for password protection Server Side Includes and Active Server Pages Please refer to the HI TP application sample that is included in the Nut OS distribution ICMP The Internet Control Message Protocol Nut Net automatically responds to an ICMP echo request with an ICMP echo reply which is useful when testing network connections with a Packet InterNet Groper PING program which is available on nearly all TCP IP implementations ARP The Address Resolution Protocol is used by IP over
70. mory in the system The heap is handled as a linked list of unused blocks of memory the so called free list Applications can use standard C calls to allocate and release memory blocks vod mal Loc siza t G1L26 VOLO Ca lLlOC Size GOUND Suse T B120 void free void ptr v id realloc vord pir Size Jt giza char strdup char str A program fragment that allocates a buffer of 1024 bytes in size senselessly filling it with OxFF and releasing the buffer again will look like this char buffer buffer malloc 1024 if buffer memset buffer OxFF 1024 free buffer else puts O t of memory Errori y You should make intensive use of dynamic memory allocation for two reasons First large local variables will occupy stack space As each thread gets its own stack you may waste a lot of memory by reserving large stacks 36 Nut OS second large global variables occupy space during the complete lifetime of the application although they may not be used during that time For some environments the global variable space may be much more limited than heap space The heap manager uses best fit address ordered algorithm to keep the free list as defragmented as possible This strategy is intended to ensure that more useful allocations can be made We end up with relatively few large free blocks rather than lots of small ones To determine the total free space call size t NutHeapAvailable vo
71. n int NutNetSaveConfig void int NutNetLoadConfig CONST char name These functions refer to a global structure variable confnet of the following type struct CONFNET uint t ed size Char cd name 9 Wine t cdn mac s uints2 Cdn Ip addr uinto2 t Cdn lp mask uint C cdn Gateway uint C Cdn Gip addr CONFNET 48 Nut Net Using this capability we can rewrite the hard coded version as NutNetLoadConfig DEV ETHER NAME NutNetlftConfig DEV ETHER NAME Cconfinet cdn mac contnet cdn ip addr CONENeL Cdn 1p Mask 7 if confnet cdn gateway NutIpRouteAdd 0 0 confnet cdn gateway amp DEV_ETHER Setting up a virgin system highly depends on the application You may provide some kind of user input to set the confnet variable and then call NutSaveConfig to store the settings in non volatile memory For AVR targets the Basemon program may be used to configure your board Today DHCP is available in most networks and it is supported by Nut Net as well However at least the MAC address must be available before DHCP can be used either hard coded or read from non volatile memory The hard coded version is uinte macle 0x00 0x06 0298 0x00 0x00 Ox00 NutDhcpIfConfig DEV ETHER NAME mac 60000 DHCP may take time to finish or the DHCP server may not be reachable at all In order not to block the system forever and let the application act on failure a third parameter is used to specify a time out in mill
72. nf 12 30 39 OK ia a 23 Nut OS Software Manual A second message box pops up after the build directory has been created or updated ot _ __ Nut OS Components 4 Property 2 Na 0s e e nos a E E Architecture J RTOS Kernel x7 Source directory nut mm 3 Dewes Diver Build directory nutbld E vas Target platform arm gcc a C runtime tool Install directory nutbld lib r C runtime targi H Gop Code sni Do you like to build the Nut OS libraries H Network gene i Abbrechen 12 30 39 OK 12 47 58 Creating Mak 12 47 58 Creating header files in nutbld 12 47 58 OK i a After confirming the second message box the Fie Edt View Buld Help Bee Configurator will remove any previously built binaries make clean create new libraries make all and move them to the installation directory make install Nut OS Components H Nut OS 4 8 3 0 Please wait running make all E amp Gorp Code snipped library H Network general i 12 49 19 Located C ethernut 4 8 3 nutitools win32 make exe 12 49 21 make clean terminated successfully Running make all 12 49 21 Located C ethernut 4 8 3 nut tools win32 make exe When done the Configurator will have created the following libraries libnutarch a Architecture dependent library a libnutc a Tool specific C runtime library a libnutcontrib a Contribution libr
73. ollowing dialog you can deselect various EE Choose which features of Win4VR 20090313 you want to install D options Although marked Recommended you may prefer not to have WinAVR directories added fitik emette halatan a c the components yai doritwantto to your PATH environment Nut OS allows to add them to the settings later This provides more control especially when switching platforms Click on nstall to start the installation Select components to install Install Files MBE Add Directories to PATH Recommended Install Programmers Notepad Space required 122 6MB cms a E Win YR 20090313 Setup eX The status of the installation progress is Instaling displayed When completed click on the Next Please wait while WinAVR 20090313 is being installed button eae Clicking the Finish button in the final dialog will start your default web browser to display a short manual Completing the WinAVR 20090313 Setup Wizard WinAVR 20090313 has been installed on your computer Click Finish to close this wizard Installing a Cross Toolchain Installing ImageCraft AVR ImageCraft Inc offers an ANSI C cross compiler IDE with strong commercial support They sell three different product editions standard advanced and professional All three editions will work for Nut OS A free demo is available too which is mainly limited in code size and may not work with all Nut OS application
74. omatically Otherwise it must be configured so Nut OS can calculate the right hardware timer setting for system ticks of one millisecond Amongst others the following timer related API functions may be useful vinto NUCCLOCKGCE ime idx returns the specified clock frequency in Hertz Accepted values are at least NUT HWCLK CPU to query the CPU clock and NUT HWCLK PERIPHERAL to query the clock that drives on chip peripherals Other values may be additionally available for your target uintos t NuUtCGStMLILIS void returns the current value of the system s uptime in millisecond and uints2 N utGertseconds void returns the system s uptime in seconds Given a system tick of 1ms both counters will overflow after about 7 years UInES2 E NUTCGECTIOCkCOUnE vond returns the current value of the system s tick counter and WInESZ t NuUCGeECLILCkOLOCk VOrd returns the number of system ticks per second Setting I O time outs is device dependent Devices that are used for standard I O often provide specific ioctl commands For UART devices we can use UART SETREADTIMEOUT UART SETWRITETIMEOUT The following code fragment opens device uartO for binary reading and writing and sets the read timeout to 1000 milliseconds int Com unsigned long tmo 1000 com open uart0O 0 RDWR O BINARY 7 _ioctl com UART SETREADTIMEOUT amp tmo Internally the related drivers use the Nut OS event management to handle time outs
75. onfigurator is to create an associated application tree Although possible we will not use the application samples in the source directory Instead we use the Configurator to create a copy of the sample directory for us Select Create Sample Directory in the Build menu A message box is displayed to confirm the settings When clicking OK the samples include in the Nut OS distribution are copied to this application directory They may also serve as a template for your own applications Nut OS Configurator eir10c Iof Xx File Edit View Build Help nF Build Nuv OS Comp Create Sample Directory Property S Value cae Enabled No Architecture RTOS Kernel Device Drivers C runtime tool specific C runtime target specific Gorp Code snipped library gt Network general i he 02 39 make all terminated successfully 13 02 39 Running make install 13 02 39 Located C ethernut 4 8 3 nut tools win32 make exe make install terminated successfully e Edit View Build Help MPE xn Nut OS Components Nut OS 4 pages Architecte gt gt H RTOS Ke s Source directory nut app Device Di Target directory nutapp F C runtime Programmer arm samba amp C runtime Do you like to create or update the sample directory E Gorp
76. ormal C programs and preserves portability Most Nut OS applications will need more than the 4 kBytes of RAM provided internally by the ATmega CPU Thus the compiler is intentionally set to External 32k SRAM We ignore the last page for Salvo settings Salvo is another RTOS similar to Nut OS Press OK to close the Compiler Option Window 31 Nut OS Software Manual Specially for our HTTP Server project another entry in the Tools menu will be helpful Select Configure Tool from the main menu and add the following entries in the Edit Tool Menu Dialog Menu Name Create urom c Program c ethernut 4 8 3 nut tools win32 crurom exe Add Parameters r ourom c sample Bhange Initial Directory c ethernut 4 8 3 nutapp httpd Activate Capture Output Click Add and OK This should have created a new entry in the Tools menu Select this entry now to run the crurom utility which converts all files in a specified directory sample in our case to a C source file This is used to include HTML files images Java Applets or other stuff into the Webserver s simple file system This C source will be compiled and linked to the Nut OS code When selecting Make Project from the project menu ICCAVR will compile and link the webserver code Check that no errors occurred during this process Refer to the ICCAVR manual for further details As a result of this step ICCAVR created several files in the project directo
77. piler Collection GCC and the commercial ImageCraft for AVR ICC AVR are officially supported The following table provides an overview about which toolchain can be used on a specific host operating system for a specific target platform Windows AWA SEV in AVR GCC ImageCraft AVR PUEY AGARTO GCC ARM ELF GCC YAGARTO GCC AVR GCC AVR GCC AVR32 GCC AVR32 GCC Not available Installing WinAVR WinAVR pronounced whenever is a suite of executable open source software development tools for the AVR hosted on the Windows platform They are mainly based on the GCC for AVR toolchain and are quite similar to the Linux tools Get the latest WinAVR installer executable from the Ethernut development DVD or download it from http winavr sourceforge net Installer Language x After starting the installer you will be guided through the Please select a language installation steps First select the language of the installer amp English i H Cancel WinA R 20090313 Setup Mle x The next dialog displays some general information f Welcome to the WinAYR 20090313 Click Next to continue Setup Wizard This wizard will guide you through the installation of WinAVR 20090313 It is recommended that you close all other applications p before starting Setup This will make it possible to update relevant system files without having to reboot your omputer Click Next to continue
78. re defined to NutAppMain Other compilers won t be hurt Almost all Nut OS header files do include compiler h Thus it is required only when no other header files are used in the application code Thread Management Typically Nut OS is most useful when there are several concurrent tasks that need to be undertaken at the same time To support this requirement Nut OS offers some kind of light processes called threads In this context a thread is a sequence of executing software that can be considered to be logically independent from other software that is running on the same CPU All threads are executing in the same address space using the same hardware resources which significantly reduces task switching overhead Therefore it is important to stop them from causing each other problems This is particularly an issue where two or more threads need to share a resources like memory locations or peripheral devices Nut OS implements cooperative multithreading That means that threads are not bound to a fixed time slice Unless they are waiting for specific event or explicitly yielding the CPU they can rely on not being stopped unexpectedly As opposed to pre emptive multithreading cooperative multithreading simplifies resource sharing and usually results in faster and smaller code Each thread has a priority which is used to determine how urgent it is This priority ranges from O to 254 with the lowest value indicating the most urgent 35
79. ry One is named httpserv hex and contains the binary code in Intel Hex Format The second file httpserv cof can be loaded into the AVR Studio Debugger and contains the binary code plus additional debugging information 32 Ba imageCraft IDE for ICCAYR Advanced File Edit Search View Project Tools Terminal Help Rel gis B Mail Setup Environment Options Editor and Print Options Program Options Menu Name Create urom c Clear Fields Program Jols win32 crurom exe Browse ourom c sample Initial Directory Jut 4 8 3 nutapp httpd Parameters Pile Es tongi Project Browser In System Programmer AVA Calc Application Builder I amp HTTPD S Files uromc hitpserv c Configure Tool Run Headers Documents index html Create urom c for html No Open File Ba ImageCraft IDE for ICCAYR Advanced File Edit Search View Project Tools Terminal Help ToS wg i Open Open All Files Close All Files C ethernut 4 8 3 OL x Ctrl F11 Reopen Make Project Rebuild All Fg Shift F9 Headers Add File s Add liopmost Wpened File Remove Selected HEIS a Documents index html form html Shift F11 c ethernut Done Mon J Ubtions
80. s This guide refers to ICCAVR version 7 Version 6 may still work with Nut OS but its support will likely be abandoned in the near future Welcome A Welcome to the ICCV for AVR Setup program The first dialog presents you with some general information Click Next to continue Setup will install the software on your computer WARNING This program is protected by copyright law and international treaties Unauthorized reproduction or distribution of this program may result in severe civil and criminal penalties and will be prosecuted to the maximum extent possible under law Click Next to continue with the Setup Cancel Important Information an unlock code If you are installing a demo version carefully read n 293 i far Afterward tl bacanna Code aed imted ot the text in this dialog Click Next to continue ee seein The primary reason we copy protected the software in this fashion is so that you can download the latest version of our software at anytime from our website to update your software Once you register the updates do not needed to be registered again providing you install the update over the existing version We feel that the ability to obtain easy upgdate from our website outweighs the minor annoyances that the registration process causes The following window displays the license Click W Syme ee This is a legal agreement between you the end user ft S and ImageCraft I
81. s packed into a source code package named ethernut X Y Z tar bz2 where X Y Z symbolizes the version number The file contains the complete code some Nut OS tools and the API reference Building the full package requires a number of additional tools and libraries It may fail at various stages and isn t trivial However several parts are optional and you should be able to create Nut OS applications with a subset The following table lists the main dependencies Module Provisions Special Requirements v Target selection via shell v None script Nut OS Sources v Configurable by editing C header files mandatory l v Tool for creating simple file system images v Multiple build and application v Lua 5 0 libraries trees v Automated script based target configuration Vv Batch build CLI Configurator optional GUI Configurator optional GUI Discoverer optional API Reference optional Easy to use configuration interface Multiple build and application trees Automated script based target configuration Lua 5 0 libraries wxWidgets 2 8 libraries GNU C compiler Scans local networks for Nut OS nodes Remote configuration of Nut OS nodes WxWidgets 2 8 build from source wxPropertyGrid extension GNU C compiler HTML documents created from source code Doxygen 1 4 or later GraphViz 2 2 or later We will present the full build here If something goes wrong then simply skip
82. se ad There are other devices for which the NUTDEVICE structure will not make sense at all like a watchdog device or in general timers and counters In order to hide hardware details from the application several device helper functions are included Although part of the nutdev library these are not device drivers in strict interpretation simply because they do not provide a global NUTDEVICE structure variable 45 Nut OS Software Manual Another kind of helper routines are so called driver frameworks A typical one is used by the UART driver The hardware specific part itself provides the NUTDEVICE structure but the device function pointers are implemented by the framework The driver itself is reduced to a few hardware specific routines which are called by the framework A similar method is used by the terminal driver framework which interprets VI52 control sequences and calls specific hardware function of the display driver This way a framework avoids duplicate code which otherwise would have been included in each device driver over and over again Error Handling While many operating systems extensively check parameters passed from applications to the system API Nut OS intentionally relies on good application code for good reasons v Due to the lack of memory protection tiny embedded systems are quite defenseless and have to rely on responsible application code anyway v Parameter checking in API functions is often redundant
83. the Device uar Ini nn Configuration for ATmega103 ATmega1 28 or renani S ATmega2561 Ce a inutpro nuts nutne Advanced Return Stack Size 32 Non default Startup ertnutram o Text Address WORD 046 T Strings in FLASH only Instruction Set JENhance Unused ROM Fill Bytes Program Type Application Boot Size I DoNOT use R20 R23 None i Extemal 32K SRAM 7 Notes CLICK HERE Boot Loader Options other Options cc lb nutinit o C Boot Loader OK T Set As Default Load Defaut Hel ance et 4s Vetaul oa efaul Help The following Additional Libs are required for our webserver project nutpro nutgorp nutfs nutnet nutos nutdev nutcrt nutarch Other Options should contain ucrtnutram o c ethernut 4 8 3 nutbld lib nutinit o except for Ethernut 1 3 where Rev G and any later revision it must contain ucrtenutram o c ethernut 4 8 3 nutbld lib nutinit o Note the additional letter e after ucrt This entry will instruct the compiler to use a Nut OS specific runtime initialization routine The main difference to the standard routine is that NutInit is called before main so any RIOS specific initialization is hidden from your application code You can simply start coding main while the idle thread and the Nut OS timer are already running in the background In fact main is started as a Nut OS thread This feature makes Nut OS applications look like n
84. timers are available for the application You can use them in cases where the system timer resolution typically 1ms is insufficient Nut OS provides time related services allowing application to delay itself for a given number of milliseconds by calling NutSleep Furthermore a time out value can be defined for most blocking operations like input output functions Again time out values are given in milliseconds The following minimal application will run in an endless loop but spend most of the time sleeping for 125 milliseconds During sleep time any other thread may take over If no other thread is ready to run CPU control is passed to the Nut OS idle thread 37 Nut OS Software Manual include lt sys timer h gt int main void LOC S 4 NutSleep 125 NutSleep guarantees a minimum sleep time but it may take more time to return to the caller Often short reproducible delays with higher resolutions are required in which case void NutMicroDelay uint32 t us should be used The delay time is specified in microseconds However this function will not release the CPU and unless the value of NUT DELAYLOOPS hadn t been exactly configured for your specific hardware it is based on a rough estimation Also note that a fast CPU is required to provide low resolutions of a few microseconds Hardware timers are based on hardware clocks e g crystal oscillators If possible Nut OS tries to determine clock frequencies aut
85. ut 4 8 3 nut tools win32 C WinAVR bin C WinAVR utils bin Here s a sample entry for the ImageCraft compiler C ethernut 4 8 23 nut tools win32 C i1cecv avr bin The items on the last page are used to create an Seay E aI wizard will become available in the future Since then the ia Configurator provides the basic functions Note that the ee application directory is tightly linked to the build directory Thus if you changed the name of your build directory to nutbld eir7Oc for example then you should give the application directory a similar name like nutapp eir70Oc The selection of a Programmer is optional see table below Finally click OK to store the settings arm samba application sample directory A more advanced application aes When the correct Programmer is selected from the drop down list applications may later be built and uploaded to the target board in a single step by entering make clean all burn on the command line The selection mainly depends on the programming software tool and the following options are available Programmer Use with arm jom JTAG O MAT for ARM targets arm samba Atmel s SAM BA utility recommended for ARM targets with SAM BA boot ROM avr dude AVRDUDE utility recommended for AVR targets supports many adapters avr jtagice Atmel s original AVR JTAGICE RS232 only and AVR targets avr jtagicemkii Atmel s AVR JTAGICE MKII and AVR targets avr uisp stk500 UI
86. w basic samples and have a Password user look at the list of links at the end of this ei manual Form demo Login for all other CGIs Login root Password root Thread list Timer list Socket list 34 Nut OS Nut OS This chapter will provide a short overview Check the Nut OS API Application Programming Interface Reference for a detailed description Be aware that this chapter makes no attempts to explain details of the C language It is assumed that you have a basic knowledge of C programming System Initialization By default C programs are started with a routine called main This isn t much different in Nut OS however the operating system requires certain initialization before the application is started This initialization is included in a module named nutinit It will initialize memory management and the thread system and start an idle thread which in turn initializes the timer functions Finally the application s main routine is called Because there s nothing to return to this routine should never do so A sample application named simple demonstrates the most simple application that can be built with Nut OS It does nothing else than running in an endless loop consuming CPU time include lt compiler h gt int Main void for 77 The file compiler h is included to fix a problem with AVR GCC which insists on setting the stack pointer again on entry to main When using this compiler main is
87. will build the toolchain and change to this directory mkdir toolchain avr cd toolchain avr Get the source packages _ wget ftp gcc gnu org pub binutils releases binutils 2 19 1 tar bz2 wget ftp gcc gnu org pub gccec releases gcc 4 3 3 gcc core 4 3 3 tar bz2 wget ftp gcc gnu org pub gcc releases gcc 4 3 3 gcc g 4 3 3 tar bz2 q4 wget http download savannah gnu org releases noredirect avr libc avr libc 1 6 7 tar bz2 q4 wget http download savannah gnu org releases noredirect avrdude avrdude 5 7 tar gz Unpack the packages tar xt DIDUCILS s LI rlata DZ tar k tf sgce core 4 3 3 e tar vozZ tar See gC Gre da 34 8 tak 022 tar xgr Avr LIpe Ii Gel kar One t r xzf avrdude 5 7e targ Now we set two useful environment variables and create a bin folder in advance which we add to the PATH variable TARGET avr export TARGET PREFIX usr local STARGET export PREFIX sudo mkdir p SPREFIX bin PATH SPATH SPREFIX bin export PATH Start with building and installing the binutils ed Dinu taels 2 oO mkdir build STARGET cd build STARGET configure target STARGET prefix SPREFIX enable languages c c disable nis disable lLibssp with dwarf2 make sudo make install COE 2 wil Sa Nut OS Software Manual Next build and install the compiler ed gGeo 4 5 3 mkdir build STARGET cd build STARGET configure target STARGET prefix SPREFIX enable languages c c
88. without too much effort Nevertheless there is an important difference to standard C applications written for the PC Typical embedded systems do not pre define devices for stdin stdout and stderr Thus the well known standard C sample Hello world include lt stdio h gt int main void printf Helio world n requires a few additional lines of code on Nut OS include lt stdio h gt include lt dev usartavr h gt int main void unsigned long baud 115200 Register the device we want to use NutRegisterDevice amp devUsartAvrO 0 0 Assign the device to stdout freopen uartO w stdout Optionally set the baudrate of the serial port foctl filenol stdout UART SETISPEED 4ba d Prints Hello world in Btw a typical pitfall is to mix Nut OS and compiler libraries for standard C functions If the linker reports duplicates or undefined syscalls or if your application hangs in stdio functions or crashes when calling them then check your linker map file to make sure that these functions are loaded from Nut OS libraries If not you may have forgotten to add nutcrt to the list of libraries or your application may reference a function that is not available in Nut OS File Systems Neither Nut OS nor Nut Net require a file system but for example Webservers are designed with a file system in mind To make things easier for the programmer Nut OS provides a very s
89. y Nut OS adds support based on hardware exception for ARM CPUs only When adding S LIBDIR arm da o in front of the L BS entry in your Makefile e g LIBS S LIBDIR arm da o S LIBDIR nutinit o lnutos lnutdev lnutarch lnutcrt then a data abort will print out a back trace on stdout There is also v arm pfa o for prefetch abort v arm swi o for software interrupt v arm udf o for undefined instructions Note that back trace requires to select arm gccdbg as the platform in the Configurator settings You may enhance various checks with the back trace by adding the following NUTPANIC function to your application vold NUTEPAN IC CONS char imt 435 va List ap NutEnterCritical Va Starti ap ime VEPrintt Stdeuty fmt ap NutHeapDump stdout ListStacks LOL SF 7 This will replace the default handling and provide a detailed analysis of the system status 47 Nut OS Software Manual Nut Net The code and buffer sizes required by traditional TCP IP implementations make them less suitable for tiny microcontrollers Nut Net has been specifically designed for small systems Although this chapter tries to explain some basics it makes no attempt to describe all aspects of TCP IP in full detail It is assumed that you have a working knowledge of the protocol Network Configuration Before using any Nut Net function the application must register the network device driver by calling Nut

Download Pdf Manuals

image

Related Search

Related Contents

2ハンドルバス水栓    SmartBoom® PRO  Samsung CLX-6200FX Manual de Usuario  Télécharger le manuel  Bosch WAA 16161 Manual User Guide Pdf  Samsung SF-330 User Manual  American Standard Hot Tub Whirlpool/Bathing Pool User's Manual  Tecumseh AEA4430AXAXC Performance Data Sheet  Installation Instructions  

Copyright © All rights reserved.
Failed to retrieve file