Programming in Linux

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am getting the following error while compiling

 

led.c:3:20: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
                    ^
compilation terminated.

 

also I have done installing   avr-gcc,  avr-libc, binutils

 

need help!!!

 

Last Edited: Fri. Apr 21, 2017 - 05:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hari_22 wrote:
also I have done installing avr-gcc, avr-libc, binutils
By "installing" do you mean "apt-get install XXXX" ? Or something else?

 

The fact is that when avr-gcc is built it is "configured" to have a knowledge of where to look for avr-libc. The error you show suggests the avr-libc headers such as io.h are not installed in the location that the avr-gcc itself has been configured to use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ya using apt-get install XXXXX only used. Have to change the location?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope it should be set OK to start with. If you used apt-get can I assume this is a derivative of Debian? In fact can I assume it is Ubuntu? If it is Ubuntu which version is it? In some of the older ones the repository maintainers did not have a clue how to build avr-gcc correctly. But from about 12.04LTS onwards they started to get it right.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its ubuntu 14 version. Even In other system I have used before, I have not faced any probelm. This first time I am using in new one.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Should work in 14. Most odd.

 

Try adding a "-H" to the command line that is trying to build the code where you include <avr/io.h>. That will show you the locations it looks for header files. Are the headers installed from avr-libc (dpkg -L) in that same location?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now the its shows as:

 

In file included from led.c:1:0:
/usr/lib/avr/include/avr/io.h:428:6: warning: #warning "device type not defined" [-Wcpp]
 #    warning "device type not defined"
      ^
In file included from led.c:5:0:
/usr/lib/avr/include/util/delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
   ^

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Exactly what command are you invoking the compiler with?

 

Are you doing the sensible thing and using an IDE or Mfile or DMBS or similar to build the code or are you just typing raw avr-gcc commands at the shell ?

 

If the latter then you have forgotten the -mmcu=atXXXX that tells the compiler/library which model of AVR it is you are building for. It might be something like -mmcu=atmega16 or -mmcu=atmega328p or -mmcu=attiny85 or -mmcu=atxmega128a1u but only you know which model of AVR it is you are building for here. If the value to use in -mmcu= is not obvious then run avr-gcc with --target-help to get a list of all the models of AVR it knows about and which can be used in -mmcu.

 

But if you have forgotten -mmcu= you have probably omitted other vital command line parameters like -Os or -gdwarf-2 or -ffunction-sections or -Wl,-gc-sections or any of the other important options. This is why using a utility like Mfile (that already knows all the important options) is a good idea!

 

Better yet get something like Eclipse or Code::Blocks and use it as an IDE for avr-gcc

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I programmed through vim editor and compiling using         avr-gcc -mmcu=atmega32 Os led.c o led.o

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now its working... dont know exact problem, during first installation of files I installed all files together by giving all packages in single command line.

Now I removed all files and installed one by one and its working now.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am in need of another help. how to burn the .hex file into chip using usbasp programmer in linux.

Need command?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"apt-get install avrdude"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have already installed avrdude. command to burn .hex file

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You asked:

Hari_22 wrote:
Need command?

The command to use is "avrdude".

 

There's loads of examples on the internet about how to invoke it for using a USBAsp.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hari_22 wrote:
Now its working... dont know exact problem, during first installation of files I installed all files together by giving all packages in single command line.

Now I removed all files and installed one by one and its working now.

Probably you were not using the command you remember.

This command is almost certainly wrong:

Hari_22 wrote:
I programmed through vim editor and compiling using         avr-gcc -mmcu=atmega32 Os led.c o led.o

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ie, command should be like:

   avr-gcc -mmcu=atmega32 -Os -o led.elf led.c

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You also have to tell Linux something about your programming device. I.E. is it an AVRisp-MKII or something else.

 

I have two Toshiba notebooks, three Dell desktops, all running Ubuntu Mate 16.0.4.  They communicate with devices ranging from the FTDI232RL used by personal projects, CH341 used on some cheap Arduino Nano v3 controllers and Atmel's new USB ( FTDI replacement ) device that are now part of the Arduino Uno R3 and Mega2560 controllers.  As well, I have a V-Pro GRBL motion comtroller attached to a Toshiba notebook and, I have two Mega2560 R3 (using the new Atmel USB device) controllers, both acting as GRBL motion controllers that are each attached to their own Raspberry Pi and running bCNC on Ubuntu Mate 16.0.4.

 

Following is the procedure I use for enabling serial devices in Linux Ubuntu Mate 16.0.4.

# Mounting Atmel AVR MKII class devices to the Linux udev() USB server

# What to do...
#--------------------------------------------------------------------------

# Open a terminal.
# root using "sudo -s"
# Enter password

# cd /lib/udev/

# Using a text editor (vi, vim, gvim, pluma, etc.) open a new file:
# 60-avrisp.rules

# Add the following

# BEGIN AVRISP SERVICE
#--------------------------------------------------------------------------
#  	AVRJTAG-MKII, AVRISP-MKII, AVRDRAGON USB mount rules
#--------------------------------------------------------------------------

SUBSYSTEM!="usb_device", ACTION!="add", GOTO="avrisp_end"

# Atmel Corp. JTAGICE-MKII
ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2103", MODE="660", GROUP="carl"

# Atmel Corp. AVRISP-MKII
ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="660", GROUP="carl"

# Atmel Corp. AVR Dragon
ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2107", MODE="660", GROUP="carl"

LABEL="avrisp_end"

#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# END AVRISP SERVER

# Save the file to the folder:
# /lib/udev and close the text editor

# Move to the rules.d sub-directory
# cd lib/udev/rules.d

# Create a virtual link for non-root access
# run:
# sudo ln ../60-avrisp.rules 60-avrisp.rules

# Restart the rules processing service
# run:
# sudo restart udev
#
# or the following on the Raspberry Pi uning the Raspberry Pi Ubuntu Mate fork.
#
# sudo /etc/init.d/udev restart

# If the USB cable is already attached to the machine,
# remove the USB cable for a few seconds,
# then plug it back into the machine's USB port.
# or
# You MUST perform a complete power cycle (NOT A REBOOT) of the machine.
#
# Install AVRDude
#
# Use the following command to see if avrdude is talking to the connected avrisp-mkii programmer.
# avrdude -p m328p -P usb -c avrispmkii -b 115200 -t
#            ^^^^^ <--- Your target AVR device.
#
# You only have to do the above one time
#
# Its good to go until you want to add another type of programmer to the system.

In the above script, YOU MUST assign a group to each attribute string, as in the following:

 

        ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="660", GROUP="carl"

 

It doesn't seem to matter which group you assign, as long as YOU belong to that group.  Groups include your "User Name" (in my case "carl") "adm", "tty", etc.

 

You do this in "system/administration/usersandgrooups/users settings".  Click on the "Manage Groups" button and a list of groups will pop up that you can select from.  While in "Users And Goups" uou might as well click on the "change" button for "Account Type" and make yourself an "Administrator".

 

Once you've done all of the above, you MUST unplug your USB cable from the machine for a few seconds and then plug it back into the machine.  That, or perform a power cycle (NOT A REBOOT) on you machine, in order for Linux to recognize your hardware device to becime registered in the Linux operating system.

 

If you don't perform the above, you will get permissions error messages, and possibly other error messages related to the device you are attempting to communicate with.

 

EDIT:

    Spelling corrections.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

Last Edited: Sat. Apr 22, 2017 - 12:50 PM