Missing device specs for AVR Dx parts

I’m trying to compile the native-blink demo for the avr128db28 on the atmelmegaavr platform, but I am getting an error about missing device specs.

I have the following packages installed:

Resolving AVR128DB28 dependencies...
Platform atmelmegaavr @ 1.9.0 (required: atmelmegaavr)
├── framework-arduino-megaavr-dxcore @ 1.5.6 (required: framework-arduino-megaavr-dxcore @ ~1.5.6)
└── toolchain-atmelavr @ 1.70300.191015 (required: platformio/toolchain-atmelavr @ ~1.70300.0)

Here is the contents of my platformio.ini:

[env:AVR128DB28]
platform = atmelmegaavr
;framework = arduino
board = AVR128DB28
upload_speed = 115200
upload_flags = 
	--tool
	uart
	--device
	avr128db28
	--uart
	$UPLOAD_PORT
	--clk
	$UPLOAD_SPEED
upload_command = pymcuprog write --erase $UPLOAD_FLAGS --filename $SOURCE

The error I get is as follows:

Compiling .pio\build\AVR128DB28\src\main.o
avr-gcc: error: device-specs/specs-avr128db28: No such file or directory
*** [.pio\build\AVR128DB28\src\main.o] Error 1

If I uncomment the framework = arduino option, it will compile successfully; however, I don’t want to do that, because if I do, it compiles the Arduino framework every time in addition to my own code, even though I’m not using it.

If I look in the .platformio\packages directory, I have toolchain-atmelavr and toolchain-atmelavr@1.70300.191015 directories. If I navigate to the lib\gcc\avr\7.3.0\device-specs subdirectory beneath each of those package directories, the toolchain-atmelavr directory has the spec files for the avr Dx parts, but the toolchain-atmelavr@1.70300.191015 directory doesn’t.

I was able to get past the spec error by copying all the missing spec files to the toolchain-atmelavr@1.70300.191015, but then it complains about missing includes:

Compiling .pio\build\AVR128DB28\src\main.o
In file included from src\main.c:6:0:
c:\users\jblan\.platformio\packages\toolchain-atmelavr@1.70300.191015\avr\include\avr\io.h:695:33: fatal error: avr/ioavr128db28.h: No such file or directory
 #  define __AVR_DEVICE_HEADER__ <avr/__header1__(io,__AVR_DEV_LIB_NAME__).h>
                                 ^
compilation terminated.
*** [.pio\build\AVR128DB28\src\main.o] Error 1

Then if I copy all the missing include files, it complains about missing libraries:

c:/users/jblan/.platformio/packages/toolchain-atmelavr@1.70300.191015/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: cannot find crtavr128db28.o: No such file or directory
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\AVR128DB28\firmware.elf] Error 1

If I copy all the missing libraries, then it finally compiles successfully without using the arduino library.

I understand that gcc doesn’t include these files by default, but if platformio claims to support native development on these chips, shouldn’t these files be included in the toolchain-atmelavr package you distribute, so it just works out of the box?

I’m new to platformio so I’m not sure where I should file a bug for this. I found the package on the registry but it didn’t have an obvious link to a github repo or bug tracker.

What does the package.json of this folder say the version is?

{
  "name": "toolchain-atmelavr",
  "version": "3.70300.220127",
  "description": "GCC Toolchain for Microchip AVR microcontrollers",
  "keywords": [
    "toolchain",
    "build tools",
    "compiler",
    "assembler",
    "linker",
    "preprocessor",
    "microchip",
    "avr"
  ],
  "homepage": "https://gcc.gnu.org/wiki/avr-gcc",
  "license": "GPL-2.0-or-later",
  "system": [
    "windows",
    "windows_amd64",
    "windows_x86"
  ]
}

OK, after noticing that the newer version 3.70300.220127 was the one that had the files, I did some more testing. Each time, I closed VS Code, removed my entire .platformio directory, and then let it install what it wanted to based on the contents of my platformio.ini. Here is what I found:

If I have framework = arduino in my platformio.ini file when I reopen VS Code, it installs both versions of GCC, and only seems to use the new one if I have framework = arduino enabled. If I comment it out, then it seems to want to use the old version of gcc that doesn’t have the necessary files.

If I do NOT have framework = arduino in my platformio.ini file when I reopen, it just installs the new one, and compiling without framework = arduino works fine. I can then add framework = arduino to the file and it will install dxcore, but does not install the old version of gcc. If I then comment out framework = arduino again, it still works fine.

So the issue seems to be that it is installing an old version of gcc if I have framework = arduino enabled the first time I open the project, but if I don’t, then it installs the new version and everything is fine.

Oops, I was wrong about the second case. It installs the old version of GCC by default regardless of whether I have framework = arduino enabled or not, and if the old version is installed, it defaults to using that unless I have framework = arduino enabled. But I was able to fix that by adding this to platformio.ini:

platform_packages = platformio/toolchain-atmelavr@^3.70300.220127

Sorry for the confusion, I was trying a bunch of things and I lost track of what I did when.

Anyway, I have a decent workaround now, but why is it defaulting to installing the old version to begin with?

To be 100% clear, this is the complete platformio.ini that works for me:

[env:AVR128DB28]
platform = atmelmegaavr
platform_packages = platformio/toolchain-atmelavr@^3.70300.220127
board = AVR128DB28
upload_speed = 115200
upload_flags = 
	--tool
	uart
	--device
	avr128db28
	--uart
	$UPLOAD_PORT
	--clk
	$UPLOAD_SPEED
upload_command = pymcuprog write --erase $UPLOAD_FLAGS --filename $SOURCE

Without specifying the new compiler explicitly via platform_packages, it will try to use the old compiler that doesn’t have support files for the Dx chips.

1 Like

FYI, I have opened issue #66 on the platform-atmelmegaavr github repo. Hopefully this is the right place to do so…

1 Like