Adding a new board from Arduino IDE to PlatformIO

Hey there. Apologies in advance, as I know this topic has been discussed before, but I’ve hit a bit of a brick wall in following the guides linked in the other threads.

The thread above details adding a new board to platformio, however, it seems that this board has an existing svd file. I’m trying to add support for the CANFDuino, which uses the ATSAM series of micros. This particular variant I have uses the ATSAMC21G17A, which it seems there is not an SVD file for. The closest I could find in the atmelsam/misc/svd directory is the ATSAMC21J18A.

The C21J and C21G have numerous differences, and I’m a bit out of my element here. The vendor (Togglebit) supplies a driver package for Arduino IDE which, in combination with the “Atmel SAMD Boards” package allows for writing to the device with Arduino IDE. They also package some libraries for utilizing the onboard CANFD controllers.

Is there any quick and easy way to port the arduino libraries over to platformio?

Here is the “getting started” page for the CANFDuino, which links to the driver packages:

That’s not just “adding a board”, that’s “adding a whole forked Arduino core with supporting packages and a board definition”.

You will need advanced PlatformIO knowledge if you want to do this yourself, regarding platform-atmelsam code, PlatformIO packages (package.json, platform.json), compiler settings, etc.

Recommended reading is also Arduino Due (or other SAM3/4) upload fails with ATMEL ICE JTAG on VSCode with PlatformIO - #8 by maxgerhardt.

I recently wrote the repo GitHub - maxgerhardt/pio-samd51n19-test that adds support for a not-yet supported chip type, you can see some things regarding board JSON files there.

More concretely, you will need to modify or add a framework-arduino-samd-XYZ (with XYZ e.g. naming canfduino packages, also a framework-cmsis-atmel-canfduino (since they have their own special) packages, reference those in the platform.json and in the platform’s python code, and in your board file reference those forked cores.

So basically what I did with Add 5G-NB-IoT Board + Arduino Core Support by maxgerhardt · Pull Request #187 · platformio/platform-atmelsam · GitHub for a different board.

Bummer. That sounds like a tremendous amount of work. Thanks for the response. I suppose I’ll delve into that when I can. I can’t really get anything worthwhile done in the arduino IDE.

That’s like a 10 minute job for me, I’ll do it this evening.

Oh wow, okay, thank you. I’ll have to study your work afterwards to see how it’s done. I’d love to know how all this works.

Please download + test

(You will need Git installed globally if not already installed.)

Dont’t forget to chose the right board in the project environment switcher.

Wow, thank you so much, I’ll test in a couple hours when I’m at my desk!

Works like a charm! I can’t thank you enough!

Awesome! Can you please check the following things though:

In the platformio.ini, there’s the line

which is to inject the bossac.exe version that is found in the CANFduino repo as the used bossac.exe upload. That is however Windows only and would not permit usage on Linux or Mac. PlatformIO however has bossac in quite a few different versions and for a lot more OSes.

Can you please try these lines instead and report back which work and which don’t?

platform_packages = tool-bossac@1.10700.190624
platform_packages = tool-bossac@1.10900.0
platform_packages = tool-bossac@1.10601.0

Sure thing! I do also have linux and mac machines to test on if need be.

1.10700.190624 - fails No device found on COM15 *** [upload] Error 1

1.10900.0 - fails bossac: extra arguments found Try 'bossac -h' or 'bossac --help' for more information *** [upload] Error 1

1.10601.0 - fails No device found on COM15 *** [upload] Error 1

Hm, so none of the PlatformIO provided versions work.

Can you download + extract https://www.mattairtech.com/software/arduino/bossac-1.7.0-mattairtech-3-mingw32-64.tar.gz (e.g. using 7zip), revert to

platform_packages = tool-bossac@symlink://canfd_bossac

and use the bossac.exe from the downloaded archive to replace the one in canfd_bossac?

If that doesn’t work you can redownload the working bossac from the repo at any time.

Yep, worked with that version. I tried the 64 bit version as well, that also worked.

Great. Then I’ll later submit the Win + Lin + Mac packages to the PIO registry from the mattairtech binaries and then it should work for all OSes.

Fantastic, can’t thank you enough!

Hi @maxgerhardt, i think that I am in a similar situation as @devin since i have a " a whole forked Arduino core with supporting packages and a board definition”. I am also very much out of my depth with implementing this within platformio.

So I am hoping that you could grace me with your help!

My microcontroller is one of the esp32 PLCs made by industrialshields, specifically the ESP32 PLC 19R

I have made a github repo with the contents of the .arduino15 folder that seems to contain the same directories as your framework-arduino-samd-5gnbiot, so hopefully this will help a bunch.

framework-arduino-esp32-industrialshields

If you consider helping me, let me know if I can help you anyway along the way!

Did you actually modify files in core/ compared to a vanilla Arduino-ESP32 core or is just the addition of a new board variant to the core?

so the files in the repo are direct copies of the ones that get downloaded by arduino IDE using the custom url provided by industrialshields.

Looking at the files it seems that there are some changes/additions made eg /hardware/esp32/2.1.2/cores/industrialshields/expanded-gpio.c, so that seems to suggest that files have been changed/added in core?

If core files were modified (but I hope they kept tools/platformio-build*.py) but the build logic itself hasn’t changed then you could just use platform_packages to inject the IndustrialShields version of Arduino-ESP32 and add boards/their_new_board.json files for the board definition.

Can you open a new topic about creating IndustrialShields support?

Sure! I have opened a new topic here