'avr/io.h' file not found

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

Hi everyone, I have macOS Catalina 10.15.1, and I'm a beginner in this Atmel world. The thing is, I have VS Code to write my .c code for the microcontroller atmega 328p. I've already installed CrossPack-AVR-20131216.dmg to compile and load my projects. I want to try the beginner program of blinking a LED, but I'm having problems with the 'avr/io.h' and 'util/delay.h' headers. The compiler says that the headers files can't be found.

The program is simple:

 

#include <avr/io.h>

#include <util/delay.h>

 

#define LED PB5

#define LED_DDR DDRB

#define LED_PORT PORTB

 

int main() {

    LED_DDR |= _BV(LED);

    while (1) {

        LED_PORT |= _BV(LED);

        _delay_ms(1000);

        LED_PORT &= ~_BV(LED);

        _delay_ms(1000);

    }

}

 

Also, /usr/local/CrossPack-AVR/bin is in my PATH. I don't know what I'm missing. Could you please help me?

Thank you.

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

Radiikal wrote:
20131216

 

Welcome to AVRFreaks!

 

Although I too am a mac user, I would either install the Arduino IDE or MPLABX as a way to do AVR dev on a mac, rather then a 3/or 4 year old dev system.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

ki0bk wrote:
I would either install the Arduino IDE
I think that at present that is the easiest/best way to get a copy of avr-gcc and AVR-LibC for Mac.

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

Can I write the code in C on the Arduino IDE? Cause it has to be obligatory on C language.

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

You don't need to actually use the Arduino IDE. It's just that the vast majority of what it delivers happens to be a full working version of the avr-gcc compiler, the GNU AVR binutils and the AVR-LibC C library. Once it's on your machine nothing stops you setting up your own choice of IDE to invoke that compiler and the other tools. In use they will use <avr/io.h> etc from the AVR-LibC library. The way they are built it should have no difficulty in finding that (and other) headers.

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

So, I uninstall the AVR-Crosspack and install the Arduino IDE and it has to solve the problem of the headers?

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

No need to uninstall anything - just install Arduino then switch to trying to use the avr-gcc within that rather than any other version that might happen to be on your PC.

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

Sorry for my ignorance but, how do I switch the avr-gcc from the CrossPack to the Arduino? Or it depends on my compiler?

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

How do you normally build your AVR code? Do you use command line make? Or  an IDE or something?

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

Yes, I use a command line make. But, when I do it, it says avr-gcc no such file or directory. 

This is my make:

DEVICE     = atmega8
CLOCK      = 8000000
PROGRAMMER = #-c stk500v2 -P avrdoper
OBJECTS    = main.o
FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m

# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:    main.hex

.c.o:
    $(COMPILE) -c $< -o $@

.S.o:
    $(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
    $(COMPILE) -S $< -o $@

flash:    all
    $(AVRDUDE) -U flash:w:main.hex:i

fuse:
    $(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
    bootloadHID main.hex

clean:
    rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
    $(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
    rm -f main.hex
    avr-objcopy -j .text -j .data -O ihex main.elf main.hex
    avr-size --format=avr --mcu=$(DEVICE) main.elf
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm:    main.elf
    avr-objdump -d main.elf

cpp:
    $(COMPILE) -E main.c

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

As you have:

COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

the key thing is "which?" copy of avr-gcc i s that going to actually invoke? What I am suggesting is that you order your PATH so that the one it encounters first is the avr-gcc that is delivered by the Arduino installation.

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

Okay, so I add the route to the Arduino avr-gcc to the PATH. Do you know exactly where can I find it?

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

Just install the Arduino IDE.    You have an ATmega328P.  Same as a 16MHz Uno.

Then try all the examples.    

You can install the bootloader if your hardware suits it i.e. has a USB->UART chip. 

Or use an external programmer e.g. USBASP, ATMEL-ICE, AVRISP-2, 

 

You can write regular C code in the Arduino IDE.    Just leave an empty "project.ino" and write your "regular.c" file.

 

The Arduino IDE editor is a bit crap but serviceable.

You can use an external editor if you want.

 

When you have everything working nicely on your Mac,   you can attempt to install another IDE.    There are several Mac users on this Forum who can help.

But I think that Arduino is the best way to "get started".

 

David.

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

Radiikal wrote:
Do you know exactly where can I find it?
I use Windows in which case:

D:\arduino-1.8.8>dir avr-gcc.exe /s /b
D:\arduino-1.8.8\hardware\tools\avr\bin\avr-gcc.exe

While things might be a bit different for the mac installation I would imagine it's in a tools/avr/bin somewhere under the installation.

 

As OSX seems a lot like Unix I imagine it must have "find" so CD to the place where Arduino lives and:

find . -name "avr-gcc"

to find out which sub-directory it is in.

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

Radiikal wrote:

Okay, so I add the route to the Arduino avr-gcc to the PATH...?

Or update your makefile so it uses the full path (once you've figured out where the tools have ended up)

COMPILE = /path/to/avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

 

You might find it useful in the Makefile to define the path to the tools dir once, and then define each tool in relation to that path, like

AVR_TOOLS_PATH = /usr/bin

CC      = $(AVR_TOOLS_PATH)/avr-gcc
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
etc.

and then use

$(CC)

$(OBJCOPY)

etc.

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

Since you’ve loaded vs code, if you load platformio it will load anything that is required to build.

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

Just install the Arduino IDE. 

If you get the "AVR Toolchain for Darwin from here: https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers

Then you'll be compatible with AVR Studio...

 

OTOH, Arduino is using their own build BECAUSE the above is a 32bit app and doesn't work on Catalina...

 

If you install Arduino in the default place, your toolchain will be somewhere like:

 

/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/