Programming Atmel using MySmartUSB Light and Ubuntu
Recently, I grew interested in programming Atmel microcontrollers. So with the help of a friend I bought some neccessary components, including the MySmartUSB Light. As an Ubuntu user and newbie engineer, I was a little bit worried how much trouble it would be to get the programmer to work. As it turns out, no trouble at all.
Connecting
The MySmartUSB Light requires a USB port instead of the more common parallel or serial port. However, as soon as the programmer is plugged in, the Linux kernel will recognise it as a serial interface, so no difference there.
To program the Atmel chips, you need some software components. Luckily, they all are available through the Ubuntu repositories. Installing goes like this:
To make things easier, I found a Makefile tailored for Atmel projects. This allows compiling for and writing to microcontrollers from the command line quite easy. The Makefile is suitably commented, and after setting the correct target controller (MCU), programmer id (AVRDUDE_PROGRAMMERID), and programmer port, you are good to go.
MCU values can be found by running
The programmer id for MySmartUSB Light is by default 'STK500' and the port is often /dev/ttyUSB0 or /dev/ttyUSB1. Look at the dmesg output after connecting the programmer to be sure.
Anyone interested in using a GUI for writing to the chip, I can recommend AVR8-Burn-O-Mat. I cannot say for sure it will work for every AVR chip, though. There is also a very complete programming IDE from Atmel, called AVR Studio, available for free. You do have to fiddle around with Wine to make this work, but all is explained in this tutorial.
Powering the board
The programmer can also be used as a power source. It supports both a 3V and 5V current ouput, which can be set using software. For that, you have to send a specific code sequence to the port.
An overview of these command sequences can be downloaded from the myAVR site. The archive contains a bunch of txt files, each with their own sequence. For example, the sequence for setting the board to 3V is stored in the file power3V.txt.
To use these commands, you can simply cat them to the port the programmer is connected to (make sure the port is configured properly using picocom):
Connecting
The MySmartUSB Light requires a USB port instead of the more common parallel or serial port. However, as soon as the programmer is plugged in, the Linux kernel will recognise it as a serial interface, so no difference there.
Software[ 4474.226058] USB Serial support registered for cp210x
[ 4474.226115] cp210x 3-2:1.0: cp210x converter detected
[ 4474.336078] usb 3-2: reset full speed USB device using uhci_hcd and address 2
[ 4474.487284] usb 3-2: cp210x converter now attached to ttyUSB0
[ 4474.487322] usbcore: registered new interface driver cp210x
[ 4474.487327] cp210x: v0.09:Silicon Labs CP210x RS232 serial adaptor driver
To program the Atmel chips, you need some software components. Luckily, they all are available through the Ubuntu repositories. Installing goes like this:
Avrdude is a command line tool for programming the chips, while binutils-avr and gcc-avr are the cross-compile tools for creating the binaries. Avr-libc is libc, the standard C library, cross-compiled for AVR chips.sudo aptitude install avrdude binutils-avr avr-libc gcc-avr
To make things easier, I found a Makefile tailored for Atmel projects. This allows compiling for and writing to microcontrollers from the command line quite easy. The Makefile is suitably commented, and after setting the correct target controller (MCU), programmer id (AVRDUDE_PROGRAMMERID), and programmer port, you are good to go.
MCU values can be found by running
and look for the 'Known MCU names' for a complete list.avr-gcc --target-help
The programmer id for MySmartUSB Light is by default 'STK500' and the port is often /dev/ttyUSB0 or /dev/ttyUSB1. Look at the dmesg output after connecting the programmer to be sure.
Anyone interested in using a GUI for writing to the chip, I can recommend AVR8-Burn-O-Mat. I cannot say for sure it will work for every AVR chip, though. There is also a very complete programming IDE from Atmel, called AVR Studio, available for free. You do have to fiddle around with Wine to make this work, but all is explained in this tutorial.
Powering the board
The programmer can also be used as a power source. It supports both a 3V and 5V current ouput, which can be set using software. For that, you have to send a specific code sequence to the port.
An overview of these command sequences can be downloaded from the myAVR site. The archive contains a bunch of txt files, each with their own sequence. For example, the sequence for setting the board to 3V is stored in the file power3V.txt.
To use these commands, you can simply cat them to the port the programmer is connected to (make sure the port is configured properly using picocom):
Note that this sequence only switches the current voltage. By default, no power is fed through the SPI connector yet. To power on the board, use the following command:cat power3V.txt > /dev/ttyUSB0
Remember that after the initial connection or programming a chip, the power is always switched off and the BoardPowerOn command must be used.cat BoardPowerOn.txt > /dev/ttyUSB0
11-'09 Subversion repository monitor
Comments
In college/school/university we used the Atmel AVR Atmega32 in combination with the STK500 motherboard. It looks like your are using High Voltage Programming, which is kind of dangerous. At least, that is what they told us. Therefore we had to replace the processor into the other socket on the STK500 so one didn't need to fiddle with voltages etc. I don't know if it's possible with your motherboard to use the standard programming mode (not High Voltage), but you might be a bit more on the safe side using it.
Anyway, it sounds like you are about to have a lot of fun with the AVR :-).
Edit: Standard programming - > ISP (In System Programming)
Anyway, it sounds like you are about to have a lot of fun with the AVR :-).
Edit: Standard programming - > ISP (In System Programming)
[Comment edited on Sunday 03 October 2010 12:13]
I am definitely looking forward programming these controllers 
About the programming mode: the dongle only has a ISP connector I can use for programming, so does this automatically mean I use the standard programming mode?
About the programming mode: the dongle only has a ISP connector I can use for programming, so does this automatically mean I use the standard programming mode?
Kan gewoon NL hoor
@Ghost: Yes, I suppose so :-). I don't know if your motherboard has the option for high voltage programming, but if so, note that it is only for advanced users since you can blow everything up if you do it wrong (or right
). I just wanted to warn you beforehand, because the electronics that we used were preset for High Voltage programming!
[Comment edited on Sunday 03 October 2010 21:48]
Op die MySmartUSB site, kopje usage. Stoppen ze hem daar nou in de ethernet poort 
cat BoardPowerOn.txt > /dev/tyUSB0 ?
I think it should be
cat BoardPowerOn.txt > /dev/ttyUSB0

I think it should be
cat BoardPowerOn.txt > /dev/ttyUSB0
Yup, you are right and I have fixed the typo. Thanks.