Sei sulla pagina 1di 16

CEENBoT Programming in C with Eclipse and WinAVR

October 8, 2012 Version 1.0

Table of Contents

Introduction......................................................................................................................... 3 Installation components for Windows PCs......................................................................... 4 Installation Steps for Windows........................................................................................... 4 Installation components for Apple Mac Computers ........................................................... 7 Installation Steps for OSX .................................................................................................. 8 Configuring Eclipse for CEENBoT Programming ............................................................. 9 Troubleshooting Ideas....................................................................................................... 16

Introduction
The ability to program the CEENBoT's ATMEGA324 microcontroller is a requirement for some users. Free but proprietary software to write C software is available from Atmel, in their AVR Studio development environment. To obtain this software, users are required to register on the Atmel web site. The Atmel AVR Studio development environment is an excellent product. However, we would also like to provide an alternative comprised almost entirely of open source software for programming the AVR microcontroller. This document describes how to obtain and download Eclipse, Java, an AVR development tool set and other software required to do this. The only non-open source component is Java, a requirement for Eclipse. Several software packages will be needed to complete this, and all are available for free from the Internet. Due to licensing restrictions, we are unable to provide the installation software directly. However, links to the software are listed in the instructions for the Windows operating system and the Apple OS X operating system.

Installation components for Windows PCs


The software components for C programming include: Eclipse integrated development environment for C/C++ (we recommend this back revision version, Helios SR2, as it works much better with the add-in); http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/heliossr2

Java Run Time Environment software, at least version 5.0, needed because Eclipse runs on Java; http://www.java.com/en/download/index.jsp

WinAVR C compiler toolchain for Windows; http://sourceforge.net/projects/winavr/files/WinAVR/20100110/

AVREclipse plug-in to quickly configure Eclipse to work with AVR microcontrollers. http://sourceforge.net/projects/avr-eclipse/

Installation Steps for Windows


Download the software components described above and save them on your computer in a location where you will be able to find them. Install these software packages in the order described below: 1. Java 2. Eclipse 3. WinAVR 4. AVREclipse plug-in. When you run the Java package you download it will open an installer. We recommend using the default settings as they will put the software in the correct locations.

Using a program that will extract files from a *.zip file, unpack Eclipse to a folder named Eclipse in your Program Files (or for Vista or Windows 7, Program Files (x86)). We recommend creating an Eclipse shortcut on your desktop pointing to the eclipse.exe program in this newly created folder. 1. To install the AVR Eclipse plug-in, start up Eclipse. 2. Since this is the first run for Eclipse, you will be prompted to set up a location on the hard disk for Eclipse projects to be stored by default. On Windows, the default location is in your user space under documents and settings\<username>. This may not be convenient, as there are no quick links to this location. You may wish to modify the location to be in your "My Documents" folder. When you are satisfied with whatever location you choose, you can also click on the checkbox that makes this decision the default and it will not ask again. 3. One place to consider is in your My Documents folder, a subfolder named workspace. To avoid having to answer the default project location question every time Eclipse starts, we suggest checking the box for Use this as the default and do not ask again. 4. Go to the Help menu and select Install New Software. Use Work with: and click the Add button. 5. In the Add Repository window, enter a name for the plug-in like AVR Eclipse. Enter the web address of the plug in. http://avr-eclipse.sourceforge.net/updatesite/ 6. Click OK. At first the window will list pending for the plugin. In a few seconds it will change to AVR Eclipse Plugin with a check box. Select the check box for AVR Eclipse Plugin. Click Next. 7. On the next screen, Install, click Next. 8. On the Review Licenses screen, click the radio button to accept the terms of the license agreement. Click Finish 9. The plugin will download to your computer. 10. At the security warning, click OK. The warning appears because the plugin is not digitally signed. 11. The last window will prompt you to click Restart Now to load the new plugin. Click this button and wait for Eclipse to restart.

