Compiling for Attiny5 (Or any of the 4, 5, 9, 10, 20 and 40 family) in the native framework

I’m trying to build an Attiny5 program from PlatformIO in VSCode under Windows. To do so this is what I’ve tried:

I created a board in “%userprofile%.platformio\boards\atTiny5.json” with the contents:

{
    "build": {
        "f_cpu": "1000000L",
        "mcu": "attiny5"
    },
    "name": "ATtiny5",
    "upload": {
        "maximum_ram_size": 32,
        "maximum_size": 512
    },
    "url": "http://www.atmel.com/devices/ATTINY5",
    "vendor": "Atmel"
}

With this I had a compiler error that “crtattiny5.o” was not found. I noticed the file was at “%userprofile%.platformio\packages\toolchain-atmelavr\avr\lib\avrtiny” so I tried copying it to the parent folder, and it worked! (looks like a bug IMO)

But now there’s another error while linking:

%userprofile%/.platformio/packages/toolchain-atmelavr/bin/…/lib/gcc/avr/7.3.0/…/…/…/…/avr/bin/ld.exe: skipping incompatible %userprofile%/.platformio/packages/toolchain-atmelavr/bin/…/lib/gcc/avr/7.3.0/…/…/…/…/avr/lib\libm.a when searching for -lm
%userprofile%/.platformio/packages/toolchain-atmelavr/bin/…/lib/gcc/avr/7.3.0/…/…/…/…/avr/bin/ld.exe: cannot find -lm

Is there any way to solve this?

I can compile the code using the console (and avr-gcc) just fine so I’m thinking that maybe it would be faster to make PlatformIO call a .bat or an app made by me instead. Could that be possible?

Also noted in https://groups.google.com/a/arduino.cc/g/developers/c/Ny82s7t11Vc and c++ - Programming ATtiny10 with Arduino ( "ld.exe" errors) - Stack Overflow and arduino uno - Cannot find crtatmega328p - Arduino Stack Exchange.

If I just take a simple main.cpp

#include <avr/io.h>

int main() {
    return 0;
}

and run

C:\Users<user>.platformio\packages\toolchain-atmelavr@1.70300.191015\bin\avr-g++ -mmcu=atmega328p main.cpp

On it, it works. Also works with -mmcu=attiny85.

But with -mmcu=attiny5 (which is correct per docs it gives

avr-g++ -mmcu=attiny5 main.cpp
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: skipping incompatible c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0\libgcc.a when searching for -lgcc
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: cannot find -lgcc
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: skipping incompatible c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/lib\libm.a when searching for -lm
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: cannot find -lm
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: skipping incompatible c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0\libgcc.a when searching for -lgcc
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: cannot find -lgcc
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: skipping incompatible c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/lib\libm.a when searching for -lm
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: cannot find -lm
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: skipping incompatible c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/lib\libc.a when searching for -lc
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: cannot find -lc
c:/users/max/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: cannot find -lattiny5
collect2.exe: error: ld returned 1 exit status

There is also a avr-libc note about it

https://nongnu.org/avr-libc/user-manual/FAQ.html#faq_tinyavr_c

So maybe it’s really not supported, or avr-gcc has a bug where it can’t find its own internal libraries. Were you ever able to compile a C/C++ program for the Attiny5 with avr-gcc?

Maybe try asking in the avr-gcc mailing list why this doesn’t work or to confirm it.

Oh the topic ATTiny10 and Toolchain 7.3.0 · Issue #65 · arduino/toolchain-avr · GitHub seems interesting. I’ll try this toolchain.

It is 100% a toolchain bug in 7.3.0.

Rolling back to 5.4.0 solves the problem.

Add

platform_packages = 
    toolchain-atmelavr@~1.50400.0

to the bottom of the platformio.ini and retry. Also see docs and available versions.

Processing attiny5 (platform: atmelavr; board: attiny5)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny5.html
PLATFORM: Atmel AVR (3.2.0) > ATtiny5       
HARDWARE: ATTINY5 1MHz, 32B RAM, 512B Flash 
PACKAGES:
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\attiny5\src\main.o
Linking .pio\build\attiny5\firmware.elf
Building .pio\build\attiny5\firmware.hex
Checking size .pio\build\attiny5\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 0 bytes from 32 bytes)
Flash: [=         ]   9.8% (used 50 bytes from 512 bytes)
==================== [SUCCESS] Took 1.53 seconds ====================

Yep! It works!
I was just about to replace the toolchain executables in platformio. Your solution is undoubtedly the best.
Thanks a lot!!

1 Like