Tag Archives: Ubuntu

Atmel AVRISP mkII working in Virtualbox

In the past I have had problems getting the Atmel AVRISP mkII to work with Virtualbox.  This can be really irritating if, like me, you want to write code in Linux but are forced to run Windows for Skype and various closed-source development tools (ugh).

Today, it seems to be working.  I can talk to the AVRISP with avrdude and program devices.  Cool!

I’m not sure what I changed.  I’m using Virtualbox 3.2.10 r66523, running on a Windows 7 64-bit host.  The VM/client OS is Ubuntu 10.10.  I created a USB filter for the AVRISP in the Virtual Machine settings; it doesn’t seem to work without it.  That might be what I was missing before.

To avoid having to run avrdude with root priveledges, I created the file /etc/udev/rules.d/10-avrisp2.rules with the contents:

SUBSYSTEM=="usb", SYSFS{idVendor}=="03eb", SYSFS{idProduct}=="2104", GROUP="adm", MODE="0666"

Pretty simple.

Oh, I should add that there is no guarantee other combinations of host/client OS will work.   If you’re getting different results, leave a comment.

AVR Toolchain Installation Instructions for Windows, Mac OS X, Linux

Mitch Altman and I are in the process of writing a book about Making Cool Things with Microcontrollers (for people who know nothing.)

The book features several DIY projects that use AVR microcontrollers.  We’re aiming to teach absolute beginners how to solder, basic electronics, and the process of turning a cool idea into reality by using microcontrollers.

I wrote these instructions about setting up a working avr-gcc environment in Windows, Mac OS X, or Linux.  Mitch and I felt that they could use some beta testing in the real world before bring included in the book, so we decided to make them available here.  We also felt that they might help some people get started with AVRs before the book is available.

We want to make the process of writing and compiling code for the AVR simple and accessible, so we’re not using any fancy IDEs (eg. no AVR Studio).  We also wanted to use the same software on all three operating systems, so Windows-only tools were out.  Instead, we’re using avr-gcc, the compiler behind WinAVR, CrossPack, and Arduino.

I would appreciate any feedback on these instructions.

Here they are:

Windows

Mac OS X

Linux

Update: I totally rewrote this post after getting feedback that I didn’t properly identify my target audience and explain why I chose avr-gcc.  Sorry!

Fix for broken avr-size in Ubuntu 10.04 (Lucid Lynx)

If you have never used it before, avr-size is a very useful command that does a relatively simple thing – it tells you how large your compiled avr-gcc programs are.  This is very useful knowledge when you are trying to fit as much code as possible into a part with only a few K of flash memory.  Additionally, the actual flash footprint of an AVR program is not something you can easily distill from a .hex file.  Hex files are usually much larger than the actual compiled code due to the overhead of that file format.

avr-size comes with the binutils-avr package in Ubuntu (and is installed as part of WinAVR and CrossPack on Windows and OSX, respectively).  Unfortunately, Ubuntu 10.04 (Lucid Lynx) ships with a broken version of avr-size that doesn’t include the necessary patches to support the AVR.

To see if your avr-size is working, open a Terminal in Lucid and try executing this command on a compiled avr-gcc .elf file of your choice:

avr-size -C --mcu=attiny2313 main.elf

You’ll probably see something like this:

avr-size: invalid option -- 'C'
Usage: avr-size [option(s)] [file(s)]
Displays the sizes of sections inside binary files
If no input file(s) are specified, a.out is assumed
The options are:
-A|-B     --format={sysv|berkeley}  Select output style (default is berkeley)
-o|-d|-x  --radix={8|10|16}         Display numbers in octal, decimal or hex
-t        --totals                  Display the total sizes (Berkeley only)
--common                  Display total size for *COM* syms
--target=<bfdname>        Set the binary file format
@<file>                   Read options from <file>
-h        --help                    Display this information
-v        --version                 Display the program's version
avr-size: supported targets: elf32-avr elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex

Bad news, but it’s not surprising. You have the broken version of avr-size that comes with binutils-avr for Lucid.

The solution:

