Developing for the Atmel AVR Microcontroller on Linux
Using avr-gdb and simulavr in tandem, you can run your software on a choice of AVR microcontrollers through the simulator, while using GDB to step through and observe the executing code. Acquire the simulavr source from the project site and perform the installation:
$ ./configure --prefix=/usr/local/AVR \ --with-avr-includes=/usr/local/AVR/avr/include $ make # make install
Install GDB, built for AVR targets, by compiling the source as follows:
$ ./configure --target=avr \
--prefix=/usr/local/AVR
$ make
# make install
When you finally have a program ready for testing on actual hardware, you need some way to upload the data and write it to the microcontroller's Flash program memory. AVRDUDE and a compatible hardware programmer are the last components of the development kit. Grab a copy of the AVRDUDE source and install it with:
$ ./configure --prefix=/usr/local/AVR $ make # make install
You now have installed every software component required for a complete AVR development environment. All you need is the physical means to transfer programs to microcontrollers.
AVRDUDE supports a number of different hardware programmer configurations. The simplest systems are described on the AVRDUDE site and are comprised of little more than a parallel port connector, a ceramic oscillator and a DIP socket. These are powered directly off the computer's port and may not work for everyone.
A step up in complexity, independently powered, buffered in-system programmers can be built easily (see Resources). Two programmers requiring only a few parts are discussed on the Psychogenic Web page, which describes the schematics, provides artwork and has complete instructions on creating your own printed circuit boards (as depicted in Figure 2) for the programmers.
A number of commercial solutions also are available. If you're interested in easily programming a wide selection of the AVR family, go with Atmel's STK500 kit. More than a simple programmer, the STK500 is a starter kit that allows you to program the microcontrollers and easily prototype new designs. It includes a number of LEDs and switches, an oscillator, RS-232 interface and other niceties that easily can be interfaced with your target chip.
Our focus here is on the development system rather than on programming for the AVR platform. The AVR Libc documentation is a good place to start for information on programming AVRs in Assembly, C and C++.
The Hello World program of the microcontroller universe is the classic flashing LEDs. A slightly different take on this theme, which Knight Rider fans should appreciate, is available on the Linux Journal FTP site, where you can download C (Listing 2) or C++ (Listing 3) versions of an example program that cycles each of eight light-emitting diodes (LEDs) back and forth.
Create a project directory—for instance, ~/helloavr/—and retrieve the program, saving Listing 2 as ~/helloavr/kr.c and Listing 3 as ~/helloavr/kitt.cpp. Also, copy the Makefile template, /usr/local/AVR/Makefile.tpl, to ~/helloavr/Makefile.
Using this Makefile is easy and makes compilation a snap. Open the Makefile in your favourite editor and modify the configuration section, near the top of the file, so that the MCU, PROJECTNAME and PRJSRC variables are set as shown in Listing 4. The MCU variable determines the AVR family member for which we are compiling the program, and the PRJSRC variable lists all the Assembly, C and C++ source files used in the project.
Listing 4. HelloAVR Project Makefile Configuration Options
##### Target Specific Details ##### ##### Customize these for your project ##### # Name of target controller # (e.g. 'at90s8515', see the available avr-gcc mmcu # options for possible values) MCU=at90s8515 # Name of our project # (use a single word, e.g. 'myproject') PROJECTNAME=helloavr # Source files # List C/C++/Assembly source files: # (list all files to compile, e.g. 'a.c b.cpp as.S') # Use .cc, .cpp or .C suffix for C++ files, use .S # (NOT .s !!!) for assembly source code files. PRJSRC=kr.c
Once you've configured the Makefile, compiling and linking the program is as simple as typing make.
You can perform the compilation and linking steps manually instead, by issuing:
$ avr-gcc -I. -g -mmcu=at90s8515 -Os \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wstrict-prototypes -c kr.c
$ avr-gcc -o helloavr.out kr.o
The most notable difference is the addition of the required -mmcu command-line argument, used to specify the target microcontroller. Either method compiles kr.c and creates the helloavr.out ELF-format program. This file cannot be executed on your development station but is used later during the debugging stage.
You also can build the C++ version of the program by doing a make clean, changing the Makefile PRJSRC variable to kitt.cpp and then issuing another make.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- New Products
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Plug-and-Play Hardware
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Evernote is much more...
54 min 33 sec ago - Reply to comment | Linux Journal
9 hours 39 min ago - Dynamic DNS
10 hours 13 min ago - Reply to comment | Linux Journal
11 hours 12 min ago - Reply to comment | Linux Journal
12 hours 2 min ago - Not free anymore
16 hours 4 min ago - Great
19 hours 51 min ago - Reply to comment | Linux Journal
19 hours 59 min ago - Understanding the Linux Kernel
22 hours 14 min ago - General
1 day 44 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?






