Overview Of The SAMD21 Arm Cortex-M0+ Based Seeeduino XIAO

The Seeed Studio XIAO SAMD21 (formerly known as the Seeeduino XIAO) arrived in my mail box on March 18, 2020. About two weeks later, I published the first version of this post. After making some corrections in the following month, the post remained unchanged until the start of 2022 when I started correcting some parts of the post in view of recent developments and things learned. While adding more and more corrections I became dissatisfied with the original post and decided that a major rewrite was in order. So this is an opportunity to clarify some things and to look at some topics not covered before such as the capacitance touch inputs and the hardware watchdog.

This post is not for the neophyte that has never used the Arduino framework. If you are in that situation, welcome to the fascinating world of microcontroller enthusiasts, and let me suggest that you start with the Seeed Studio XIAO Starter Kit Courses or the original Seeeduino XIAO Free Course by Seeed Studio. Once you have worked through the course, you may want to return to this page if you are curious about some particular topics.

The author of this post is a hobbyist who has tinkered with classic Atmel AVR, STM32 and ESP32 microcontrollers and has somewhat more experience with ESP8266 based development boards. That background obviously tainted the first encounter with the SAM D21 microcontroller found on the Seeed Studio board and it explains some references to the ESP. There were mistakes in the first version of this overview, but welcomed help from readers, notably D. J. Park, made it possible to correct some of the more egregious errors. No doubt, old errors remain while new ones were introduced in this new version. Corrections and suggestions are heartily sought; there is an email link at the bottom of the page for that purpose. Questions adressed to me are answered as best a "non expert" can.

Apologies for the length of this introduction, but that is in keeping with the length of this page which is one of the longest on this site where long posts abound. Hopefully, the table of content will be of use for those looking for a particular topic.

Table of contents
  1. The XIAO Form Factor
    1. Hardware Accessories
    2. What's in a name?
  2. The SAM D21 Microcontroller
  3. Meet Some Seeed Studio XIAO SAMD21 Competitors
  4. Web Resources
  5. Development Environments
  6. Uploading/Bootloader/COM Port/Reset Problem
  7. Only a Blink Sketch, But Do Read Me
  8. A Proper setup() Function
  9. XIAO SAMD21 Input Output Pins
  10. Analogue Input and Output
    1. Analogue Input Calibration
    2. Analogue Measure of Light with an LDR
    3. Capacitance Touch Sensors
    4. Analogue Output
  11. Digital Input and Output
    1. Digital Output
    2. Pulse Width Modulation
    3. Digital Input
  12. Interrupts
  13. Timers
  14. Watchdog
  15. Serial Communication
    1. UART
    2. SPI
    3. I²C
The XIAO Form Factor toc

When SeeedStudio announced the XIAO SAMD21 in late 2019, it was actually launching the first of a family of boards that share a common form factor. Aside from a common size, all the members of the family share a common general pin assignment and a full speed (12Mbsp) USB 2.0 interface with a USB-C type connector. The first four boards in the family have a 32-bit RISC ARM Cortex-M processor from three different chip makers. The latest board is based on the Risc-V architecture. Each member of the complete family is described in the Seeed Studio XIAO Series Web page which also contains a very clear and detailed comparison table. There is another comparison table that is worth looking at.

XIAO (小 in Chinese) means small, as Paul Battley kindly informed me in a private correspondence. There is no doubt that the boards are very small (22x18 mm). Given their tiny size, the two breadboard-compatible headers along the long sides of the board contain only 7 pins each. Three of these are for ground and power (3.3 and 5 volts) while the other 11 pins are I/O pins. All boards share a common Arduino pin numbering and serial connections. By default they all offer one UART, one I²C, and one SPI channel (see the figure below). It is possible to reassign these serial connections in various ways depending on the microprocessor used.

XIAO form factor - front XIAO form factor - backt

All boards have pads on the underside. The number and layout of these is not common although the ARM based boards appear to implement the Serial Wire Debug (SWD) interface in similar fashion (not verified). Instead of the SWD interface, the Risc-V XIAO has pads for the JTAG debug interface on the underside.

Hardware Accessories toc

When purchasing the XIAO SAMD21, it is possible to add three hardware accessories:

  • The Seeed Studio XIAO Expansion board which is a carrier board that adds a number of peripherals, including a buzzer, a real-time clock and a OLED display, as well as standard Grove connectors and a header for the Serial Wire Debug interface.
  • The Grove Shield for Seeed Studio XIAO which is also a carrier board that adds 8 Grove connectors and battery management.
  • The Seeed Studio XIAO Starter Kit which includes the XIAO Expansion board, nine Grove modules and additional components. It is meant to accompany the free Seeed Studio XIAO Series course already recommended above for neophytes.

