Programming using avr-gcc and avrdude, Getting the prerequisites, Compiling an example program – Pololu A-Star 32U4 User Manual

Page 20

Advertising
background image

5.3. Programming using avr-gcc and AVRDUDE

This section explains how to program the A-Star boards using the avr-gcc toolchain and AVRDUDE. This section is
intended for advanced users who do not want to use the Arduino IDE as described in

Section 5.2

.

Getting the prerequisites

If you are using Windows, we recommend downloading

WinAVR

[http://winavr.sourceforge.net/]

, which contains the avr-

gcc toolchain and a command-line utility called

AVRDUDE

[http://www.nongnu.org/avrdude/]

that can be used to upload

programs to the A-Star bootloader. If the version of GNU Make that comes with WinAVR crashes on your computer,
we recommend using the

Pololu version of GNU Make

[https://github.com/pololu/make/releases]

.

If you are using Mac OS X, we recommend downloading the

CrossPack for AVR Development

[http://www.obdev.at/

products/crosspack]

.

If you are using Linux, you will need to install avr-gcc, avr-libc, and AVRDUDE. Ubuntu users can get the required
software by running:

sudo apt-get install gcc-avr avr-libc avrdude

After you have installed the prerequisites, open a command prompt and try running these commands to make sure all
the required utilities are available:

avr-gcc -v

avr-objcopy -V

make -v

avrdude

If any of those commands fail, make sure the desired executable is installed on your computer and make sure that it
is in a directory listed in your PATH environment variable.

Compiling an example program

Copy the following code to a file named “main.c”:

#define F_CPU 16000000

#include <avr/io.h>

#include <util/delay.h>

int main()

{

DDRC |= (1 << DDC7); // Make pin 13 be an output.

while(1)

{

PORTC |= (1 << PORTC7); // Turn the LED on.

_delay_ms(500);

PORTC &= ~(1 << PORTC7); // Turn the LED off.

_delay_ms(500);

}

}

In the same folder, create a file named “Makefile” with the following contents:

PORT=\\\\.\\USBSER000

MCU=atmega32u4

CFLAGS=-g -Wall -mcall-prologues -mmcu=$(MCU) -Os

LDFLAGS=-Wl,-gc-sections -Wl,-relax

CC=avr-gcc

TARGET=main

OBJECT_FILES=main.o

Pololu A-Star 32U4 User’s Guide

© 2001–2014 Pololu Corporation

5. Getting started

Page 20 of 30

Advertising