Documente Academic
Documente Profesional
Documente Cultură
www.phytec.in
In this manual copyrighted products are not explicitly indicated. The absence of the trademark () and copyright ( ) symbols does not imply that a product is not protected. !dditionally" registered patents and trademarks are similarly not expressly indicated in this manual. The information in this document has been carefully checked and is belie#ed to be entirely reliable. $o%e#er" &$'T() (mbedded &#t. *td. assumes no responsibility for any inaccuracies. &$'T() (mbedded &#t. *td neither gi#es any guarantee nor accepts any liability %hatsoe#er for conse+uential damages resulting from the use of this manual or its associated product. &$'T() (mbedded &#t. *td reser#es the right to alter the information contained herein %ithout prior notification and accepts no responsibility for any damages that might result. !dditionally" &$'T() (mbedded &#t. *td offers no guarantee nor accepts any liability for damages arising from the improper usage or improper installation of the hard%are or soft%are. &$'T() (mbedded &#t. *td further reser#es the right to alter the layout and,or design of the hard%are %ithout prior notification and accepts no liability for doing so. )opyright -01. &$'T() (mbedded &#t. *td" /oramangala 0angalore. Rights - including those of translation, reprint, broadcast, photomechanical or similar reproduction and storage or processing in computer systems, in whole or in part - are reserved. No reproduction may be made without the explicit written consent from P !"#$ #mbedded Pvt. %td.
'ddress(
&ndia #urope North 'merica P !"#$ #mbedded Pvt. &$'T() Technologie &$'T() !merica **) %td. $olding !1 -0. &arfitt 9ay 39" th )oramangala * bloc+, Robert2/och23tr. .4 3uite 1100 0ainbridge ,angalore --. 551-4 6ain7 Island" 9! 4:110 ;3! &ndia 1(R6!8' /-1-*0-01102.*3ales4phytec.in http(55www.phytec.in >?4 (:00) 0@?4:.order4phytec.de http(55www.phytec.de 1 (:00) -@:2441. sales4phytec.com http(55www.phytec.com
www.phytec.in
(a)le o* Content+
#mbedded %inux 'ppliation 7evelopment for 8pen,oard-'911.x.................................................. 1. 'pplication development using #clipse &7#................................................................................ 1.1. #clipse &7# &nstallaion......................................................................................................... 1.6. #clipse &7# $onfiguration for 8pen,oard-'911.x..........................................................: 1.6.1. ost 3etup....................................................................................................................: 1.6.6. "arget 3etup..................................................................................................................: 1.6.1.1. 3et the ip for the open board.................................................................................: 1.1. $reating a New Pro;ect........................................................................................................2 1.1.1. ow to open eclipse.....................................................................................................2 1.1.6. <elcome to #clipse......................................................................................................* 1.1.1. 8pen a new pro;ect.......................................................................................................* 1.1.0. 3elect $ Pro;ect............................................................................................................1.1... 3elect the $ross =$$...................................................................................................1.1.:. 3elect 7ebug >acilities...............................................................................................10 1.1.2 "oolchain Prefix ? Path..............................................................................................10 1.1.*. 8pen new $ source file..............................................................................................11 1.1.-. <rite simple ello 'pplication..................................................................................16 1.1.10. 9odify Post build steps............................................................................................16 1.1.11. >inally ,uild the pro;ect...........................................................................................10 1.0. $hanging the 7emo 'pplication........................................................................................10 1.0.1. 8pen "arget ,oard using 9inicom............................................................................1: 1... %ed ,lin+ing 'pplication...................................................................................................12 1...1. 3elect the $ross =$$.................................................................................................12 1...6. 3elect 7ebug >acilities...............................................................................................1* 1...1. "oolchain Prefix ? Path.............................................................................................1* 1...0. 8pen new $ source file..............................................................................................11..... <rite %ed 'pplication................................................................................................60 1...:. <rite 8pen ,oard eader..........................................................................................61 1...2. 9odify the %ibrary Path.............................................................................................61 1...*. 9odify Post build steps..............................................................................................60 1...-. Remote 3ystem 'ccess using #clipse........................................................................6. 1...10. $reate New $onnection for Remote 3ystem login..................................................62 1...11. 3et the ost Name and &P.........................................................................................6* 1...16. %aunch the Remote "erminal...................................................................................11 1...11. &nsert the driver using the Remote "erminal............................................................16 1...11. >inally ,uild the pro;ect...........................................................................................11 1.:. 7ebugging an example pro;ect...........................................................................................10 1.:.1. 3tarting the =7, server on the target........................................................................10 1.:.6. $onfiguring and starting the debugger in #clipse......................................................1. 1.:.1. 3etting a ,rea+point...................................................................................................00 1.:.0. 3tepping and <atching @ariable $ontents.................................................................01 1.:... 3tepping and <atching @ariable $ontents.................................................................01 1.:.:. Asing the 9emory 9onitor........................................................................................00 6. 'pplication development using $onsole "erminal....................................................................02 6.1. Aser %#7B3........................................................................................................................0* 6.1.1. Pre-ReCuists................................................................................................................0* 6.1.6.$ompiling Aser %ed 'pplication................................................................................0* 6.1.6.1. ost 3ide.............................................................................................................0* 6.1.6.6. "arget 3ide..........................................................................................................0* 6.6. Aser ,A""8NB3................................................................................................................0-
www.phytec.in
6.6.1. Pre-ReCuists................................................................................................................06.6.6. $ompiling Aser 3witch 'pplication...........................................................................06.6.6.1. ost 3ide.................................................................................................................06.6.6.6. "arget 3ide..........................................................................................................06.1. '7$....................................................................................................................................0 6.1.1. Pre-ReCuists.................................................................................................................0 6.1.6. $ompiling Aser '7$ 'pplication..............................................................................0 6.1.6.1. ost 3ide..............................................................................................................0 6.1.6.6. "arget 3ide...........................................................................................................1
www.phytec.in
www.phytec.in
Eclipse IDE for C/C++ Developers for ) c *+ ,-Coco #$. http(55www.eclipse.org5downloads5download.phpD fileE5technology5epp5downloads5release5;uno53R15eclipse-cpp-;uno-3R1-macosx-cocoax*:G:0.tar.gF
www.phytec.in
" route add default gw &'(.&)*.&.& !o see the change in the gateway. " route
In this section you will learn how to create a new project with +clipse and how to configure the project for use with the ,-. C/C00 cross de$elopment toolchain. Click the +clipse icon to start the application. 1ou can find this icon where you ha$e extracted the +clipse I2+ for C/C00 2e$elopers . 1...1. Ho/ to open eclipse
www.phytec.in
Close the 3Welcome to +clipse3 screen by clicking on the 3,o to the workbench3 button
www.phytec.in
4 5elect File 6 -ew 6 7roject from the menu bar A new dialog opens. 1...3. Select C Pro2ect
5elect C 7roject and click -ext 1...4. Select t#e Cross (CC
www.phytec.in
+nter the project name my8elloWorld and !oolchain as Cross ,CC then click -ext 1...5. Select De,ug Facilities
www.phytec.in
10
5elect the Cross Compiler 7refix as arm-cortexa3-lin"x-0n"ea)iand Cross Compiler 7ath as 9path of toolchain bin: #ote; for window you ha$e to select the arm-none-lin"x-0n"ea)i- and the appropriate path of the toolchain. 1...8. 1pen ne/ C source %ile
1ou will see the C/C00 I2+ with the my8elloWorld project. <ight#click on 8elloWorld project 5elect File 6 -ew 6 5ource file from the menu bar In 5ource file write my8elloWorld.c and click on finish
www.phytec.in
11
Write a simple 8ello Application in C. !o compile your project for the =pen ,-. C/C00 cross compiler. 1...1:. 'odi% Post ,uild steps oard#A>??@A instead, you will ha$e to use the
www.phytec.in
16
<ight#click the my8elloWorld project and chose 7roperties !he 7roperties dialog appears. 5elect C/C00 uild ####: 5etting #######:5elect the uild 5teps tab +nter the following command in the 7ost#build steps Command input field; +cp -4my5ello6orld root7&'/-&83-&-&&$4home4- 9++h root7&'/-&83-&-&& -4my5ello6orld #ote$ .* yo" are "+in0 6indo1 machine then there i+ no "+e o* 1ritin0 the a)ove line it 1ill thro"0h error +o yo" have to "+e 6in+cp or directly copy the )inary into tar0et )oard "+in0 pen drive or +d card1ou can download the winscp from the below link; http;//download.winscp.net/download/files/(%&?%((B&&@'a@e%d'e&'??B?cacc'''*a(df(* ?e&'a/winscp@&Csetup.exe Click Apply Click =D 5elect 7roject 6 uild project from the menu bar !he project will be built. 5elect the Console tab. if no errors occur while building the project, you will see the following output; #ote$ .* yo" are "+in0 6indo1 machine then yo" need the ma:e "til+ "+in0 te )elo1 lin: yo" can do1nload it. ftp;//ftp.eEuation.com/make/?(/make.exe
www.phytec.in
11
"hen add the function writeGttyHI, which writes n bytes to the first serial interface Hwhich, on the 8pen-,oard-'911.x, is connected to the system console 5dev5consoleI(
void write_tty (char *buffer, int count) { int out; out = o en (!"dev"console!, ###); write(out, buffer, count); close(out); $
www.phytec.in
10
#nter the following two lines in the mainHI function to declare the buffer and call the writeGttyHI function.
char buf %& = { !'elco(e to the 'orld of the ) en*+oard*,-../01 (serial)2n! $; write_tty(buf, si3eof (buf) * 4);
&n the next screenshot you can see the complete program.
3ave your program after changing the code. "he application will be compiled, built, copied to the target and executed.
www.phytec.in
1.
1.3.1. 1pen -arget "oard using 'inicom 8pen the terminal using minicom J minicom -7 5dev5ttyKK &f you are not logged in, enter root and press #nter then type ls to see all the file. J ls "ype .5my ello<orld to start the application .5my ello<orld ello <orld <elcome to the <orld of the 8pen-,oard-'911.xL HserialI close minicom. &n this section you have changed an existing application. !ou also learned how to access the serial interface. >irst you called the function openHI on the device 5dev5console. "he return value of this function was a file descriptor. <ith the file descriptor you called the function writeHI to send n bytes to the device 5dev5console. 'fter that, the file descriptor was closed with the function closeHI.
www.phytec.in
1:
+nter the project name myled and !oolchain as Cross ,CC then click -ext
www.phytec.in
12
5elect the Cross Compiler 7refix as arm-cortexa3-lin"x-0n"ea)iand Cross Compiler 7ath as 9path of toolchain bin:
www.phytec.in
1*
1ou will see the C/C00 I2+ with the led project. <ight#click on led project 5elect File 6 -ew 6 5ource file from the menu bar In 5ource file write myled.c and click on finish
www.phytec.in
1-
1.4.4. 0rite $ed Application !hen write a led application as; /F F myled.c F F Created on; ()#Feb#(%&? F Author; Ashutosh F/ "include 9stdio.h: "include 9stdlib.h: "include 9unistd.h: "include 9sys/ioctl.h: "include 3openGboard.h3 int mainHI J int fdK fdLopenGgpioH3/de$/openGboardGgpio3, )))IK /F....... !his function will configure the user led as output.......F/ gpioGconfHfd, gpioGconfHfd, gpioGconfHfd, gpioGconfHfd, A-D&,7I-?%,=.!IK A-D&,7I-?&,=.!IK A-D&,7I-*,=.!IK A-D&,7I-',=.!IK
/F....... !here we will toggled the user led .......F/ whileH&I J setGgpioHfd, A-D&,7I-',5+!IK setGgpioHfd, A-D&,7I-*,5+!IK setGgpioHfd, A-D&,7I-?%,5+!IK setGgpioHfd, A-D&,7I-?&,5+!IK sleepH&IK setGgpioHfd, A-D&,7I-',CM+A<IK setGgpioHfd, A-D&,7I-*,CM+A<IK setGgpioHfd, A-D&,7I-?%,CM+A<IK setGgpioHfd, A-D&,7I-?&,CM+A<IK sleepH&IK N /F....... !his function will free the user led.......F/ gpioGfreeHfd, gpioGfreeHfd, gpioGfreeHfd, gpioGfreeHfd, A-D&,7I-?%IK A-D&,7I-?&IK A-D&,7I-*IK A-D&,7I-'IK
www.phytec.in
60
return %K N
1.4.5. 0rite 1pen "oard Header 5elect File 6 -ew 6 8eader file from the menu bar In 8eader file write openGboard.h and click on finish !hen write the 8eader file as. /F F openGboard.h F F Created on; ()#Feb#(%&? F Author; Ashutosh F/ "ifndef =7+-G =A<2G8G "define =7+-G =A<2G8G "define =.! % "define I- & "define 5+! & "define CM+A< % "define A-D% % "define A-D& & "define A-D( (
www.phytec.in
61
"define A-D? ? "define 7I-% % "define 7I-& & "define 7I-( ( "define 7I-? ? "define 7I-C C "define 7I-@ @ "define 7I-) ) "define 7I-B B "define 7I-* * "define 7I-' ' "define 7I-&% &% "define 7I-&& && "define 7I-&( &( "define 7I-&? &? "define 7I-&C &C "define 7I-&@ &@ "define 7I-&) &) "define 7I-&B &B "define 7I-&* &* "define 7I-&' &' "define 7I-(% (% "define 7I-(& (& "define 7I-(( (( "define 7I-(? (? "define 7I-(C (C "define 7I-(@ (@ "define 7I-() () "define 7I-(B (B "define 7I-(* (* "define 7I-(' (' "define 7I-?% ?% "define 7I-?& ?& int openGgpioHchar Fnode, int perIK int gpioGconfHint fd, int bank, int pin, int dirIK int gpioGintrGconfHint fd, int bank, int pin, int dirIK int gpioGfreeHint fd, int bank, int pinIK int gpioGintrGfreeHint fd, int bank, int pinIK int setGgpioHint fd, int bank, int pin, int $alueIK int closeGgpioHint fdIK unsigned int readGinteruptHint fd, int bank, int pinIK "endif /F =7+-G =A<2G8G F/
www.phytec.in
66
1.4.6. 'odi% t#e $i,rar Pat# !hese abo$e functions are in the shared library so we are going to add our shared library to this project. you can download led and user button library from 7hytec F!7 using this link ftp;//ftp.phytec.de/pub/7roducts/India/=pen oard# A>??@x/Minux/latest/src/apps/apps.tar.gO untar it and go to the led app directory where you find the library file, this is your library path. <ight#click the led project and chose 7roperties !he 7roperties dialog appears. 5elect C/C00 uild ####: 5etting #######: tools setting ###########: Cross ,CC Minker ###############: Mibraries !here add new Mibraries H#lI as openGboard and Mibrary search path H#MI as 9location of your library :
www.phytec.in
61
+nter the following command in the 7ost#build steps Command input field;
www.phytec.in
60
+cp -4myled root7&'/-&83-&-&&$4home4- 9++h root7&'/-&83-&-&& -4myled Click Apply and then Click =D efore building your application we need the dri$ers for led which is already in the =pen oard root file in home directory; 4home4led4driver-:o we ha$e to insert this dri$er before using the application so for this you ha$e a remote access of the open board. 1.4.9. &emote S stem Access using Eclipse For Windows : You have to set the address manually connect ethernet cable goto network connections right click on "Local area connection" -->properties -->under general tab double click on "Internet Protocol(T P!IP"" change the parameters For Linux : You have to set the address manually connect ethernet cable !o see all the interfaces present on the open board " ifconfig #a After this we got the particular interface then we ha$e to configure it. " ifconfig eth% &'(.&)*.&.&( up where eth% is the interface name. Again check whether it is configured or not " ifconfig #a !hen we ha$e to set the gateway " route add default gw &'(.&)*.&.&
www.phytec.in
6.
!o see the change in the gateway. " route Meft#click the Window tab. 5how $iew ####: others.. #######: <emote 5ystems and ok
www.phytec.in
6:
1.4.1:. Create )e/ Connection %or &emote S stem login <ight Click on Mocal select new connection select linux
www.phytec.in
62
1.4.11. Set t#e Host )ame and IP !hen write 8ost name as &'(.&)*.&.&& and connection name as =pen oard.
5elect ssh.files
www.phytec.in
6*
www.phytec.in
6-
select ssh.terminals and finish -ow we successfully create the connection. Click on the open board >y 8ome
www.phytec.in
10
!ype .ser I2 as root lea$e password as blank. !hen press =D. 1.4.12. $aunc# t#e &emote -erminal
-ow we can see all the contents of open board. If you want to open the =pen oard terminal just <ight click on 5sh !erminal and click on the Maunch !erminal.
www.phytec.in
11
1.4.1.. Insert t#e driver using t#e &emote -erminal ,o to the led directory and insert the dri$er into the kernel space. " cd led " ls " insmod dri$er.ko
www.phytec.in
16
5ince the dri$er is inserted in the kernel space now we can run our application 1.4.1.. Finall "uild t#e pro2ect
5elect 7roject 6 uild project from the menu bar !he project will be built. 5elect the Console tab. if no errors occur while building the project, you will see the following output; It will ask for a confirmation the type ye+ to allow.
www.phytec.in
11
1.5.1. Starting t#e (D" server on t#e target &n this passage you will learn how to start the =7, server on the target. "he =7, server will be used to start and control the my ello<orld program. "o debug a program with =7,, the program needs extended debugging symbols. "his has already been added while building the program. 8pen 9inicom J minicom -7 5dev5ttyKK "ype root and press #nter
www.phytec.in
10
3tart the =7, server( J gdbserver 1-6.1:*.1.11(10000 myled !ou have started the =7, server on the target. "he =7, server is now waiting for connections on "$P port 10000. 1.5.2. Con%iguring and starting t#e de,ugger in Eclipse &n this passage you will learn how to configure your pro;ect settings to use #clipse with the =NA debugger. 'fter the configuration of your pro;ect settings, the =NA debugger will start and connect to the =7, server on the target. N 3tart #clipse if the application is not started yet N Right-clic+ on the my ello<orld pro;ect in the Navigator window N 3elect 7ebug 's O 7ebug $onfigurations ' dialog to create, manage and run applications appears. N 3elect my ello<orld under $5$// 'pplication
www.phytec.in
1.
3elect gdbserver 7ebugger from the 7ebugger drop-down box $lic+ the ,rowse button right beside the =7, debugger input field. ' new dialog opens to choose the =7, executable. $lic+ on >ile 3ystem Navigate to the directory PPath of the "oolchainQ5bin 3elect the file arm-cortexa*-linux-gnueabi-gdb $lic+ 8)
www.phytec.in
1:
)eep the =7, command file field empty 3elect the $onnection tab and select "$P in the drop-down box #nter 1-6.1:*.1.11 Hthe targetBs &P addressI in the ost name input field. "he hostBs =7, will connect to this &P address to communicate with the targetBs =7, server
www.phytec.in
12
www.phytec.in
1*
"he debug perspective opens and the debugger stops automatically at the first line. "he hostBs =7, is now connected to the =7, server on the target.
!ou have configured your pro;ect for remote debugging. !ou have started the =NA debugger in #clipse and connected the hostBs =7, with the targetBs =7, server. !ou can now start to debug the pro;ect.
www.phytec.in
1-
1.5... Setting a "rea;point Now you will set a brea+point in your program. "he brea+point will be set on the last line of the function mainHI. &f you resume the application, the debugger will stop on this line.
3elect the last line in mainHI Right-clic+ into the small grey border on the left-hand side and select "oggle ,rea+point to set a new brea+point
www.phytec.in
00
1.5.3. Stepping and 0atc#ing <aria,le Contents &n this part you will step through the example pro;ect with the debugger. !ou will also learn how to chec+ the content of a variable. #xpand buf in the @ariables window
$lic+ the 3tep 8ver button in the 7ebug window to step to the next line
!ou will see the content of the buf variable in the @ariables window.
www.phytec.in
01
$lic+ on the variable buf "hen clic+ the button 3tep into to enter the function writeGttyHI
"he debugger stops in writeGttyHI. !ou will see the following variable window(
www.phytec.in
06
$lic+ on the variable buffer !ou will probably see a different address on the buffer pointer. Remember what address is shown in your caseR you will need this address later.
&n this section you will change the value of a variable. 't the end of this part you will see the effect of this change. 3elect the count variable in the @ariables window Right-clic+ on count and select $hange @alue
www.phytec.in
01
$hange the value of count to 2 and clic+ 8) 8pen 9inicom if the application is not already opened =o bac+ to #clipse $lic+ the 3tep 8verbutton two times
$hange to 9inicom
!ou will see the output <elcome in the 9icrocom window. "his shows when changing the counter variableBs value to 2 only the first seven characters of the buffer are output, instead of the whole sentence.
1.5.5. *sing t#e 'emor 'onitor &n the last section of this chapter you will use the memory monitor to control the content at a memory address. 3elect the 9emory tab $lic+ 'dd 9emory 9onitor
#nter the address of buffer and clic+ 8). Remember that the variableBs address might differ from your system.
www.phytec.in
00
www.phytec.in
0.
!ou can see the contents of the variable buffer at the address 0xbee11ca2 Hor whatever address is used on your systemI. Now clic+ the Resume button from the menu bar
"he debugger stops at the brea+point in the last line of mainHI. $lic+ the Resume button to end the application
www.phytec.in
0:
www.phytec.in
02
www.phytec.in
0*
2.2.1. Pre=&e>uists .ser utton dri$er should be enabled in Dernel below is configuarion details. It is already enable in our linux uImage. If you want to do it manually then. ,o to the kernel directory and type make menuconfig " make menuconfig 5ystem !ype ###: !I =>A7(/?/C 5pecific Features ###: RFS A>??@A based phyC=<+ A>??@A 8andle A>??@' =penboard >uxing ###: RFS .ser uttons dri$er 2.2.2. Compiling *ser S/itc# Application 2.2.2.1. Host Side First go to the application directory and then to the button directory. " cd final/button +xport the kernel source directory path, architecture, cross compiler " export DG5<CL/home/phytec/work//linux#?.( H!his is the path of your kernel sourceI " export A<C8Larm " export C<=55GC=>7IM+Larm#cortexa*#linux#gnueabi# After exporting these things just simply type make " make It will create a bin directory where dri$er.ko Hdri$er to be insertedI and buttonGshared, buttonGstatic Happlication to be executedI is created. /-/-/-/- (ar0et ide Copy the contents of the bin directory into the target using 52#CA<2, !F!7, .5 , etc. Insert the dri$er.ko into the kernel space using insmod " insmod dri$er.ko !hen run the Application " ./buttonGshared It will blink the leds depends on the buttons pressed.
www.phytec.in
0-
/-3- ADC
"he 8pen ,oard-'911.x provided additional '7$ expansion for '7$ $annels there we have * channel. !ou find it out in the board at connector number K-.0. 2...1. Pre=&e>uists >or testing the '7$ you can use an P8" which loo+s li+e
'
()')
$% -I&
P#T *&% +e can connect ' ()') to ,-./0 *&% to ,-./11 and $% -I& to $I&.-$I&2
&n the above figure we are using a 10 + Potentiometer 2...2. Compiling *ser ADC Application /-3-/-&- 5o+t ide First go to the application directory and then to the adc directory. " cd final/adc +xport the kernel source directory path, architecture, cross compiler " export DG5<CL/home/phytec/work//linux#?.( H!his is the path of your kernel sourceI " export A<C8Larm " export C<=55GC=>7IM+Larm#cortexa*#linux#gnueabi# After exporting these things just simply type make
www.phytec.in
.0
" make It will create a bin directory where adcGam??@'.ko Hdri$er to be insertedI and adc Happlication to be executedI is created. /-3-/-/- (ar0et ide Copy the contents of the bin directory into the target using 52#CA<2, !F!7, .5 , etc. 5tep#&; Insert the dri$er file adcGam??@'.ko " insmod adcGam??@'.ko 5tep#(; <un the adc user app to print the adc $alue 5yntax; adc 9channelGnum: " ./adc & 5tep#?; Change the $alue of 7=! and obser$er the $alues printed on the screen. // channelGnum % to B
www.phytec.in
.1
www.phytec.in
.6