I have not tested any of these products, so what I am about to say is based on reading the product descriptions and may not be accurate. First of all, I believe the two carrier boards were developed for the XIAO SAMD21 and I am confused about the compatibility of these with other members of the XIAO series. That's because pogo pins are used to connect to some of the pads on the underside of the XIAO, notably the SWD interface. It is unlikely that the debug interface would work on the XIAO ESP32C3 because it uses the JTAG standard instead of SWD. Even my first generation XIAO SAMD21 boards could have problems because they do not have the GND and RST pads just below the SWD pads. So before purchasing any of these accessories, make sure it will meet your expectations.

What's in a name? toc

A couple of months ago, Seeed Studio posted the following note: product names of the XIAO series might not be consistent enough, which is why we’ve changed the product names of all XIAO series products [so that] they have one unified, consistent name (source). Here is part of the table.

Original NameNew Name
Seeeduino XIAOSeeed Studio XIAO SAMD21
Seeed XIAO RP2040Seeed Studio XIAO RP2040
Seeed XIAO BLE - nRF52840Seeed Studio XIAO nRF52840
Seeed XIAO BLE Sense - nRF52840Seeed Studio XIAO nRF52840 Sense
XIAO WiFi/BLE - ESP32C3Seeed Studio XIAO ESP32C3

The logic behind the names makes sense.

  • Manufacturer's name: Seeed Studio
  • Product series (or form factor): XIAO
  • Product ID (or microcontroller): SAMD21, RP2040, etc.

This new naming scheme is a good idea, as others have been introducing their own names such as XIAO M0 for the Seeeduino XIAO XIAO SAMD21. However, there is no going back for many libraries and packages that have been available for a long time already. Programming environments continue to identify the SAMD21 XIAO as the Seeeduino XIAO for example.

There will be no other mention of the newer members of the XIAO family in this post; XIAO will refer to the SAM D21 based board from now on.

The SAM D21 Microcontroller toc

The Atmel (now Microchip) SAM D21 is by no means a new microcontroller. It was introduced in 2012 as a low power and high performance 32-bit alternative to the mostly 8 bit devices used for IoT applications at the time. The high performance is relative, the core cannot perform floating point arithmetic in hardware. The same applies to 32-bit integer division and 32-bit integer multiplication with 64 bit results. Nevertheless, the M0+ core is a significant step up from AVR type microcontrollers.

ATTINY85-20MU ATMEGA328P-MUR ATSAMD21G18A-MU
Core Size (bits) 8 32
Speed (MHz) 20 48
Flash Memory (K bytes) 8 32 256
RAM (K bytes) 0.5 2 32
I/O 6 23 38
ADC (number/bits) 4/10 8/10 14/12
DAC (number/bits) 0 1/10
Connectivity I²C, SPI, UART I²C, SPI, UART, LIN, USB
Unit price ($US) 0.95 2.08 3.00

Prices were obtained from Digikey on March 20, 2020. At just under $5.00 from Seeed Studio, the XIAO looks like a bargain. I very much doubt one could purchase the CPU, an external crystal, a voltage regulator, four LEDs, various capacitors and resistors, metal can and a USB-C connector to make a similar board any cheaper. You could try, the schematic and more technical information is available in the Hardware Development Kit. Meet Some Seeed Studio XIAO SAMD21 Competitors toc

The Seeeduino XIAO is not the first board based on the SAM D21 microprocessor. The major players in the hobbyist world have numerous boards in production: Arduino, See the Zero, MKR Zero and MKR 1000. Adafruit, and See the METRO M0, Feather M0 Basic Proto and the many other Feather devices based on the same processor. Sparkfun See the Redboard Turbo, SAMD21 Dev Breakout and SAMD21 Mini Breakout.

However the most direct competitor is the Adafruit QT Py. It has the same form factor as the XIAO, uses almost the same microcontroller (ATSAMD21E18 vs the ATSAMD21G18 on the XIAO), and adds some additional features such as an onboard Stemma QT connector for the I²C bus and solder pads on the back side for an optional SPI flash chip. The SWD interface is made available as two pads on the back side of the board just like the XIAO, but their location appears to be different.

There are others. Freescale (an offshoot of Motorola but now owned by NXP which is itself an offshoot of Phillips) may have been one of the first to offer boards based on the SAM D21. PjRC and avdweb produce small boards based on the same processor. Even Seeed Studio has at least four other SAM D21 based boards on offer (such as the Seeeduino Lotus Cortex-M0+ and Seeeduino LoRaWAN).

Web Resources toc

Information about the SAMD21 microcontroller, XIAO development board and other boards of the same type is accumulating rapidly on the Internet. There is now much more than can be read by any one person. So here is a partial list of sources that I have found useful.

General Information about the ARM architecture and the SAM D21 microcontroller. These references are quite technical and probably best avoided by those first starting out.

  • Joseph Yiu, (September 2016)) Arm Cortex-M for Beginners.
  • Microchip, (2020) SAM D21/DA1 Family, Complete Datasheet DS40001882E.

