Friday, 22 September 2017

linux - AVR-GCC: Ports Undeclared when compiling


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 
#include
#include

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




Answer



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.



No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...