I was able to fix this issue by installing the binutils-avr package for Debian Squeeze, an approach I learned about from this Ubuntu bug report.

To download the Debian binutils-avr package, either go to the Debian package repository or execute this command:

wget "http://ftp.us.debian.org/debian/pool/main/b/binutils-avr/binutils-avr_2.20.1-1_amd64.deb"

Now install the package by double clicking on it or executing:

sudo dpkg -i binutils-avr_2.20.1-1_amd64.deb

If you tell Ubuntu to “hold” the package you just installed, it should stop trying to revert to the broken version in the Lucid repository every time you run a system update:

echo "binutils-avr hold" | sudo dpkg --set-selections

You can check the hold status by running

sudo dpkg --get-selections | grep binutils-avr

The status should be shown as “hold” (not “install”).

Now if you run avr-size, you should see the special AVR option ‘-C’ is now present.

jkeyzer@atom:~$ avr-size --help

Usage: avr-size [option(s)] [file(s)]
Displays the sizes of sections inside binary files
If no input file(s) are specified, a.out is assumed
The options are:
-A|-B|-C  --format={sysv|berkeley|avr}  Select output style (default is berkeley)
--mcu=<avrmcu>            MCU name for AVR format only
-o|-d|-x  --radix={8|10|16}         Display numbers in octal, decimal or hex
-t        --totals                  Display the total sizes (Berkeley only)
--common                  Display total size for *COM* syms
--target=<bfdname>        Set the binary file format
@<file>                   Read options from <file>
-h        --help                    Display this information
-v        --version                 Display the program's version
avr-size: supported targets: elf32-avr coff-avr coff-ext-avr elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex

Report bugs to <http://www.sourceware.org/bugzilla/>

You can also test it out on a compiled .elf file:

jkeyzer@atom:~$ avr-size -C --mcu=attiny2313 main.elf

AVR Memory Usage
----------------
Device: attiny2313

Program: 2008 bytes (98.0% Full)
(.text + .data + .bootloader)

Data: 23 bytes (18.0% Full)
(.data + .bss + .noinit)

It works!  You now have a working avr-size command for Ubuntu.

There is a good chance this package will eventually be fixed in the Lucid repository, but based on the bug report above, it could be a while (2012?) before we see an update.  Until then, installing the Debian package seems to be a good solution.

If anyone reading this is close to the Ubuntu package maintainers, can you please kick them about this issue?

Run avrdude on Ubuntu without root

A quick tip for Ubuntu users:

As installed by the avrdude package on Ubuntu, avrdude needs root priveledges to work properly with the Adafruit USBTinyISP AVR programmer.  This gets annoying pretty fast because to program an AVR you need to run avrdude (or make) with sudo every time or log in as root (not recommended).  Without sudo, avrdude will return an error:

avrdude: error: usbtiny_transmit: error sending control message: Operation not permitted
avrdude: initialization failed, rc=-1
 Double check connections and try again, or use -F to override
 this check.
avrdude: error: usbtiny_transmit: error sending control message: Operation not permitted
avrdude done.  Thank you.

LadyAda points out in her avrdude tutorial that there is a way around this behavior by setting up some udev rules for the USBTinyISP.  However, I found that the rules given in her tutorial did not work with my stock Ubuntu 9.10 installation.  The problem arises because the user Ubuntu creates on install is not part of the “users” group.

The fix:

Create a file called 10-usbtinyisp.rules in directory /etc/udev/rules.d

 SUBSYSTEM=="usb", SYSFS{idVendor}=="1781", SYSFS{idProduct}=="0c9f", GROUP="adm", MODE="0666"

Then execute:

 sudo restart udev

That’s it.  Unplug and replug in the USB cable to your USBTinyISP programmer.  Now avrdude should be able to access the USBTinyISP without root privileges.

If your account is part of another group, just change the GROUP= flag to that group instead.  New users in Ubuntu are assigned to a group named after their username by default, so that is another option (ie. GROUP=”yourusername”).  Interestingly, new users are not assigned to the “users” group, for reasons that escape me (and no doubt some of our more Linux-savvy readers can enlighten us about).