Information by SeeedStudio The information provided by the manufacturer is voluminous in comparison to others although most of it is from third parties. The main problem that I have is that it is dispersed and hence rather difficult to find.

  • The catalogue of XIAO parts and the new Seeed Studio XIAO Series page already mentioned.
  • The Seeed Studio XIAO SAMD21 product detail page. Scroll down the page to the Documentations section which contains many useful links. I am pleased and honoured to report that a link to this post is included in that page.
  • The Seeeduino XIAO Free Course. That archive contains a 124 page PDF manual entitled Seeeduino XIAO in Action Minitype & Wearable Projects Step by Step by Yimeng Shi at SeeedStudio. As mentioned in the introduction, neophytes should begin with that resource. The course assumes that the XIAO SAMD21 is used along with the XIAO Starter Kit. That kit may be a valuable resource for a neophyte. I remember using a similar kit for the Arduino when starting out and it simplified the learning process which is always a bit daunting at first. Hobbyists on the other hand will already have a breadboard or two, Dupont wires and most of the devices found in the kit.
  • The SeeedStudio Wiki. Click on Platform in the Seeed Wiki on the left of the page and then select Seeed Studio XIAO and then Seeed Studio XIAO SAMD21. Aside from the introductory page there are 8 other topics. I highly recommend Seeeduino XIAO Get Started By Nanase as a better introduction to the device than my attempt here.
  • Search the Seeed Studio Forum for XIAO.
  • Search the The Seeed Studio Blog for XIAO.

Given the number of boards available, there is good information on the Web about the SAM D21. Adafruit has a tutorial Adafruit Feather M0 Basic Proto, Wanna play with the ARM Cortex M0 chipset? that is useful for XIAO users, particularly the section entitled Adapting Sketches to M0 & M4. The same is true at Sparkfun: RedBoard Turbo Hookup Guide and SAMD21 Mini/Dev Breakout Hookup Guide. The avdweb site by Albert van Dalen also has very useful information although it may be a little difficult to find. I use the search facility to find something I remember having seen previously.

A search of GitHub for "SEEED XIAO" will produce some interesting projects along with chaff. The search criteria "xiao m0" will yield the repository of sketches that accompanies this post as well as other collections of examples. The DroneBot Workshop published a Meet the Seeeduino XIAO blog post along with a YouTube video just yesterday (Dec 1, 2020). The author Bill (William) is a fellow Canadian born in Montréal as I was. Back to the topic, I have a number of additional posts about the XIAO SAMD21:

  • "Adding the Seeeduino XIAO in PlatformIO (May 3, 2020). Ignore this post, the XIAO is fully supported in PlatformIO.
  • "Hello XIAO" in PlatformIO (June 6, 2020)
  • I²C Light Sensor using a Seeeduino XIAO
  • Seeeduino XIAO Serial Communication Interfaces (SERCOM) (May 5, 2020)
  • The XAIO as a USB-Serial Converter (November 2020)
  • Three Nay, Four Hardware Serial Ports on a SAM D21 XIAO (26 March, 2022)

The increasing availability of good information about the XIAO and the SAM D21 microcontroller and other topics is a primary motivator for this second edition of the post.

Development Environments toc

Purists might want to try to program the XIAO using the Microchip (Atmel) Studio 7 IDE. There is copious documentation on the Microchip site although most appears to be based on the in-house development boards. This IDE is complex and I suspect that the learning curve is rather steep. There is another catch, at least for me, Studio 7 only runs in Windows.

Most readers of this post will probably choose to work with the XIAO in the Arduino framework. The original Arduino core for the SAM D21/D51 microcontrollers is available on GitHub. However it does not contain the board definition for the XIAO. Instead a fork by Seeed Studio must be used. When first introduced, only the Arduino Software (i.e. the Arduino integrated development environment or Arduino IDE) supported the XIAO, but it did not take long before PlatformIO supported the board as well.

There is another framework that can be used to program the XIAO in PlatformIO. Called Zephyr, an "OS [that] is based on a small-footprint kernel designed for use on resource-constrained and embedded systems: from simple embedded environmental sensors and LED wearables to sophisticated embedded controllers, smart watches, and IoT wireless applications." It does not appear to be as user-friendly as the Arduino framework, but that is just an uninformed judgment because I have absolutely no experience with Zephyr. Have a look at the source of its "blinky" sample program to get a little taste.

The programming language in the previous development frameworks is C/C++. Some, especially those that write programs for the Raspberry Pi, may prefer Python. There is a SAM D21 implementation of MicroPython which is largely compatible with Python 3. It is not entirely clear to me how well the XIAO is supported when looking at a recent entry in the forum. Adafruit has created CircuitPython which is a fork of MicroPython that tries to make the language easier to learn. Unfortunately, Adafruit only supports its own boards but it looks as if the XIAO is supported. Read Installing Circuit Python on Seeeduino Xiao. Andy Warburton makes it look simple to set up and use. MicroPyhton and CircuitPython bring to mind the ESP8266

Từ khóa » Xiao M0