Programming Atmel using MySmartUSB Light and Ubuntu

By Ghost on Sunday 3 October 2010 11:57 - Comments (7)
Categories: Linux, Microcontrollers, Views: 14.150

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.

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.
[ 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:
sudo aptitude install avrdude binutils-avr avr-libc gcc-avr
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.

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
avr-gcc --target-help
and look for the 'Known MCU names' for a complete list.

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):
cat power3V.txt > /dev/ttyUSB0
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 BoardPowerOn.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.

Volgende: Subversion repository monitor 11-'09 Subversion repository monitor


By Tweakers user Forsith, Sunday 3 October 2010 12:12

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)

[Comment edited on Sunday 3 October 2010 12:13]

By Tweakers user Ghost, Sunday 3 October 2010 12:25

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?

By Tweakers user Morellow, Sunday 3 October 2010 19:16

Kan gewoon NL hoor

By Tweakers user Forsith, Sunday 3 October 2010 21:48

@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 :P ). I just wanted to warn you beforehand, because the electronics that we used were preset for High Voltage programming!

[Comment edited on Sunday 3 October 2010 21:48]

By Tweakers user hberntsen, Sunday 3 October 2010 23:03

Op die MySmartUSB site, kopje usage. Stoppen ze hem daar nou in de ethernet poort :+

By Igor Scheller, Wednesday 21 March 2012 15:22

cat BoardPowerOn.txt > /dev/tyUSB0 ?
I think it should be
cat BoardPowerOn.txt > /dev/ttyUSB0


By Tweakers user Ghost, Thursday 22 March 2012 08:40

Yup, you are right and I have fixed the typo. Thanks.

Comments are closed