Run the downloaded WinAVR 20100110 package and install all of the parts of the package. Accept the default options for all installation choices. 12. Once the installation of these items is complete, one change is needed to force use of a correct supporting file. Navigate your Windows Explorer window to: C:\WinAVR-20100110\avr\lib\avr4\libc.a and rename this file to: C:\WinAVR-20100110\avr\lib\avr4\libc.a.bak

Installation components for Apple Mac Computers


The software components for C programming include: Eclipse integrated development environment for C/C++ (we recommend this back revision version, Helios SR2, as it works much better with the add-in); http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/heliossr2

Java Run Time Environment software, at least version 5.0, needed because Eclipse runs on Java; Apple provides the Java Run Time Environment for OSX. Apple also installs more than one version of Java Run Time Environment into OSX. We suggest updating the Java version on your Mac computer to the current version, and setting the default to use the most recent version supplied by Apple. Configuring Your Mac to Run the Latest Java Open a Filer window on your computer, find and select the Applications folder. Scroll down and open the Utilities folder. Scroll down to Java Preferences and start the program. The window will show different versions of Java installed on your Mac. You will want to use the newest (highest version number) and if possible the 64-bit version. The configuration change is simply un-checking the older versions, and checking the newest Java-64 bit version. Drag this selected version to the top of the list and your computer will run only the latest version of Java.

CrossPack C compiler toolchain for OS X; http://www.obdev.at/downloads/crosspack/CrossPack-AVR-20120217.dmg

AVREclipse plug-in to quickly configure Eclipse to work with AVR Microcontrollers. http://sourceforge.net/projects/avr-eclipse/

Installation Steps for OSX


Download or install software the software components described above. Java must be obtained from Apple via the App Store. Save downloaded programs on your computer in a location where you will be able to find them. Install these software packages in the order described below: 1. Java (from the Apple App Store) 2. Eclipse 3. CrossPack 4. AVREclipse plug-in. When you run the Java package you download it will open an installer. We recommend using the default settings as they will put the software in the correct locations. Using a program that will extract files from a *.zip file, unpack Eclipse to a folder on your desktop. Drag the Eclipse folder to your Applications folder (or for Vista or Windows 7, Program Files (x86)). We recommend creating an Eclipse shortcut on your desktop pointing to the eclipse.exe program in this newly created folder. Run the downloaded CrossPack package and install all of the parts of the package. 13. To install the AVR Eclipse plug-in, start up Eclipse. 14. Go to the Help menu and select Software Updates -> Find and install. 15. Select search for new features to install 16. Click New Remote Site and enter AVR Plugin for Name this URL:

http://avr-eclipse.sourceforge.net/updatesite/
17. Follow the rest of the wizard. 18. Once the installation of these items is complete, one change is needed to force use of a correct supporting file. Navigate your Finder window to: CrossPack-AVR-20100115/avr-4/lib/avr4/libc.a and rename this file to: CrossPack-AVR-20100115/avr-4/lib/avr4/libc.a.bak

Configuring Eclipse for CEENBoT Programming


If it is not already running, start Eclipse. The icon on the far right of the Eclipse desktop will open the working area of the program. Click on this button, Workbench. To start a new project go to File->New->C Project. In AVR Cross Target Applications, select Empty Project and enter Project name. Click Next. This name also serves as new project folder. In the demonstration the project name is Test. In a few seconds, an icon named Test will appear in the left window of Eclipse. In the Select Configurations window, clear the check in the Debug box, leaving the Release box checked. Then click the Next button to go to the next properties choice for the Test project. The next window allows you to set the microcontroller for the robot. Select ATMega324P from the MCU Type dropdown list. Next edit the MCU Frequency (Hz) to be 15,000,000 (15000000). This setting will make software timing loops more accurate.

Figure 1 - (<project>, AVR, Target Hardware, MCU Type)

