How do you start a new project using a custom board?

When I start a project using the wizard it insists on a board, but I’m trying to set up a custom board so it’s not in the list. Should I just pick one at random and then configure things myself? My custom board is based on a SAME53N19A chip.

https://github.com/platformio/platform-atmelsam does currently not support any SAME53N19A based board. Also see https://github.com/platformio/platformio-core/issues/4609 and https://github.com/platformio/platform-atmelsam/issues/175.

Is your intention to run an Arduino core on this board?

Yes, I’d like to run Arduino Core. Is it possible to define a custom board to get a SAME53 working?

Possible: Yes. Will it be a lot more work: Yes.

The problem is not that you just have to create a board definition using JSON. PlatformIO also doesn’t yet support the Arduino core you need for a SAME53N19A, that is this one

There is also https://github.com/Longan-Labs/ArduinoCore-same but this seems outdated and incomplete.

All of the other “Atmel SAMx” cores are either SAMD21 / SAM51 (arduino/ArduinoCore-samd, adafruit/ArduinoCore-samd) or SAML21B (https://github.com/kumajaya/IndustruinoSAMx) or SAM3XE

PlatformIO needs to have a builder script (written in Python, see e.g. here, that explains how to build a specifc Arduino core to PlatformIO (compiler settings, linker settings, preprocessing and postprocessing steps etc.). It’s basically a mirror of the platform.txt and boards.txt.

Do you have that SAME53N19A right now? Are you planing to flash it via SWD or bossac or how?

Would a SAME51 be close to a SAME53, enough to use as a starting point?

I’d prefer to flash it with bossac using a uf2 bootloader.

Well you can using the adafruit_feather_m4(_can) verbatim or editing that macro and see if you can a simple blinky running at all. Same for Teknik core: Just try it out without PlatformIO (bootloader is prebuilt i nhttps://github.com/Teknic-Inc/ClearCore-Arduino-wrapper/tree/master/bootloader), you just need to put

https://raw.githubusercontent.com/Teknic-Inc/ClearCore-Arduino-wrapper/master/package_clearcore_index.json

into File → Settings → Addition URLs of your Arduino IDE, then you can install their core.

If any of that works, you can think about using PlatformIO (which needs expansion of varying degrees depending on which board / core worked).

The Arduino IDE works. PlatformIO will flash the board with the adafruit_feather_m4_can.json board definition but it seems to crash and can’t reflash without double-clicking the reset button to enter the bootloader.

After copying the adafruit_feather_m4_can.json file into the core_dir/boards (~/.platformio/boards in my case) and I start a new project it seems like something is misconfigured since it shows up as a SAM, ESP32, and a Teensy.

the system view description file for the chip is here: https://github.com/Microchip-MPLAB-Harmony/dev_packs/blob/master/Microchip/SAME53_DFP/3.7.228/svd/ATSAME53J19A.svd

With which core and Arduino IDE → Tools settings is that? Did you modify anything in the core files for that?

In Arduino after adding the board url in preferences (https://www.teknic.com/files/downloads/package_clearcore_index.json) and installing the ClearCore package in Boards Manager I selected the Teknic ClearCore in Tools → Board.

I’ve gotten a bit further in platformio, but I’m still stuck with an error.

I copied over the arduino package into /home/patrick/.platformio/packages/framework-arduino-samd-clearcore

and updated /home/patrick/.platformio/platforms/atmelsam/platform.json with

    "framework-arduino-samd-clearcore": {
      "type": "framework",
      "optional": true,
      "owner": "platformio",
      "version": "~1.1.2"
    },

I also had to add a package.json file into the framework-arduino-samd-clearcore folder:

{
  "name": "framework-arduino-samd-clearcore",
  "version": "1.1.2",
  "description": "Arduino Wiring-based Framework for Microchip SAM D microcontrollers (ClearCore SAMD Core)",
  "keywords": [
    "framework",
    "arduino",
    "microchip",
    "samd"
  ],
  "license": "LGPL-2.1-or-later",
  "repository": {
    "type": "git",
    "url": "https://github.com/Teknic-Inc/ClearCore-Arduino-wrapper"
  }
}

This is the clearcore.json file I made

{
    "build": {
        "arduino": {
            "ldscript": "flash_with_bootloader.ld",
            "_ldscript_comment": "looks for {ldscript} in the core directory under variants/{variant}/linker_scripts/gcc/{ldscript}"
        },
        "core": "clearcore",
        "_core_comment": "looks for .platformio/packages/framework-arduino-samd-{core}",
        "cpu": "cortex-m4",
        "_cpu_comment": "sets arm-none-eabi-g++ -mcpu target",
        "extra_flags": [
            "-D__SAME53N19A__",
            "-D__SAMD53__",
            "-DARDUINO_ARM_ClearCore",
            "-DARDUINO_ARCH_SAM",
            "-D__ARM_FEATURE_DSP=1",
            "-D__FPU_PRESENT",
            "-DARM_MATH_CM4",
            "-DENABLE_CACHE",
            "-DVARIANT_QSPI_BAUD_DEFAULT=50000000"
        ],
        "f_cpu": "120000000L",
        "_f_cpu_comment": "indicates the clock frequency 120 MHz in this case. sets arm-none-eabi-g++ -DF_CPU {f_cpu}",
        "hwids": [
            [
                "0x2890",
                "0x0022"
            ]
        ],
        "_hwi_comment": "matches devices with the given VID/PID shown using lsusb: Bus 003 Device 044: ID 2890:0022 Teknic, Inc ClearCore",
        "mcu": "same53n19a",
        "_mcu_comment": "will prevent uploads if set incorrectly, not sure where it is explicitly used",
        "system": "samd",
        "_system_comment": "looks for .platformio/platforms/atmelsam/builder/frameworks/arduino/arduino-{system}.py",
        "usb_product": "Teknic ClearCore",
        "_usb_product_comment": "seems to have no effect",
        "variant": "clearcore",
        "_variant_comment": "looks for .platformio/packages/framework-arduino-samd-{core}/variants/{variant}"
    },
    "debug": {
        "jlink_device": "ATSAME53N19A",
        "openocd_chipname": "at91same53n19",
        "openocd_target": "atsame5x",
        "svd_path": "ATSAME53N19A.svd"
    },
    "frameworks": [
        "arduino"
    ],
    "_frameworks_comment": "declares which framework the device supports. not sure where it is explicitly used",
    "name": "ClearCore",
    "upload": {
        "disable_flushing": true,
        "maximum_ram_size": 196608,
        "maximum_size": 507904,
        "native_usb": true,
        "offset_address": "0x4000",
        "protocol": "sam-ba",
        "protocols": [
            "sam-ba",
            "jlink",
            "atmel-ice"
        ],
        "require_upload_port": true,
        "use_1200bps_touch": true,
        "wait_for_upload_port": true
    },
    "url": "https://www.teknic.com",
    "vendor": "Teknic"
}

and the platformio.ini needed some additional build flags. I copied these from the verbose output of the Arduino IDE compiler output.

[env:clearcore]
platform = atmelsam
board = clearcore
framework = arduino
build_flags = 
    -I /home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/variants/clearcore/ThirdParty/SAME53/CMSIS/Device/Include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/cores/arduino/api
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/cores/arduino
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/variants/clearcore
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/LwIP/LwIP/port/include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/LwIP/LwIP/src/include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/libClearCore/inc

I had to rename the “variants/clearcore/Third Party” folder in the source package to remove the space “variants/cleacore/ThirdParty” because was causing issues finding includes.

now when I compile it has this error:

/home/patrick/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol Reset_Handler; defaulting to 0000000000004000
.pio/build/clearcore/libFrameworkArduino.a(startup_same53.c.o):(.vectors+0x4): undefined reference to `Reset_Handler'
.pio/build/clearcore/libFrameworkArduino.a(main.cpp.o): In function `SysTick_Handler':
main.cpp:(.text.SysTick_Handler+0x4): undefined reference to `ClearCore::SysManager::SysTickUpdate()'
main.cpp:(.text.SysTick_Handler+0x18): undefined reference to `ClearCore::SysMgr'
collect2: error: ld returned 1 exit status
*** [.pio/build/clearcore/firmware.elf] Error 1

I’m thinking SAME53 support is missing somewhere, but not sure where to add it yet. Any ideas?

The remaining undefined references are because you’re not linking in a special precompiled library file (.a)

See

Try adding these 4 flags with the right paths to the build flags

“-L{runtime.platform.path}/Teknic/libClearCore/Release” -lClearCore “-L{runtime.platform.path}/Teknic/LwIP/Release” -lLwI

It compiles now! Thanks

this is the modified ini file.

[env:clearcore]
platform = atmelsam
board = clearcore
framework = arduino
build_flags = 
    -I /home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/variants/clearcore/ThirdParty/SAME53/CMSIS/Device/Include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/cores/arduino/api
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/cores/arduino
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/variants/clearcore
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/LwIP/LwIP/port/include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/LwIP/LwIP/src/include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/libClearCore/inc
    -L /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/libClearCore/Release
    -l ClearCore
    -L /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/LwIP/Release
    -l LwIP
    -L /home/patrick/.platformio/packages/framework-cmsis/CMSIS/Lib/GCC
    -l arm_cortexM4lf_math

But it’s having trouble uploading. It seems to be forcing the reset as a blinking LED stops but then can’t continue.

Uploading works when starting a new project as a SAME51

[env:adafruit_feather_m4_can]
platform = atmelsam
board = adafruit_feather_m4_can
framework = arduino

The upload portion between the adafruit_feather_m4_can.json and my custom clearcore.json is identical:

  "upload": {
    "disable_flushing": true,
    "maximum_ram_size": 196608,
    "maximum_size": 507904,
    "native_usb": true,
    "offset_address": "0x4000",
    "protocol": "sam-ba",
    "protocols": [
      "sam-ba",
      "jlink",
      "atmel-ice"
    ],
    "require_upload_port": true,
    "use_1200bps_touch": true,
    "wait_for_upload_port": true
  },

are there other places I can look for upload configuration?

What’s the exact error message?

It might be using a different version of the bossac binary (or different paramaters to it). See

The package.json file of that core dictates

              "name": "bossac",
              "version": "1.9.1-arduino1"

which should be also the latest available here: PlatformIO Registry

I would recommend:

  1. In the Arduino IDE, go File → Preferences → enable “Verbose Upload”
  2. Upload in the Arduino IDE
  3. Post the exact bossac.exe invocation
  4. In PlatformIO, use project tasks → Advanced → Verbose Upload
  5. Post invocation and initial “PACKAGES:” list in output
  6. Let’s compare that.

the failed upload output is after running pio run --target upload -v in the custom board project is:

...
PLATFORM: Atmel SAM (8.1.0) > ClearCore
HARDWARE: SAME53N19A 120MHz, 192KB RAM, 496KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, jlink)
PACKAGES: 
 - framework-arduino-samd-clearcore @ 1.1.2 
 - framework-cmsis @ 1.40500.0 (4.5.0) 
 - framework-cmsis-atmel @ 1.2.2 
 - tool-bossac @ 1.10700.190624 (1.7.0) 
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)

...

CURRENT: upload_protocol = sam-ba

BeforeUpload(["upload"], [".pio/build/clearcore/firmware.bin"])
Warning! Please install `99-platformio-udev.rules`. 
More details: https://docs.platformio.org/en/latest/core/installation/udev-rules.html

Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
bossac --info --debug --port "ttyACM0" --write --verify --reset --erase -U true .pio/build/clearcore/firmware.bin
Set binary mode
readWord(addr=0)=0x2000e430
readWord(addr=0xe000ed00)=0x410fc241
Send auto-baud
Set binary mode
No device found on ttyACM0
*** [upload] Error 1

using a new project with the adafruit m4 can (SAME51) board it uploads and the output is:

...
PLATFORM: Atmel SAM (8.1.0) > Adafruit Feather M4 CAN
HARDWARE: SAME51J19A 120MHz, 192KB RAM, 496KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, jlink)
PACKAGES: 
 - framework-arduino-samd-adafruit @ 1.7.10 
 - framework-cmsis @ 2.50400.181126 (5.4.0) 
 - framework-cmsis-atmel @ 1.2.2 
 - tool-bossac @ 1.10900.0 (1.9.0) 
 - toolchain-gccarmnoneeabi @ 1.90301.200702 (9.3.1)

...
CURRENT: upload_protocol = sam-ba
BeforeUpload(["upload"], [".pio/build/adafruit_feather_m4_can/firmware.bin"])

Warning! Please install `99-platformio-udev.rules`. 
More details: https://docs.platformio.org/en/latest/core/installation/udev-rules.html

TimeoutError: Could not automatically find serial port for the `Adafruit Feather M4 CAN` board based on the declared HWIDs=['239A:80CD', '239A:00CD']
Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
bossac --info --debug --port "ttyACM0" --write --verify --reset -U --offset 0x4000 .pio/build/adafruit_feather_m4_can/firmware.bin
Set binary mode
version()=v1.1 [Arduino:XYZ] Sep 14 2020 14:10:57
Connected at 921600 baud
...

The Arduino IDE output when uploading is:

/home/patrick/Apps/arduino-1.8.19/arduino-builder -dump-prefs -logger=machine -hardware /home/patrick/Apps/arduino-1.8.19/hardware -hardware /home/patrick/.arduino15/packages -tools /home/patrick/Apps/arduino-1.8.19/tools-builder -tools /home/patrick/Apps/arduino-1.8.19/hardware/tools/avr -tools /home/patrick/.arduino15/packages -built-in-libraries /home/patrick/Apps/arduino-1.8.19/libraries -libraries /home/patrick/Arduino/libraries -fqbn=ClearCore:sam:clearcore -vid-pid=2890_0022 -ide-version=10819 -build-path /tmp/arduino_build_480600 -warnings=all -build-cache /tmp/arduino_cache_421006 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.CMSIS.path=/home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0 -prefs=runtime.tools.CMSIS-4.5.0.path=/home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0 -prefs=runtime.tools.arm-none-eabi-gcc.path=/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4 -prefs=runtime.tools.arm-none-eabi-gcc-7-2017q4.path=/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4 -prefs=runtime.tools.bossac.path=/home/patrick/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino1 -prefs=runtime.tools.bossac-1.9.1-arduino1.path=/home/patrick/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino1 -verbose /home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/libraries/DigitalIO/ReadDigitalInput/ReadDigitalInput.ino
/home/patrick/Apps/arduino-1.8.19/arduino-builder -compile -logger=machine -hardware /home/patrick/Apps/arduino-1.8.19/hardware -hardware /home/patrick/.arduino15/packages -tools /home/patrick/Apps/arduino-1.8.19/tools-builder -tools /home/patrick/Apps/arduino-1.8.19/hardware/tools/avr -tools /home/patrick/.arduino15/packages -built-in-libraries /home/patrick/Apps/arduino-1.8.19/libraries -libraries /home/patrick/Arduino/libraries -fqbn=ClearCore:sam:clearcore -vid-pid=2890_0022 -ide-version=10819 -build-path /tmp/arduino_build_480600 -warnings=all -build-cache /tmp/arduino_cache_421006 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.CMSIS.path=/home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0 -prefs=runtime.tools.CMSIS-4.5.0.path=/home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0 -prefs=runtime.tools.arm-none-eabi-gcc.path=/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4 -prefs=runtime.tools.arm-none-eabi-gcc-7-2017q4.path=/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4 -prefs=runtime.tools.bossac.path=/home/patrick/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino1 -prefs=runtime.tools.bossac-1.9.1-arduino1.path=/home/patrick/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino1 -verbose /home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/libraries/DigitalIO/ReadDigitalInput/ReadDigitalInput.ino
Using board 'clearcore' from platform in folder: /home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2
Using core 'arduino' from platform in folder: /home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2
Detecting libraries used...
/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -c -g -O3 -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=120000000L -D__FPU_PRESENT=1 -DARDUINO=10819 -DARDUINO_ARM_ClearCore -DARDUINO_ARCH_SAM -D__ARM_FEATURE_DSP=1 -DCPPUTEST_USE_MEM_LEAK_DETECTION=0 -DUSB_VID=0x2890 -DUSB_PID=0x0022 "-DUSB_MANUFACTURER=\"Teknic, Inc.\"" "-DUSB_PRODUCT=\"Teknic ClearCore\"" -lc -DDEBUG -DUSBCON -DUSB_CONFIG_POWER=0 -D__CLEARCORE__ -D__SAME53N19A__ -DARM_MATH_CM4 -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/cores/arduino/api -I/home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ "-I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/variants/clearcore/Third Party/SAME53/CMSIS/Device/Include" -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/libClearCore/inc -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/LwIP/LwIP/src/include -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/LwIP/LwIP/port/include -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/cores/arduino -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/variants/clearcore /tmp/arduino_build_480600/sketch/ReadDigitalInput.ino.cpp -o /dev/null
Generating function prototypes...
/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -c -g -O3 -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=120000000L -D__FPU_PRESENT=1 -DARDUINO=10819 -DARDUINO_ARM_ClearCore -DARDUINO_ARCH_SAM -D__ARM_FEATURE_DSP=1 -DCPPUTEST_USE_MEM_LEAK_DETECTION=0 -DUSB_VID=0x2890 -DUSB_PID=0x0022 "-DUSB_MANUFACTURER=\"Teknic, Inc.\"" "-DUSB_PRODUCT=\"Teknic ClearCore\"" -lc -DDEBUG -DUSBCON -DUSB_CONFIG_POWER=0 -D__CLEARCORE__ -D__SAME53N19A__ -DARM_MATH_CM4 -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/cores/arduino/api -I/home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ "-I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/variants/clearcore/Third Party/SAME53/CMSIS/Device/Include" -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/libClearCore/inc -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/LwIP/LwIP/src/include -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/LwIP/LwIP/port/include -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/cores/arduino -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/variants/clearcore /tmp/arduino_build_480600/sketch/ReadDigitalInput.ino.cpp -o /tmp/arduino_build_480600/preproc/ctags_target_for_gcc_minus_e.cpp
/home/patrick/Apps/arduino-1.8.19/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_480600/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -c -g -O3 -Wall -Wextra -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=120000000L -D__FPU_PRESENT=1 -DARDUINO=10819 -DARDUINO_ARM_ClearCore -DARDUINO_ARCH_SAM -D__ARM_FEATURE_DSP=1 -DCPPUTEST_USE_MEM_LEAK_DETECTION=0 -DUSB_VID=0x2890 -DUSB_PID=0x0022 "-DUSB_MANUFACTURER=\"Teknic, Inc.\"" "-DUSB_PRODUCT=\"Teknic ClearCore\"" -lc -DDEBUG -DUSBCON -DUSB_CONFIG_POWER=0 -D__CLEARCORE__ -D__SAME53N19A__ -DARM_MATH_CM4 -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/cores/arduino/api -I/home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ "-I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/variants/clearcore/Third Party/SAME53/CMSIS/Device/Include" -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/libClearCore/inc -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/LwIP/LwIP/src/include -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/LwIP/LwIP/port/include -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/cores/arduino -I/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/variants/clearcore /tmp/arduino_build_480600/sketch/ReadDigitalInput.ino.cpp -o /tmp/arduino_build_480600/sketch/ReadDigitalInput.ino.cpp.o
Compiling libraries...
Compiling core...
Using previously compiled file: /tmp/arduino_build_480600/core/variant.cpp.o
Using precompiled core: /tmp/arduino_cache_421006/core/core_ClearCore_sam_clearcore_77c8e367dd842bb8ef51e64e5e0c46a2.a
Linking everything together...
/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -Wl,--gc-sections -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -specs=rdimon.specs -o /tmp/arduino_build_480600/ReadDigitalInput.ino.elf -T/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/variants/clearcore/linker_scripts/gcc/flash_with_bootloader.ld /tmp/arduino_build_480600/sketch/ReadDigitalInput.ino.cpp.o /tmp/arduino_build_480600/core/variant.cpp.o /tmp/arduino_build_480600/../arduino_cache_421006/core/core_ClearCore_sam_clearcore_77c8e367dd842bb8ef51e64e5e0c46a2.a -L/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/libClearCore/Release -lClearCore -L/home/patrick/.arduino15/packages/ClearCore/hardware/sam/1.1.2/Teknic/LwIP/Release -lLwIP -L/home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Lib/GCC/ -larm_cortexM4lf_math -lm -Xlinker -Map=/tmp/arduino_build_480600/ReadDigitalInput.ino.map
/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino_build_480600/ReadDigitalInput.ino.elf /tmp/arduino_build_480600/ReadDigitalInput.ino.eep
/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-objcopy -O binary /tmp/arduino_build_480600/ReadDigitalInput.ino.elf /tmp/arduino_build_480600/ReadDigitalInput.ino.bin
/home/patrick/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-size -A /tmp/arduino_build_480600/ReadDigitalInput.ino.elf
Sketch uses 136528 bytes (26%) of program storage space. Maximum is 507904 bytes.
Global variables use 9212 bytes of dynamic memory.
Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, /dev/ttyS4, } / {/dev/ttyACM0, /dev/ttyS4, } => {}
Uploading using selected port: /dev/ttyACM0
/home/patrick/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino1/bossac -i -d --port=ttyACM0 -U -e -w -v --offset=0x4000 /tmp/arduino_build_480600/ReadDigitalInput.ino.bin -R 
Set binary mode
version()=v1.1 [Arduino:XYZ] Sep 14 2020 14:10:57
Connected at 921600 baud
...
  1. Custom Board Project (ClearCore): tool-bossac @ 1.10700.190624 (1.7.0)
  • Version: 1.7.0
  1. Adafruit M4 CAN (SAME51) Board:tool-bossac @ 1.10900.0 (1.9.0)
  • Version: 1.9.0
  1. Arduino IDE:runtime.tools.bossac-1.9.1-arduino1.path
  • Version: 1.9.1-arduino1