Comments
AVR microcontrollers
AVR microcontrollers is definitely user friendly since the combination of onboard reprogrammable Flash program memory and the in-system programming interface keeps the process of transferring software to the microcontroller simple and cheap.
______
texas criminal defense lawyer
Hi I run Ubuntu 8.10 but got
Hi
I run Ubuntu 8.10 but got troubles when making bin utilities. Giving message "format not a string literal and no format arguments"
Tried to google but one of the thread said it would be dificult to omit. I guess they are wrong but how to solve it is out of my mind. I understand it have something to do with 8.10 using -Wformat=2 and that this flag may give false positives. Any sugestions???
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.././opcodes -I. -I. -I.././opcodes -I../bfd -I.././opcodes/../include -I.././opcodes/../bfd -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g -O2 -c avr-dis.c -o avr-dis.o
cc1: warnings being treated as errors
avr-dis.c: In function 'avr_operand':
avr-dis.c:112: error: format not a string literal and no format arguments
avr-dis.c:152: error: format not a string literal and no format arguments
avr-dis.c:161: error: format not a string literal and no format arguments
avr-dis.c:172: error: format not a string literal and no format arguments
make[4]: *** [avr-dis.lo] Error 1
make[4]: Leaving directory `/home/zainka/Downloads/binutils-2.19.1/opcodes'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/zainka/Downloads/binutils-2.19.1/opcodes'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/zainka/Downloads/binutils-2.19.1/opcodes'
make[1]: *** [all-opcodes] Error 2
make[1]: Leaving directory `/home/zainka/Downloads/binutils-2.19.1'
make: *** [all] Error 2
AVR libc
Maybe the configure process for AVR Libc has changed since this was written; "./doconf" is not present in the archive I downloaded.
The INSTALL file tells me to:
./configure --build=`./config.guess` --host=avr
To follow the directory conventions in this article, append that with a "--prefix" option like this:
./configure --build=`./config.guess` \
--host=avr --pref \
--prefix="/usr/local/AVR"
Then make it with:
make
make install
AVR STK500
I have an AVR STK500 and I am using Ubuntu8.04. I am trying to download the update necessary to run the my AVR STK500 but I can't. Are these packages free?
Problem with optimization in the sample file kr.c from psychogen
I had a problem with gcc just skipping the busywait() function until i switched off optimization in the Makefile.
This resulted in all LEDs glowing since they were each turned on with approximately 30 clock cycles in between.
Lovely guide anyway!
Wrinkle (& resolution) using gcc-4.2.2 sources to build avr-gcc
I ran into a problem with the above instructions, using the gcc-4.2.2 sources. The build died with a long string of errors, starting with:
A little research showed this popping up for a few other folks trying to build cross-compilers with gcc 4.x. This message on the gcc-help list suggests that libssp is not likely to be needed when compiling for embedded systems, and suggests the expedient of disabling it during
configure. The following worked for me:$ ./configure --prefix=/usr/local/AVR \ --target=avr --enable-languages="c,c++" \ --disable-nls --disable-libssp $ make # make installSimulavr
Hi,
I am using simulavr version 0.1.2.2 in current Debian testing. In the article you stated, regarding output from simulavr, that "You should see a message to that effect, for example, writing 0xff to 0x0038." I don't get that output from simulavr, I only get the following message for each time through line 71:
Breakpoint 2, main () at kr.c:71
71 PORTB = ~currentValue;
(gdb) c
Continuing.
decoder.c:737: MESSAGE: BREAK POINT: PC = 0x00000045: clock = 194
Am I doing something wrong or could it be different versions of simulavr causing the problem?
Re: Simulavr
Ok,
I figured it out. I had to use the following changes to the simulavr command in one terminal:
simulavr --gdbserver --device at90s8515 -X -P simulavr-disp
Before I ran this command in another terminal:
The -X -P simulavr-disp invokes the display program, that shows all the register info for simulavr, and puts it in a normal terminal window instead of an xterm.
Re: Simulavr
The command I ran in the other terminal that I forgot to put above is the same as the one in the article:
avr-gdb -x gdbinit-helloavr