"avr/io.h" not found when compiling assembly for ATmega128

66 Views Asked by At

I'm new to assembler and ATmega128.

The problem I have is I can't compile my assembly file. After this step I'd want to upload the program to an STK-300.

Here's the code

.include "avr/io.h"

.org 0x0000
    rjmp reset

reset:
    ldi r16,0xff
    out DDRB,r16

loop:
    in r16,PIND
    ori r16,0b00000010
    andi r16,0b11110111
    out PORTB,r16
    rjmp loop

And I tried compiling it with

~ avr-gcc -mmcu=atmega128 -I/usr/lib/avr/include -o main.elf main.S
/tmp/cctvJInM.s: Assembler messages:
/tmp/cctvJInM.s:5: Error: can't open avr/io.h for reading: No such file or directory

Now I have installed avr-gcc, avr-libc and binutils-avr.

I don't really know how to debug this. I checked the avr directory and found the files

~ ls /usr/lib/avr/include/avr/
boot.h         ioa6285.h      iom168p.h       iom32.h         iom88pa.h    iotn828.h     iox256a3.h
builtins.h     ioa6286.h      iom169a.h       iom32hvb.h      iom88pb.h    iotn841.h     iox256a3u.h
common.h       ioa6289.h      iom169.h        iom32hvbrevb.h  iom88p.h     iotn84a.h     iox256c3.h
cpufunc.h      ioa6612c.h     iom169pa.h      iom32m1.h       iom8a.h      iotn84.h      iox256d3.h
crc16.h        ioa6613c.h     iom169p.h       iom32u2.h       iom8.h       iotn85.h      iox32a4.h
delay.h        ioa6614q.h     iom16a.h        iom32u4.h       iom8hva.h    iotn861a.h    iox32a4u.h
eeprom.h       ioa6616c.h     iom16.h         iom32u6.h       iom8u2.h     iotn861.h     iox32c3.h
fuse.h         ioa6617c.h     iom16hva2.h     iom406.h        iomx8.h      iotn87.h      iox32c4.h
interrupt.h    ioa664251.h    iom16hva.h      iom48a.h        iomxx0_1.h   iotn88.h      iox32d3.h
io1200.h       ioa8210.h      iom16hvb.h      iom48.h         iomxx4.h     iotn9.h       iox32d4.h
io2313.h       ioa8510.h      iom16hvbrevb.h  iom48pa.h       iomxxhva.h   iotnx4.h      iox32e5.h
io2323.h       ioat94k.h      iom16m1.h       iom48pb.h       iotn10.h     iotnx5.h      iox384c3.h
io2333.h       iocan128.h     iom16u2.h       iom48p.h        iotn11.h     iotnx61.h     iox384d3.h
...

I tried to include the more specific header file with .include "avr/iom128.h (but I don't really know which one I'd need exactly).

Does anybody know what the issue is, or has any tips to debug?

Thanks in advance.

1

There are 1 best solutions below

0
emacs drives me nuts On

avr/io.h is a C/C++ header that uses the C preprocessor, hence use

#include <avr/io.h>

.include would use gas's preprocessor, which has different syntax and runs at a different time (CPP runs prior to assembler, while gas's is run by the assembler proper).

avr-gcc -mmcu=atmega128 -I/usr/lib/avr/include ...

I'd remove that include path: A sane toolchain will know where to find it's headers. If the system headers are not found without further ado, then you have a broken installation.

FYI, with -save-temps added, CPP will save the pre-processed assembly in main.s.

Some more problems:

  • .org ... might not do what you expect. Write your code without .org. As you are using avr-gcc to drive the compilation, your code will be linked against the startup-code from AVR-LibC which includes the vector table and startup-code. You can just start you program in main.

  • out DDRB,r16: Here DDRB is the RAM-address of the SFR, not its I/O address!. See notes __SFR_OFFSET at https://www.nongnu.org/avr-libc/user-manual/group__avr__sfr__notes.html