In /home/patrick/.platformio/packages/tool-bossac I have version “1.10900.0” and I have another folder, /home/patrick/.platformio/packages/tool-bossac@1.10700.190624 with the corresponding version inside.

I added this upload command to the platformio.ini file and it works now!

upload_command = /home/patrick/.platformio/packages/tool-bossac/bossac --info --debug --port "ttyACM0" --write --verify --reset -U --offset 0x4000 .pio/build/clearcore/firmware.bin

Now that compiling and uploading is working, what can I do to make things feel less hacky and messy. Ideally I’d like to encapsulate all the boiler plane somewhere so that my platform.ini file looks like

[env:clearcore]
platform = atmelsam
board = clearcore
framework = arduino

And then for the include files to be relative to the platform instead of full paths to my home directory. I guess what I’m asking is how do I share this set up with others?

Thanks again!

Could you add

platform_packages = tool-bossac@~1.10901.0

to the platformio.ini of the custom project and retry?

Otherwise it needs adapations in the platform.py for the version selection of that package.

Basically what you should do is fork the platform-atmelsam repository and adapt the python code (platform.py, arduino-samd.py or whatever builder script is used) and the platform.json to give you the correct build and package settings. You can also add the new board definition in the boards/ folder instead of in .platformio/boards. Then, for distributions, users need only say platform = <your github fork link> and they can use your newly defined boards.

