attiny412 avr-gcc 'PORTA' undeclared (first use in this function)'

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

Hi there!

 

I have successfully compiled the toolchain for avr-gcc on my mac by following these instructions, and I have a Makefile that can successfully compile and burn an empty main.c file to an attiny412 using a jtag2updi adapter I made with an arduino nano. So far so good!

 

The problem I am having now is how to get the register definitions to be usable so I can get a blink test going. As soon as I try to access, say, PORTA, I get errors. Here is the code I am trying to build (I know it won't do anything, keeping it short just to fix this error):

 

#include <avr/io.h>
#include <util/delay.h>

int main() {
  PORTA.DIR = 0xff;

  while(1) {
    _delay_ms(500);
  }
}

and here is my build command and output:

avr-gcc -Wall -Os -DF_CPU=1000000 -mmcu=attiny412 -c main.c -o main.o
In file included from main.c:7:
/usr/local/avr/avr/include/avr/io.h:581:6: warning: #warning "device type not defined" [-Wcpp]
  581 | #    warning "device type not defined"
      |      ^~~~~~~
main.c: In function 'main':
main.c:11:3: error: 'PORTA' undeclared (first use in this function); did you mean 'PORT0'?
   11 |   PORTA.DIR = 0xff;
      |   ^~~~~
      |   PORT0
main.c:11:3: note: each undeclared identifier is reported only once for each function it appears in
make: *** [main.o] Error 1

I know there are some posts around about similar issues in Atmel Studio, but I am wondering what the Right Way to fix this on a linux system using avr-gcc is. Should I add lines to avr/io.h that link to defs from the atmel pack? Thanks a lot!

 

-Charlie

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

The core compiler only "knows" some AVR models (about 250), the more recent ones are added by what are known as "device packs" so for a new chip like 402 you likely need -B on the command line and tell it where to look for the device pack. As example this is what AS7 does when I try to build your code for 402...

"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  
    -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATtiny_DFP\1.3.229\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct 
    -fshort-enums -g2 -Wall -mmcu=attiny402 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny402" -c 
    -std=gnu99 -MD -MP -MF "main.d" -MT"main.d" -MT"main.o"   -o "main.o" ".././main.c" 
Finished building: .././main.c

To get the pack you need you will probably need to visit:

 

http://packs.download.atmel.com/

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

...or open Atmel Studio and then select Tools / Device Pack Manager and download all updates

extronic.pl

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

Do you have the specs-attiny412 correct? Compiling with -H iotn412.h must be in the displayed file list.
.
You need avr-libc from SVN trunk or else avrxmega3 multilib support is missing for the libc bits.

avrfreaks does not support Opera. Profile inactive.

Last Edited: Wed. Jul 31, 2019 - 04:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks so much for the replies. This was solved by adding "-D__AVR_DEV_LIB_NAME__=tn412" to the build options, now everything works! Final is:

 

avr-gcc -Wall -Os -DF_CPU=1000000 -mmcu=attiny412 -D__AVR_DEV_LIB_NAME__=tn412 -c main.c -o main.o
avr-gcc -Wall -Os -DF_CPU=1000000 -mmcu=attiny412 -D__AVR_DEV_LIB_NAME__=tn412 -o main.elf main.o

 

Last Edited: Wed. Jul 31, 2019 - 08:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This option should be set by the *cpp spec in specs-attiny412.

avrfreaks does not support Opera. Profile inactive.

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

I checked and I do have the specs file with the *cpp def, but I'm not sure I follow your suggestion. If this is my current build line:

 

avr-gcc -Wall -Os -DF_CPU=1000000 -mmcu=attiny412 -D__AVR_DEV_LIB_NAME__=tn412 -c main.c -o main.o

what should it be to pick up the instructions from the specs file as you describe?

 

thanks again

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

 

I will bring you back to:

-B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny402"

When I look at that directory on my PC:

 

 

So if you get the device pack from Atmel and then direct the compiler to it using -B on the command line it should find the specs file it needs - it will also find the right CRT and LIB too.

 

Some of the important data in that file are:

*cpp:
        -D__AVR_ATtiny402__ -D__AVR_DEVICE_NAME__=attiny402 -D__AVR_DEV_LIB_NAME__=tn402

%rename link old_link

*link:
        %(old_link)--defsym=__RODATA_PM_OFFSET__=0x8000

 

Last Edited: Thu. Aug 1, 2019 - 08:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Move that option from the command line to the spec file. If you get a build error then it's not the spec file actually in use. There is detailed comment in the spec file on how avr/io.h works and how to adjust the specs.
.
To see the actual subtool options add -v to the command line.

avrfreaks does not support Opera. Profile inactive.

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

Despite ATtiny402, ATtiny412 is supported by avr-gcc v8+. What's missing is the avr-libc support. The shown %rename of *link is wrong for ATtiny412.

avrfreaks does not support Opera. Profile inactive.

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

Admittedly my own Atmel device packs (above) are not up to date so I would check the latest from Atmel - they keep fixing things for these recent devices.

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

isnt the latest pack is 1.3.229 ?

 

via http://packs.download.atmel.com/

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

No idea - I haven't updated in months so I have no idea what is current.

 

But it does seem that Microchip/Atmel have made so many mistakes in the support files for these new AVR-0/1 things that they have to reissue updates at a blistering rate!

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

No, It is at least 2.0.10 for attiny.

 

The atmel site you link to only has old versions, there is a new "microchip" site, but it doesn't show up in searches (at least for me):

https://packs.download.microchip.com/

 

Why they wouldn't re-direct the old atmel site to the new microchip site is a mystery.

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

https://packs.download.microchip.com/
has device packs for MPLAB OR AS7 ?

Last Edited: Sun. Aug 4, 2019 - 02:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would assume both??  In any event they are the latest packs and have updates over the last release under Atmels name.

 

 

Last Edited: Wed. Aug 7, 2019 - 11:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At least MPLAB X v5.00 and subsequent; v2 packs and v1 packs appear to be available.

Device Pack Frequently Asked Questions - Developer Help

...

 

How does a developer load and manage DFP revisions?

https://microchipdeveloper.com/mplabx:dfp-faqs#toc6

  • The developer needs to note the compiler, IDE, and DFP versions used in a project.
  • User-installed DFPs are in the user directory, IDE-installed (default) DFPs are part of the IDE directory.
  • Select Tools->Packs to install a specific DFP version as needed.
  • https://packs.download.microchip.com and http://packs.download.atmel.com contain all historical packs for downloading outside of the IDE.

 

...

 

"Dare to be naïve." - Buckminster Fuller