Using avr-gcc to compile for ATtiny4

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

I am trying to compile code for ATtiny4 from the command line as follows.

 

/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-gcc -mmcu=attiny4 -Os -o ~/Documents/ATtiny4/ATtiny4 ~/Documents/ATtiny4/ATtiny4.c

 

And I get the error 'Assembler messages: Fatal error: unknown MCU: avrtiny'

 

I can see the following lines in in avr/io.h
#elif defined (__AVR_ATtiny4__)
#  include <avr/iotn4.h>

 

So, I'm lost about what the problem might be. And attiny4 is listed as a supported microcontroller.

 

The code ATtiny4.c is just for a basic blinking LED.

 

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
    DDRB |= 1 << DDB1;
    
    while( 1)
    {
        PORTB ^= 1 << PORTB1;
        _delay_ms(1000);
    }
    return 0;
}

 

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

I just plugged your code into a Tiny4 new Studio project and it complied ok. Hex file attached for you to test.

 

Attachment(s): 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Tue. Dec 13, 2016 - 07:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

So the question arises as to which version of avr-gcc (and avr-libc) you are using? Tiny4/5/9/10 support was a fairly recent addition (like the last 2 years or something?). Also if you are on Linux (and your path characters suggest you are) and are using an avr-gcc/avr-libc from the Linux distro repo it may be that is a generic FSF build not the Atmel branch and support for "new" micros like tiny4/5/9/10 in "generic" lags the Atmel build by a year or two also.

 

For an easy life just pick up the .tar.gz here:

 

http://www.atmel.com/tools/atmel...

 

If that fails to support tiny4 I would be very surprised!

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

Thank you John Samperi and clawson.

 

The problem was my outdated toolchain. I'm on a Mac, and was relying on the toolchain that came with the Arduino IDE. The avr-gcc version was 4.9.2.

 

I followed the instructions here, and now the avr-gcc version is 6.2.0, and things are working as expected.

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

avr-gcc 4.9.2 is actually quite a modern one. Certainly the 4.8.2 and 4.9.2 from Atmel would have tiny 4 support. So I guess your one must have been built out of the GNU generic code tree.

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

By the way this is start of the map file for the build

c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.9.2/avrtiny\libgcc.a(_exit.o)
                              C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.1.102/gcc/dev/attiny4/avrtiny/crtattiny4.o (exit)

it is 4.9.2 like the one you have, maybe you had an older part pack.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I just downloaded the latest Arduino release 1.6.13 for the Mac. It also has the 4.9.2 avr-gcc version. And it still has the issue with compiling for ATtiny4. So it appears that the deficiency is in the Arduino toolchain. And it does not matter for them, because they do not have any boards that use this microcontroller.

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

tiny4 is a part of architecture avrtiny in AVR GCC 5.

https://www.avrfreaks.net/forum/new-chips-attiny102-attiny104#comment-1942921

 

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