E.g., the uploader version selection code is in

but for your core you need ~1.10901.0.

do you mean like this?

[env:clearcore]
platform = atmelsam
board = clearcore
framework = arduino
build_flags = 
    -I /home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/variants/clearcore/ThirdParty/SAME53/CMSIS/Device/Include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/cores/arduino/api
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/cores/arduino
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/variants/clearcore
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/LwIP/LwIP/port/include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/LwIP/LwIP/src/include
    -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/libClearCore/inc
    -L /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/libClearCore/Release
    -l ClearCore
    -L /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/Teknic/LwIP/Release
    -l LwIP
    -L /home/patrick/.platformio/packages/framework-cmsis/CMSIS/Lib/GCC
    -l arm_cortexM4lf_math
platform_packages = tool-bossac@~1.10901.0

if I remove the upload command it doesn’t work.

Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
Uploading .pio/build/clearcore/firmware.bin
bossac: extra arguments found
Try 'bossac -h' or 'bossac --help' for more information
*** [upload] Error 1

Aww, so now the right uploader package version is used but the arguments are not right. As said in above post, fork and adapt this code block as needed, you know the correct parameters from the Arduino IDE.

thanks, I’ll attempt to make the fork and try to set up a new project using it.

Hi @maxgerhardt, just getting back to this and I’m a bit confused about the process of adding support using a fork.

