AVR ATtiny2313 in eclipse

I have just returned to using AVR chips, in particular the ATtiny2313 and it really is tiny to use. I am running on mac os x, and avrstudio wont run on mac, but luckily there is an eclipse avr plugin that works really well. First of all you need to install an avr compiler, avrdude. You can find it to download here cross pack. This provides you with a command line compiler for a selection of avr chips.

Next you need to install the eclipse plugin, and eclipse if you dont have it. Go to the eclipse environment, the help -> install new software menu, and add http://avr-eclipse.sourceforge.net/updatesite/ to the “work with” field. Once done only one option “AVR Eclipse Plugin” will be available. Install it. Now you should be set up to compile AVR code, by typically creating a new C project from the new avr plugin project wizard.

Finally you need an AVR programmer. Those familiar with the Arduino, you normally just need an usb cable to program the Arduino, but this is because it has a bootloader already programmed in to the chip to allow programming over usb-serial. There are a few cheap choices, such as the AVRISP MKII available at farnel, or the tinyusb from lady ada which I am using.

To get a programmer to work you have to tell eclipse about it. Under project settings -> AVR -> AVR Dude, select the programmer tab. Create a new programmer with the new button then in the next window find your programmer in the extensive list. Select it an give it a sensible name. Once assigned to your project you should now be able to upload a compiled program with the AVR upload button in the top menu bar.

Anyway that is all a bit brief but its hugely documented on google. The main reason I am writing this post is so I can remember this. The ATtiny2313 is well very tiny on memory. If you project is small then you wot have any problems, only I want to talk to an XBee chip over serial, and being greedy I want to use ASCII. To do most string operators you need to stdio.h library. This is a massive library and will easily fill up your memory, and if it doesnt it wont leave any space for performing tasks like sending string without causing strange data errors. There are a couple of things you can do.

Firstly in project settings -> c/c++ build -> settings -> AVR compiler -> optimisation, chose the option Size Optimisation (-Os). This will greatly reduce your compiled size.

Secondly you can using minimal size library references for stdio. In project settings -> c/c++ build -> settings -> AVR linker -> General -> other arguments, using the following command -Wl,-u,vfprintf -lprintf_min points the linker to a smaller but less capable stdio. This allows you to do string operations such as sprintf and include integer but with no support for floats or more complicated operators.

If your code compiles but does strange things, check the size your compiler outputs, and if over 90% try these two things and you should be able to loser 20% or so.

Leave a Reply