Workaround for AVRxxDDxx (dxcore outdated)

I’m posting this work-around for the outdated dxcore that currently comes with platformIO for AVR-DD, since errors/documentation were slightly unhelpful. Please comment if you’ve found a better way.

Problem: I want to compile code for an avr64dd28 on PlatformIO. It works on the Arduino IDE, but fails on PlatformIO.

Diagnosis: PlatformIO pulls in atmelmegaavr 1.7.0 (published a month ago on PlatformIO), which pulls in dxcore 1.4.10 (published almost a year ago on PlatformIO), but needs dxcore 1.5.6 (available on github and used by Arduino IDE, but not available on PlatformIO).

Workaround: (1) fork dxcore on github, (2) add package.json to the megaavr subdirectory of DxCore, (3)adjust the version number in package.json, (4) set platform_packages in your project’s platformio.ini. See below.

Attempt 1 (failed): Use platform_packages in platformio.ini
platform_packages = platformio/framework-arduino-megaavr-dxcore@1.5.6

Result: Error: Could not find the package with ‘platformio/framework-arduino-megaavr-dxcore @ 1.5.6’ requirements for your system ‘windows_amd64’
(Does not work because only 1.4.5 and 1.4.10 are available via PlatformIO.)

Attempt 2 (failed): Use platform_packages to pull from git.
platform_packages = framework-arduino-megaavr-dxcore @ https://github.com/SpenceKonde/DxCore.git

Result: Error: Could not find one of ‘package.json’ manifest files in the package.
(A quick comparison of …/.platformio/packages/framework-arduino-megaavr-dxcore and a corresponding git pull of 1.4.10 shows indeed that there is a package.json and .piopm and a few other files of lesser relevance missing.)

Attempt 3 (failed): Fork DxCore on github, add package.json to its root, and point platform_package to the fork.
platform_packages = framework-arduino-megaavr-dxcore @ https://github.com/fredrikvang/DxCore.git@1.5.6
Copied package.json from …/.platformio/packages/framework-arduino-megaavr-dxcore into the github repo, and changed to “version”: “1.5.6”.

Result: Could not build my files because #include <Arduino.h> failed with file not found. (The problem seemed to be that the include path was slightly wrong.)

Attempt 4: As above, but add package.json to the megaavr subdirectory of DxCore instead.

Success!