I forked the original Teknic repo to remove the space in “Third Party” that was causing issues

  • https://github.com/patrickwasp/ClearCore-Arduino-wrapper

I also forked the platform-atmelsam repo and started modifying the files to add support for the clearcore.

  • https://github.com/patrickwasp/platform-atmelsam

And now here starts my confusion.

  1. Do I need to publish the ClearCore-Arduino-wrapper to https://registry.platformio.org/ so that I can reference it in platform-atmelsam? I think I would want it to show up under .platformio/packages/framework-arduino-samd-clearcore just like the others in there.

  2. If I need to publish to the registry, how do I do that? Ideally, I’d like the package to be a mirror of the github repo so that whenever the repo is updated (when a new release is tagged), so is the registry package. Where does the https://registry.platformio.org/tools/platformio/framework-arduino-samd-adafruit package get its source from? The referenced git repo (https://github.com/adafruit/ArduinoCore-samd) doesn’t include any platformio meta data like package.json.

  3. Where do I put additional build flags and specify the upload command? Is it all in the boards json file? How do I specify a relative path to a package, for example -I /home/patrick/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include or -I /home/patrick/.platformio/packages/framework-arduino-samd-clearcore/cores/arduino

  4. Where do I specify the upload command options? Right now this works:

    upload_command = /home/patrick/.platformio/packages/tool-bossac/bossac --info --debug --port “ttyACM0” --write --verify --reset -U --offset 0x4000 .pio/build/clearcore/firmware.bin