Highlight and right click the Test icon in the left window, and select "Properties" from the bottom of the dropdown menu. Starting with AVR > AVRDude, Programmer tab, select the New button to select the programmer you have to use for loading software onto the robot. Give this configuration choice a name, such as AVR ISP mkII. A long list of available programmer choices displays in the left side window. In our examples, the programmer we will use is the Atmel AVR ISP mkII programmer. This programmer choice is about 1/3 down the list. Below the list is text box for Overriding the default port (-P). Enter usb (no quotation marks, lower case letters). Click Apply, then OK Eclipse now knows the type of microcontroller you are using, and the make and model of the programmer you will use to load your programs.

Figure 2 - Set standard options for programmer, target processor, target processor speed

Click Finish. Next select C/C++ Build on the left side window. At the top of the page, if Configuration is anything but Release change it to be Release.

Select the Settings option in the left window. A long list of options will appear in the right window. Starting with the first option, Additional Tools In Toolchain, check all of the boxes for generating files, as well as Print Size, and AVRDude. These are steps that will be performed in each build process.

Figure 3 - Set output options for flash hex file build, AVRDude

Next, under AVR Assembler > Debugging, use the dropdown window to set Generate Debugging Info to No Debugging Info. Under AVR Compiler > Debugging, use the dropdown window to set Generate Debugging Info to No Debugging Info. Under AVR Compiler > Optimization, set Optimization Level to Size Optimizations (-Os) and set Other Optimization Flags to: -ffunction-sections -fdata-sections -Wl,--gc-sections This is to reduce the final file size.

Select AVR C Linker from the left side window. Replace the contents of Command line patterns with: ${COMMAND} --cref -s -Os ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -lm ${FLAGS} This is all one line, although formatting in this document is adding line returns. This will help reduce the size of the executable file produced in a build.

Click Apply and then OK. The next two changes will tell Eclipse where to find some required library files. Select AVR C Linker > General and add to Other Arguments, "-Wl,-u,vfprintf -lprintf_flt -lm" Note that the double quote marks are NOT INCLUDED in the pasted text.

Click Apply and then OK. Select AVR C Linker > Libraries. Windows: From the Libraries Path (-L) section, click on the Add Directory Path option (+ plus sign icon), and enter: "C:\WinAVR-20100110\avr\lib\avr4" And, "C:\WinAVR-20100110\avr\include\avr" Mac OSX: From the Libraries Path (-L) section, click on the Add Directory Path option (+ plus sign icon), and enter: /usr/local/CrossPack-AVR-20100115/avr-4 /usr/local/CrossPack-AVR-20100115/avr-4/include and, /usr/local/CrossPack-AVR-20100115/avr-4/lib/avr4 Note that the double quote marks ARE INCLUDED in the pasted text.

Click Apply and then OK. Click OK to close the Properties window.

Troubleshooting Ideas
Error messages: make: *** [avrdudedummy] Error 1 This is probably Eclipse obtuse way of telling you that the programming step failed, either because you dont have the programmer connected, or you dont have the CEENBoT controller connected or turned on. Plug in the programmer at the PC and the controller, and turn on the controller. To be determined This is AVRDude saying it cannot find a port on the computer. You probably need to edit the project Properties, AVR, AVRDude, Programmer Configuration, and specify Override default port (-P) to add usb (no quotes, lower case) so it can find the programmer. In the *.h file, you have a line containing #define F_CPU 15000000L. This line competes with the project Properties, AVR, Target Hardware MCU Clock Frequency entry. To make sure the variable is set, wrap the F_CPU define with: #ifndef F_CPU #define F_CPU nnnnnnn #endif Eclipse cant find the libprintf_flt.a and libm.a libraries. When adding the static library to the linker you have to remove the lib prefix and the .a suffix.

make: *** [FW1104.elf] Error 1 avrdude: stk500_2_ReceiveMessage(): timeout

warning: "F_CPU" redefined

Potrebbero piacerti anche