md
Adding the Seeeduino XIAO in PlatformIO
May 3, 2020
<-Overview of the SAMD21 Arm Cortex-M0+ Based Seeeduino XIAO --

A very informative response to my first post about the Seeeduino XIAO came in three days ago from D. J. Park in Malaysia. The long email contained many comments, corrections and suggestions which I have yet to digest, but I already know that they will help me improve that overview of the XIAO. However, the purpose of this post is to make available the last part of the message which contained instructions on how to add the XIAO to the list of SAM D21 boards in PlatformIO.

It will be assumed that PlatformIO (PIO for short) is installed and working properly in the Visual Studio Code editor (or another supported editor) on the desktop, but if not, here are the installation instructions. It will also be assumed that the XIAO board has been installed in the Arduino IDE although, strictly speaking, that is not mandatory. In essence adding the XIAO to the environment is a two-step operation.

Copy the XIAO_m0 variants directory from Arduino to PlatformIO

You will need to locate the pertinent "variants" directories of each platform.

  1. The Seeeduino SAMD variants directory in the Arduino IDE.

    On my system this is its absolute path.

    /home/michel/ED/arduino-1.8.10/portable/packages/Seeeduino/hardware/samd/1.7.2/variants/

    It contains 6 subdirectories,

    michel@hp:~$ ls ED/arduino-1.8.10/portable/packages/Seeeduino/hardware/samd/1.7.2/variants/ arduino_zero femto_m0 grove_ui_wireless wio_terminal XIAO_m0 zero_radio

    including the one that is needed: XIAO_m0. Note that I chose the "portable" configuration for the Arduino IDE which was installed inside a directory called ED in my home directory. Had I chosen the standard configuration, the wanted directory would be somewhere else such as

    /home/michel/.arduino15/packages/Seeeduino/hardware/samd/1.7.2/variants/
  2. The PlatformIO variants directory for SAMD devices.

    On my system this is its absolute path.

    /home/michel/.platformio/packages/framework-arduino-samd/variants/

    At the time of writing this, the folder contained 13 subdirectories.

    michel@hp:~$ ls /home/michel/.platformio/packages/framework-arduino-samd/variants/ arduino_mzero circuitplay mkrfox1200 mkrnb1500 mkrwan1300 mkrzero w25_xplained_pro arduino_zero mkr1000 mkrgsm1400 mkrvidor4000 mkrwifi1010 nano_33_iot

    Note the absence of the XIAO_m0 variants directory. If it is there, then the XIAO has been added to PlatformIO, stop reading this!

Now, it's just a matter of copying the directory.

michel@hp:~$ cp -ar ED/arduino-1.8.10/portable/packages/Seeeduino/hardware/samd/1.7.2/variants/XIAO_m0 \ > /home/michel/.platformio/packages/framework-arduino-samd/variants michel@hp:~$ ls /home/michel/.platformio/packages/framework-arduino-samd/variants/XIAO_m0 debug_scripts linker_scripts openocd_scripts pins_arduino.h variant.cpp variant.h

The copy command was split over two lines because it is so long. I was just showing off, it was simpler to use Double Commander to copy the directory.

If the XIAO board is not installed in the Arduino IDE, the variant directory could be pulled from the Seeed-Studio SAMD Arduino Core fork. In the end you should end up with the following directories and files in the <.../.platformio>/packages/framework-arduino-samd/variants/ directory.

XIAO_m0 debug_scripts variant.gdb linker_scripts gcc flash_with_bootloader.ld flash_without_bootloader.ld openocd_scripts XIAO_m0.cfg pins_arduino.h variant.cpp variant.h

Add the XIAO board definition

Thankfully, D. J. Park provided the board definition.

{ "build": { "arduino": { "ldscript": "flash_with_bootloader.ld" }, "core": "arduino", "cpu": "cortex-m0plus", "extra_flags": "-DARDUINO_SAMD_MKRZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__", "f_cpu": "48000000L", "hwids": [ [ "0x2886", "0x802F" ], [ "0x2886", "0x002F" ] ], "mcu": "samd21g18a", "usb_product": "Seeeduino XIAO M0", "variant": "XIAO_m0" }, "debug": { "jlink_device": "ATSAMD21G18", "openocd_chipname": "at91samd21g18", "openocd_target": "at91samdXX", "svd_path": "ATSAMD21G18A.svd" }, "frameworks": [ "arduino" ], "name": "Seeeduino XIAO M0", "upload": { "disable_flushing": true, "maximum_ram_size": 32768, "maximum_size": 262144, "native_usb": true, "offset_address": "0x2000", "protocol": "sam-ba", "protocols": [ "sam-ba", "blackmagic", "jlink", "atmel-ice" ], "require_upload_port": true, "use_1200bps_touch": true, "wait_for_upload_port": true }, "url": "http://wiki.seeedstudio.com/Seeeduino-XIAO/", "vendor": "Seeed" }

All that we have to do is copy it to the correct directory.

/home/michel/.platformio/platforms/atmelsam/boards/seeeduino_xiao.json

The file can be downloaded by clicking on this link: seeeduino_xiao.json. Clicking with the right mouse button might be preferable here.

When a new project is started in PlatformIO, it will be possible to use the Seeeduino XIAO board definition from now on. I use the following platformio.ini configuration file with new projects.

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:seeeduino_xiao] platform = atmelsam board = seeeduino_xiao framework = arduino monitor_speed = 115200

Bonus: printf

The Print library in the SAMD Arduino core of PlatformIO does not support the printf method. Mr Park noted that I liked to use that function so he provided instructions on how to replace that library with the Arduino version which does support printf. All that needed to be done was to copy Print.h and Print.cpp from /home/michel/ED/arduino-1.8.10/portable/packages/Seeeduino/hardware/samd/1.7.2/cores/arduino/ to /home/michel/.platformio/packages/framework-arduino-samd/cores/arduino/. You should probably back up the original PlatformIO Print.h and Print.cpp files before overwriting them.

Thank you

Heartfelt thanks to D. J. Park for this very useful information.

<-Overview of the SAMD21 Arm Cortex-M0+ Based Seeeduino XIAO --