I specifically need to use self.packages[“tool-bossac”][“version”] = “~1.10901.0”, which I defined in the modified platform-atmelsam.

This is the platform.ini file I’m using:

[env:clearcore]
platform = https://github.com/patrickwasp/platform-atmelsam
board = clearcore
framework = arduino

When trying to compile it gives an expected error:

Tool Manager: Installing patrickwasp/framework-arduino-samd-clearcore @ ~1.1.2
UnknownPackageError: Could not find the package with 'patrickwasp/framework-arduino-samd-clearcore @ ~1.1.2' requirements for your system 'linux_x86_64'

Publishing a package (via the command line’s pio pkg publish command) is only one way that you can make your package be able to be included in your platform. In fact, there’s nothing stopping you from using any package specification, and that includes just a simple git link as the version field. E.g.,

You can publish something to the registy by using pio account login as a base step, then inside your downloaded framework folder (that should have a package.json in it), you use pio pkg publish, all of that on the CLI.

If you want to be close to the contents of the repo, either reference your base repository as the version directly (see example above), manually pio pkg publish when you release a new version or setup an automated Github CI trigger that does the pio pkg publish for you (this requires that you generate an authentication token and save it in the Github repo’s “Secrets”, see e.g. Arduino-Pico).

The builder script (builder/frameworks/arduino/arduino-samd.py) should take care of all build options so that no build_flags are required at the user site. That Python script can manipulate the SCons construction variables such as CPPPATH (generates -I flags), CPPDEFINES (generates -D flags). See e.g. here. Note that the CMSIS package is special because it’s usually not included in the Arduino core, it’s pulled form the framework-cmsis and framework-cmsis-atmel packages, the version selection being done by platform.py and the default version selection in the platform.json. If none of those available versions match what your Arduino core uses, you also need to set the correct version to a e.g. Github link where you provide the correct package(s).

See upload logic in main.py. Also note the package selection in the platform.py/platform.json as needed.