Reputation: 1406
When compiling the following code:
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
DDRC = 255;
while(1){
PORTC=255;
_delay_ms(200);
PORTC=0;
_delay_ms(200);
}
return 0;
}
for ATMega16 is fine:
avr-gcc -w -Os -DF_CPU=1000000UL -mmcu=atmega16 -c -o main.o main.c
However, for ATMega164PA, I get these errors:
avr-gcc -w -Os -DF_CPU=1000000UL -mmcu=atmega164pa -c -o main.o main.c
error:
DDRC
undeclared (first use in this function)DDRC=255;
^
error:
PORTC
undeclared (first use in this function)PORTC=255;
^
It is even fine with atmega164p
but not atmega164pa
Upvotes: 1
Views: 3777
Reputation: 2096
This issue seems due to the fact that inside the file io.h
there's no specific file inclusion for the MCU type __AVR_ATmega164PA__
; there're only: __AVR_ATmega164P__
and __AVR_ATmega164A__
. I think the code for 164PA has to be compiled as 164P.
This is part of the code inside the file io.h
#elif defined (__AVR_ATmega163__)
# include <avr/iom163.h>
//------------------------------------------------------------ To note
#elif defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164A__)
# include <avr/iom164.h>
//--------------------------------------------------------------------
#elif defined (__AVR_ATmega165__) || defined (__AVR_ATmega165A__)
# include <avr/iom165.h>
If you see the compiler output, you might note more warnings:
In file included from avr164.c:3:0:
--------------------------------------------> To note
/usr/lib/avr/include/avr/io.h:428:6: warning: #warning "device type not defined" [-Wcpp]
# warning "device type not defined"
^
To note <---------------------------------------------
avr164.c: In function ‘main’:
avr164.c:8:1: error: ‘DDRC’ undeclared (first use in this function)
DDRC = 255;
^
avr164.c:8:1: note: each undeclared identifier is reported only once for each function it appears in
avr164.c:28:1: error: ‘PORTC’ undeclared (first use in this function)
PORTC=255;
^
The first warning: io.h:428:6: warning: #warning "device type not defined"
indicates you that the preprocessor has parsed the io.h
file till the line that emits the warning.
In the following lines of the file io.h
you may see where the warning is emitted.
#elif defined (__AVR_M3000__)
# include <avr/iom3000.h>
#else // <<<---------------------- To note!
// To note -------------------------------
# if !defined(__COMPILING_AVR_LIBC__)
# warning "device type not defined"
# endif
// To note -------------------------------
#endif
The emitted warning indicates you that probably there're no libraries for the specified target (and "fortunately" for my debugging purpose indicates also the end of the section of interest).
If you try to compile the SW without managing PORTC
and DDRC
(commenting their use), you should have a result like this:
In file included from avr164.c:3:0:
/usr/lib/avr/include/avr/io.h:428:6: warning: #warning "device type not defined" [-Wcpp]
# warning "device type not defined"
^
---------------------------> Note
/usr/lib/gcc/avr/4.8.2/../../../avr/bin/ld: cannot find crtm164pa.o: No such file or directory
collect2: error: ld returned 1 exit status
Note <---------------------------
The result indicates you there isn't a crtm164pa.o file in the linker environment. (And this is another problem!)
I've used: avr-gcc (GCC) 4.8.2
Upvotes: 2