2
\$\begingroup\$

My Setup

I'm running Ubuntu 12.10, and I want to be able to use gcc and avrdude to compile and program my ATmega328.

I followed this Ladyada tutorial: Ladyada AVR Tutorial

Everything installed perfectly, no errors or warnings. I have not installed avrdude yet, but that is beside the point.

I use the command:

avr-gcc -O0 -c blink_1MHz.c -o main.o

However, I get one warning, and many errors:

warning "device type not defined"

error: 'PORTC' undeclared (first use in this function)

The error above repeats itself for each Port and each Data Direction Register used in the code.

blink_1MHz.c is just some simple code I'm using to test my setup. It has worked on my Windows setup through AVR Studio 6.

I've tried Google, but the only real suggestion I got was to import the libraries:

#include <avr/io.h>
#include <stdlib.h>
#include <stdint.h>

Unfortunately, still nothing. I've been playing around with this for a while and I'm simply stumped. I saw suggestions that avr-libc isn't installed, but I have installed avr-libc. I would think that if I didn't have it installed, I would be seeing complaints about the libraries not existing.

Question

Could an enlightened individual suggest what may be the cause of these errors? Thanks.

EDIT

Amoch pointed out that I needed to check out avr/io.h; there you will see that you need to define the processor with the -mmcu flag. In my case, I have an ATmega328, so my command looked like:

avr-gcc -O0 -c blink_1MHz.c -mmcu=atmega328 -o main.o

\$\endgroup\$
  • \$\begingroup\$ It is bad practice to use screenshots for a pure text dump. When searched through Google these error messages will never be found and therefore renders the question to lower value for others. Although the question is answered now, it would be nice if you could reproduce the errors and paste them as normal text. It'll help other visitors. \$\endgroup\$ – jippie May 30 '13 at 6:25
  • \$\begingroup\$ You're right. I was just too lazy to type it out, and I wanted the comprehension of the screenshot. I edited the picture out and added some of the errors and warnings in text. \$\endgroup\$ – Nick Williams May 30 '13 at 14:07
4
\$\begingroup\$

I'm not familiar with AVRs but the compiler is telling you that it can't find where "PORTC" etc are defined. Normally these definitions are included via a header file, and from your post I would suggest that it is likely avr/io.h. You will need to take a look at this file and determine that it is the source of these missing definitions. Further more, the first error that is encountered states that "device type not defined". This means that this header file requires a #define to inform it which code to include for the processor that you are using. This would normally be provided to the compiler via a -D option.

Seeing that you have had this working on windows under AVR studio, I suggest that you dig into the compiler settings within the GUI or examine the console output and find out exactly what is being passed to the compiler under windows so that you can copy the settings in your custom build under linux.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Your suggestion to look into avr/io.h paid off! I knew I had to define the processor somehow; but there is nothing when I typed: avr-gcc --help. Digging through avr/io.h, I saw that I had to define the processor with -mmcu. Thanks Amoch! +1 and accepted. I'll make an edit pointing out the correct command to send. \$\endgroup\$ – Nick Williams May 30 '13 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.