mattairtech / ArduinoCore-samd

This is a fork from arduino/ArduinoCore-samd on GitHub. This will be used to maintain Arduino support for SAM D|L|C (M0+ and M4F) boards including the MattairTech Xeno Mini and the MT-D21E (see https://www.mattairtech.com/). It adds support for new devices like the D51, L21, C21, and D11. It also adds new clock sources, like a high speed crystal or internal oscillator.
103 stars 43 forks source link

MattairTech SAM D|L|C Core for Arduino

The MattairTech SAM D|L|C Core for Arduino is a fork from arduino/ArduinoCore-samd on GitHub, which will be used to maintain Arduino support for MattairTech boards (see https://www.mattairtech.com/) as well as for "Generic" boards.

SAMD51 support starting with 1.6.18-beta-b0

This core is intended to be installed using Boards Manager (see below). To update from a previous version, click on MattairTech SAM D|L|C Boards in Boards Manager, then click Update.

New Version Numbering The MattairTech version number will now track with the Arduino version number, to better understand which upstream changes have been merged in. See the CHANGELOG for details on upstream commits and MattairTech additions that have been merged.

What's New - Release Version (1.6.17)

The latest updates are in the Beta version (if available). See below.

1.6.17 (February 22, 2018):

What's New - Beta Version (1.6.18-beta)

Beta builds are now included in the main json. See Beta Builds section.

1.6.18-beta-b1 (June 26, 2018):

1.6.18-beta-b0 (February 22, 2018):

1.6.17-beta-b0: Beta version 1.6.17-beta-b0 became release version 1.6.17. See above

1.6.16-beta-b0:

Features Summary for D51

Feature 51P (128 pin) 51N (100 pin) 51J (64 pin) 51G (48 pin)
Board Variants Generic 51P Generic 51N MattairTech Xeno, Generic 51J Xeno Mini, Generic 51G
Processor 120 MHz 32-bit ARM Cortex M4F 120 MHz 32-bit ARM Cortex M4F 120 MHz 32-bit ARM Cortex M4F 120 MHz 32-bit ARM Cortex M4F
Processor Features FPU, DSP, MPU FPU, DSP, MPU FPU, DSP, MPU FPU, DSP, MPU
Flash Memory Up to 1MB with RWW support and cache Up to 1MB with RWW support and cache Up to 1MB with RWW support and cache Up to 512KB with RWW support and cache
SRAM Up to 256KB (8KB backup SRAM), ECC Up to 256KB (8KB backup SRAM), ECC Up to 256KB (8KB backup SRAM), ECC Up to 192KB (8KB backup SRAM), ECC
Digital Pins 99 81 51 37
Analog Inputs 2 ADCs, 16/16 channels, 12-bit, 1MSPS 2 ADCs, 16/12 channels, 12-bit, 1MSPS 2 ADCs, 16/8 channels, 12-bit, 1MSPS 2 ADCs, 16/4 channels, 12-bit, 1MSPS
Analog Outputs Two 12-bit, 1MSPS Two 12-bit, 1MSPS Two 12-bit, 1MSPS Two 12-bit, 1MSPS
PWM Outputs 17 TCC channels, 16 TC channels 17 TCC channels, 16 TC channels 17 TCC channels, 12 TC channels 13 TCC channels, 8 TC channels
Interrupts 16 16 16 16
USB Full Speed Device and Host Full Speed Device and Host Full Speed Device and Host (not C21) Full Speed Device and Host
SERCOM 8 (UART/SPI/I2C) 8 (UART/SPI/I2C) 6 (UART/SPI/I2C) 6 (UART/SPI/I2C)
QSPI / SDHC 1 QSPI / 2 SDHC 1 QSPI / 2 SDHC 1 QSPI / 1 SDHC 1 QSPI / 1 SDHC
I2S One RX, one TX, two clocks One RX, one TX, two clocks One RX, one TX, two clocks One RX, one TX, two clocks
Voltage 1.71V - 3.63V 1.71V - 3.63V 1.71V - 3.63V 1.71V - 3.63V
I/O Pin Current 8mA sink/source @ 3.3V 8mA sink/source @ 3.3V 8mA sink/source @ 3.3V 8mA sink/source @ 3.3V

Features Summary for D21/L21/C21/D11

Feature 21J (64 pin) 21G (48 pin) 21E (32 pin) D11 (24, 20, or 14 pin)
Board Variants MattairTech Xeno, Generic 21J Xeno Mini, Arduino Zero, Generic 21G MT-D21E, Generic 21E MT-D11, Generic D11D14AM, Generic D11D14AS, Generic D11C14A
Processor 48 MHz 32-bit ARM Cortex M0+ 48 MHz 32-bit ARM Cortex M0+ 48 MHz 32-bit ARM Cortex M0+ 48 MHz 32-bit ARM Cortex M0+
Flash Memory Up to 256KB (L21/C21 have RWW) Up to 256KB (L21/C21 have RWW) Up to 256KB (L21/C21 have RWW) 16 KB (4KB used by bootloader)
SRAM Up to 32KB (plus <=8KB LPSRAM on L21) Up to 32KB (plus <=8KB LPSRAM on L21) Up to 32KB (plus <=8KB LPSRAM on L21) 4 KB
Digital Pins 52 (51 for L21) 38 (37 for L21) 26 (25 for L21) 24-pin: 21, 20-pin: 17, 14-pin: 11
Analog Inputs 18 channels, 12-bit 14 channels, 12-bit 10 channels, 12-bit 24-pin: 10, 20-pin: 8, 14-pin: 5 (12-bit)
Analog Outputs One 10-bit (two 12-bit on L21) One 10-bit (two 12-bit on L21) One 10-bit (two 12-bit on L21) One 10-bit
PWM Outputs 18 14 14 8 (6 for 14-pin)
Interrupts 16 16 16 8 (7 for 14-pin)
USB Full Speed Device and Host (not C21) Full Speed Device and Host (not C21) Full Speed Device and Host (not C21) Full Speed Device
SERCOM* 6 6 4 (6 for L21) 3 (2 for 14-pin)
UART (Serial)* Up to 3 (will add more later) Up to 6 Up to 4 (up to 6 for L21) Up to 2
SPI* Up to 2 (will add more later) Up to 2 Up to 2 Up to 1
I2C (WIRE)* Up to 2 (will add more later) Up to 2 Up to 2 Up to 1
I2S Present on the D21 only Present on the D21 only Present on the D21 only Not present
Voltage 1.62V-3.63V (2.7V-5.5V for the C21) 1.62V-3.63V (2.7V-5.5V for the C21) 1.62V-3.63V (2.7V-5.5V for the C21) 1.62V-3.63V
I/O Pin Current D21: 7mA, L21: 5mA, C21: 6mA@5V D21: 7mA, L21: 5mA, C21: 6mA@5V D21: 7mA, L21: 5mA, C21: 6mA@5V 7 mA

Note that the maximum number of UART/SPI/I2C is the number of SERCOM. The number listed above for UART/SPI/I2C indicated how many are currently configurable through the Arduino IDE menu.

Board Variants

Pin configuration and peripheral assignment information is now in the README.md for each board variant. README.md also now includes technical information on the new PinDescription table format.

Tools Menu Additions

Depending on the board variant, different menu options will appear in the Tools menu.

Microcontroller Menu

This menu will appear with boards that have multiple microcontroller options.

Clock Source Menu

There are up to four clock source choices, depending on board variant and microcontroller. They are:

See Clock Source section for more information.

Bootloader Size Menu

With the D51, D21, L21, and C21, the bootloader size can be configured as:

With the D11, the bootloader size can be configured as:

Choose NO_BOOTLOADER if not using a bootloader (an external programmer will be used for sketch upload).

Serial Config Menu

This menu is used to select different combinations of serial peripherals. It adds additional UART, SPI, and WIRE instances. This is also useful for the D11, which has a reduced pin count and number of SERCOMs. It can also be used to reduce FLASH and SRAM usage by selecting fewer UART peripherals, which are instantiated in the core, rather than only when including a library (like SPI and WIRE). Note that with options where there is more than one SPI or WIRE, the additional instances will consume a small amount of RAM, but neither the peripheral nor the pins are configured until begin() method is called (thus, the pins can be used for other purposes).

Use the ASCII art rendering at the top of the README.md file of the board variant used in order to determine the mapping of instances to pins. When USB CDC is enabled, Serial refers to SerialUSB, otherwise it refers to Serial1 (TX1/RX1).

USB Config Menu

This menu will appear with all microcontrollers except the C21, which does not have USB. The options are:

Choose an option that best matches your code and library usage. Each option results in a different USB PID. Choose an option with CDC if you want auto-reset to function, or the serial monitor over USB. If CDC is not enabled, Serial will refer to Serial1 instead of SerialUSB. These options can be used to optimize FLASH and SRAM usage by allowing CDC to be disabled (or USB completely disabled).

Timer PWM Frequency

This menu will appear with all microcontrollers. It allows selection of the PWM frequency used by all timers. When using a timer in 16-bit mode, calls to analogWrite() are made with 8-bit resolution by default. For 16-bit writes, call analogWriteResolution(16) first. Because of the faster timer clock used with the D51, the 1465Hz setting is 16-bit. Older cores used the 187500Hz (8-bit) setting, which is now available in the menu. Note that some motor controllers can be inefficient or overheat with higher PWM frequencies, however, using a higher frequency can quiet down noisy ceramic capacitors or reduce flicker with LED lighting applications. The menu options are:

Floating Point

By default, when using the Print or String classes to print or convert floating point numbers to character arrays, singles are automatically promoted to doubles. This consumes a lot of code space. Use the options in this menu to make use of single floating point versions of Print and String, which will reduce code space, increase performance, and also allow the D51 to make use of the hardware FPU (in the case of Print). See Floating Point Notes.

Build Options (config.h)

This menu will appear with all microcontrollers. It is currently used to enable or disable including config.h, which contains several defines that are used primarily to reduce code space. config.h should be edited first. Please see config.h for documentation on the defines. The menu options are:

Current Build Options

Clock Source

There are up to four clock source choices, depending on board features and microcontroller. Since currently the cpu runs at 48MHz (or 120MHz with the D51), the PLL or DFLL must be used (the SAMC can use OSC48M).

32KHZ_CRYSTAL (default)

HIGH_SPEED_CRYSTAL

INTERNAL_OSCILLATOR

INTERNAL_USB_CALIBRATED_OSCILLATOR (not available with SAMC)

SAMD21 / SAMD11

Source Frequency Range Supply Current (max.) Startup Time typ. (max.) Notes, jitter, accuracy, other differences
XOSC 0.4MHz-32MHz crystal 307uA (552uA) AGC on 5K-14K cycles (10K-48K) up to 32MHz digital clock input, Supply current based on 16MHz crystal
XOSC32K 32.768KHz typical crystal 1.22uA (2.19uA) 28K cycles (30K) 32.768KHz typical digital clock input
OSC32K 32.27-33.26KHz (28.50-34.74KHz) 0.67uA (1.32uA) 1 cycle (2 cycles)
OSCULP32K 31.29-34.57KHz (25.55-38.01KHz) 0.125uA max. 10 cycles
OSC8M 7.94-8.06MHz (7.80-8.16MHz) 64uA 2.1us (3us)
FDPLL96M 32KHz-2MHz in, 48MHz-96MHz out 500uA (700uA) Lock: 25us (50us) @ 2MHz in 1.5% (2%) period jitter (32KHz in, 48MHz out), Lock: 1.3ms (2ms) @ 32KHz in
DFLL48M open 47MHz-49MHz out 403uA (453uA) 8us (9us)
DFLL48M closed 0.73-33KHz in, 47.96-47.98MHz out 425uA (482uA) Lock: 200us (500us) 0.42ns max. jitter

SAMD51

Source Frequency Range Supply Current (max.) Startup Time typ. (max.) Notes, jitter, accuracy, other differences
XOSC (x2) 8MHz-48MHz crystal 250uA (810uA) ENALC on 37K cycles (62K) Up to 48MHz digital clock input, supply current based on 16MHz crystal
XOSC32K 32.768KHz crystal 1.9uA (3uA) 9K cycles (23K) Use high gain setting
OSCULP32K 32.10-33.42KHz Not Specified. Not Specified 27.12-37.68KHz across temperature
FDPLL200M (x2) 32KHz-3.2MHz in, 96MHz-200MHz out 0.9mA (1.3mA) @ 96MHz Lock: 54us (95us) @ 3.2MHz in 1.9% (2.7%) period jitter (32KHz in, 96MHz out), Datasheet lock time in ms.
DFLL48M open 47.2MHz-48.8MHz 400uA (850uA) 4.3us (7us) 45.8MHz-49.3MHz across temperature
DFLL48M closed 47.972MHz typical 400uA (850uA) Lock: 429us (1145us) 0.42ns max. jitter, 0.73-33KHz input

SAML21

Source Frequency Range Supply Current (max.) Startup Time typ. (max.) Notes, jitter, accuracy, other differences
XOSC 0.4MHz-32MHz crystal 293uA (393uA) AGC on 5K-14K cycles (10K-48K) up to 24MHz digital clock input, Supply current based on 16MHz crystal
XOSC32K 32.768KHz typical crystal 0.311uA (2.19uA) 25K cycles (82K) 32.768KHz typical digital clock input (1MHz max.)
OSC32K 32.57-33.05KHz (28.58-34.72KHz) 0.54uA (1.10uA) 1 cycle (2 cycles)
OSCULP32K 31.77-34.03KHz (26.29-38.39KHz) Not Specified. Not Specified
OSC16M 15.75-16.24MHz 141uA (169uA) 1.4us (3.1us) Wake up time: 0.12us (0.25us)
FDPLL96M 32KHz-2MHz in, 48MHz-96MHz out 454uA (548uA) Lock: 25us (35us) @ 2MHz in 1.9% (4%) period jitter (32KHz in, 48MHz out), Lock: 1ms (2ms) @ 32KHz in
DFLL48M open 46.6MHz-49MHz out 286uA 8.3us (9.1us)
DFLL48M closed 0.73-33KHz in, 47.96-47.98MHz out 362uA Lock: 200us (700us) 0.51ns max. jitter

SAMC21

Source Frequency Range Supply Current (max.) Startup Time typ. (max.) Notes, jitter, accuracy, other differences
XOSC 0.4MHz-32MHz crystal 429uA (699uA) AGC on 6K-12K cycles (20K-48K) up to 48MHz digital clock input, Supply current based on 16MHz crystal
XOSC32K 32.768KHz typical crystal 1.53uA (2.84uA) 16K cycles (24K) 32.768KHz typical digital clock input
OSC32K 32.11-33.43KHz (25.55-37.36KHz) 0.864uA (1.08uA) 1 cycle (2 cycles)
OSCULP32K 30.96-34.57KHz (22.93-38.99KHz) Not Specified. Not Specified
OSC48M 47.04-48.96MHz 87uA (174uA) 22.5us (25.5us)
FDPLL96M 32KHz-2MHz in, 48MHz-96MHz out 536uA (612uA) Not Yet Specified

External 32.768KHz Crystal

The PLL will be used with the 32.768KHz crystal. PLL_FRACTIONAL_ENABLED can be defined, which will result in a more accurate 48MHz output frequency at the expense of increased jitter.

External High-Speed Crystal

HS_CRYSTAL_FREQUENCY_HERTZ must be defined with the external crystal frequency in Hertz. The crystal frequency must be between 400000Hz and 32000000Hz (800000Hz and 48000000Hz with the D51). The PLL will be used. PLL_FRACTIONAL_ENABLED can be defined, which will result in a more accurate 48MHz output frequency at the expense of increased jitter. If PLL_FAST_STARTUP is defined, the crystal will be divided down to 1MHz - 2MHz, rather than 32KHz - 64KHz, before being multiplied by the PLL. This will result in a faster lock time for the PLL, however, it will also result in a less accurate PLL output frequency if the crystal is not divisible (without remainder) by 1MHz. In this case, define PLL_FRACTIONAL_ENABLED as well. By default, PLL_FAST_STARTUP is disabled. PLL_FAST_STARTUP is also useful for USB host mode applications. See datasheet USB electrical characteristics. The crystal frequency must be at least 1000000Hz when PLL_FAST_STARTUP is defined.

Internal Oscillator

The DFLL will be used in open-loop mode, except with the C21 which lacks a DFLL, so the internal 48MHz RC oscillator is used instead. NVM_SW_CALIB_DFLL48M_FINE_VAL is the fine calibration value for DFLL open-loop mode. The coarse calibration value is loaded from NVM OTP (factory calibration values).

Internal Oscillator with USB Calibration

This is available for the D51, D21, D11, or L21. It will also use the DFLL in open-loop mode, except when connected to a USB port with data lines (and not suspended), then it will calibrate against the USB SOF signal. NVM_SW_CALIB_DFLL48M_FINE_VAL is the fine calibration value for DFLL open-loop mode. The coarse calibration value is loaded from NVM OTP (factory calibration values).

Clock Generators Currently Used

The D51 has 12 generators and all others have 9 generators. Unused generators are automatically stopped to reduce power consumption.

  1. MAIN - Used for the CPU/APB clocks. With the D51, it runs at either 96MHz (divided by 2 in MCLK) or 120MHz undivided. Otherwise, it runs at 48MHz.
  2. XOSC - The high speed crystal is connected to GCLK1 in order to use the 16-bit prescaler.
  3. OSCULP32K - Initialized at reset for WDT (D21 and D11 only). Not used by core.
  4. OSC_HS - 8MHz from internal RC oscillator (D21, D11, and L21 only). Setup by core but not used.
  5. 48MHz - Used for USB or any peripheral that has a 48MHz (60MHz for D51) maximum peripheral clock. GCLK0 is now only 96MHz or 120MHz with the D51.
  6. TIMERS - Used by the timers for controlling PWM frequency. Can be up to 48MHz (up to 96MHz with the D51).
  7. 192MHz - Used only by D51 for any peripheral that has a 200MHz maximum peripheral clock (note that GCLK8 - GCLK11 must be <= 100MHz).
  8. I2S - Used by D51 and D21 for I2S peripheral. This define is not currently used. The generator is defined in each variant.h.
  9. I2S1 - Used by D51 and D21 for I2S peripheral. This define is not currently used. The generator is defined in each variant.h.
  10. DFLL - Used only by D51 (only when the cpu is 120MHz) with CLOCKCONFIG_INTERNAL or CLOCKCONFIG_INTERNAL_USB to generate 2MHz output for the PLL input.
  11. 96MHz - Used only by D51 for any peripheral that has a 100MHz maximum peripheral clock.
  12. UNUSED11 - Unused for now. D51 only.

Analog Reference

D21 / D11

D51

L21

C21

Warning : The maximum IO voltage is Vcc (up to 3.6 volts for the D51/D21/D11/L21, 5V for the C21)

Reference Selection Table

D21 / D11 Volts D51 Volts L21 Volts C21 Volts
AR_DEFAULT 1/2 VCC* AR_DEFAULT VCC AR_DEFAULT VCC AR_DEFAULT VCC
AR_INTERNAL1V0 1.00V AR_INTREF 1.00V AR_INTREF 1.00V AR_INTREF 1.024V
AR_INTERNAL_INTVCC0 1/1.48 VCC AR_INTREF_1V0 1.00V AR_INTREF_1V0 1.00V AR_INTREF_1V024 1.024V
AR_INTERNAL_INTVCC1 1/2 VCC AR_INTREF_1V1 1.10V AR_INTREF_1V1 1.10V AR_INTREF_2V048 2.048V
AR_EXTERNAL_REFA REFA AR_INTREF_1V2 1.20V AR_INTREF_1V2 1.20V AR_INTREF_4V096 4.096V
AR_EXTERNAL_REFB REFB AR_INTREF_1V25 1.25V AR_INTREF_1V25 1.25V AR_INTERNAL1V0 1.024V
--- AR_INTREF_2V0 2.00V AR_INTREF_2V0 2.00V AR_INTERNAL_INTVCC0 1/1.6 VCC
--- AR_INTREF_2V2 2.20V AR_INTREF_2V2 2.20V AR_INTERNAL_INTVCC1 1/2 VCC
--- AR_INTREF_2V4 2.40V AR_INTREF_2V4 2.40V AR_INTERNAL_INTVCC2 VCC
--- AR_INTREF_2V5 2.50V AR_INTREF_2V5 2.50V AR_EXTERNAL_REFA REFA
--- AR_INTERNAL1V0 1.00V AR_INTERNAL1V0 1.00V AR_EXTERNAL_DAC DAC
--- AR_INTERNAL_INTVCC1 1/2 VCC AR_INTERNAL_INTVCC0 1/1.6 VCC
--- AR_INTERNAL_INTVCC2 VCC AR_INTERNAL_INTVCC1 1/2 VCC
--- AR_EXTERNAL_REFA REFA AR_INTERNAL_INTVCC2 VCC
--- AR_EXTERNAL_REFB REFB AR_EXTERNAL_REFA REFA
--- AR_EXTERNAL_REFC REFC AR_EXTERNAL_REFB REFB

Common Settings

Note that with the D51, INTVCC1 and INTVCC2 as used in Arduino are actually INTVCC0 and INTVCC1 in the datasheet. AR_DEFAULT uses 1/2X gain on each input and a Vcc/2 (1.65V) reference supporting measurements up to Vcc.

Floating Point Notes

Floating Point Changes

Hints for Using Floating Point Numbers

Floating Point Size Comparison Table

Configuration and MCU TEST_SINGLE_PRINT TEST_DOUBLE_PRINT TEST_SINGLE_STRING TEST_DOUBLE_STRING
FLOAT_BOTH_DOUBLES_ONLY - D21 9504 8144 16848 16688
FLOAT_BOTH_SINGLES_DOUBLES - D21 4176 8144 4016 16688
FLOAT_BOTH_DOUBLES_ONLY - D51 2968 2952 11144 11152
FLOAT_BOTH_SINGLES_DOUBLES - D51 544 2952 3264 11152

Values indicate additional size of option in bytes. The base test sketch was 864 bytes larger with the D51 when no floating point was used.

Chip Specific Notes

SAMD21

SAMD51

SAML21

SAMC21

SAMD11

Reducing SRAM/FLASH Usage

TODO: Disable usb, disable serial, enable config.h, use PIN_DESCRIPTION_TABLE_SIMPLE and PIN_MAP_COMPACT with the D11, don't use double precision (see above), use no bootloader Most of this can be done from the Tools menu, and by editing config.h.

Code Size and RAM Usage (1.6.5-mt2)

TODO: This is old. Update this, maybe just for D11.

Sketch and Configuration MT-D21E (Flash + RAM) MT-D11 (Flash + RAM)
Blink (CDC + HID + UART) 7564 + 1524 7452 + 1424
Blink (CDC + UART) 6588 + 1496 6484 + 1396
Blink (CDC Only) 5248 + 1304 5192 + 1300
Blink (UART Only) 3828 + 336 3716 + 236
Blink (No USB or UART) 2472 + 144 2416 + 140
Datalogger (No USB or UART) 10340 + 948 10260 + 944

Detailed Memory Usage Output After Compilation

The flash used message at the end of compilation is not correct. The number shown represents the .text segment only. However, Flash usage = .text + .data segments (RAM usage = .data + .bss segments). In this release, two programs are run at the end of compilation to provide more detailed memory usage. To enable this output, go to File->Preferences and beside "Show verbose output during:", check "compilation".

Just above the normal flash usage message, is the output from the size utility. However, this output is also incorrect, as it shows .text+.data in the .text field, but 0 in the .data field. However, the .text field does show the total flash used. The .data field can be determined by subtracting the value from the normal flash usage message (.text) from the value in the .text field (.text+.data). The .bss field is correct.

Above the size utility output is the output from the nm utility. The values on the left are in bytes. The letters stand for: T(t)=.text, D(d)=.data, B(b)=.bss, and everything else (ie: W) resides in flash (in most cases).

Serial Monitor

To print to the Serial Monitor over USB, use 'Serial'. Serial refers to SerialUSB (Serial1 and Serial2 are UARTs). Unlike most Arduino boards (ie. Uno), SAMD boards do not automatically reset when the serial monitor is opened. To see what your sketch outputs to the serial monitor from the beginning, the sketch must wait for the SerialUSB port to open first. Add the following to setup():

while (!Serial) ;

Remember that if the sketch needs to run without SerialUSB connected, another approach must be used. You can also reset the board manually with the Reset button if you wish to restart your sketch. However, pressing the Reset button will reset the chip, which in turn will reset USB communication. This interruption means that if the serial monitor is open, it will be necessary to close and re-open it to restart communication.

When USB CDC is not enabled, Serial will instead refer to Serial1, which is the first UART.

Differences Between MattairTech and Arduino Cores (TODO)

Installation

Driver Installation

Windows

Prior to core version 1.6.6-mt1, sketches compiled with both CDC and HID USB code by default, thus requiring a CDC driver for the bootloader and a CDC-HID driver for sketches. Now that PluggableUSB is supported, sketches compile with only CDC code by default. Thus, only one driver is needed. Since HID and MIDI are currently supported (and MSD potentially in the future), driver installation will be required for each different combination of USB devices. There are currently four USB composite device combinations that include CDC as well as a CDC only device. Each supported combination has a unique USB VID:PID pair, and these are listed in the .inf file. Once the first device is installed (the CDC only device), future installations might be automatic, otherwise, you may direct the installer to the same .inf file. The drivers are signed and support both 32 and 64 bit versions of Windows XP(SP3), Vista, 7, 8, and 10. Note that the Windows 10 generic CDC drivers work as well.

  1. If you do not already have the SAM-BA bootloader installed, see below.
  2. Download https://www.mattairtech.com/software/MattairTech_CDC_Driver_Signed.zip and unzip into any folder. Note that the Windows 10 generic CDC drivers work as well.
  3. Plug in the board. The LED should fade when the bootloader is running (or blink if the test sketch is running).
  4. Windows will detect the board. Point the installer to the folder from above to install the bootloader driver.
  5. If you don't intend on using Arduino, you can skip the rest of this list. See Using Bossac Standalone below.
  6. If you do not already have the test firmware installed (comes preinstalled), see Using Bossac Standalone below.
  7. Press the reset button to run the test firmware (if needed). The LED will blink.
  8. Windows will detect the board. Point the installer to the above folder to install the sketch driver (if needed).
  9. Continue with SAM D|L|C Core Installation below.

Linux

  1. No driver installation is needed.
  2. On some distros, you may need to add your user to the same group as the port (ie: dialout) or set udev rules:
  3. You MAY have to install and use Arduino as the root user in order to get reliable access to the serial port.
    • This is true even when group permissions are set correctly, and it may fail after previously working.
    • You can also create/modify a udev rule to set permissions on the port so everyone can read / write.
  4. If you are running modemmanager (ie: Ubuntu), disable it, or use the udev rules file above.
  5. Continue with SAM D|L|C Core Installation below.

OS X

OS X support was added in version 1.6.7-beta-b0.

  1. No driver installation is needed.
  2. Plug in the board. You may get a dialog box asking if you wish to open the “Network Preferences”:
    • Click the "Network Preferences..." button, then click "Apply".
    • The board will show up as “Not Configured”, but it will work fine.
  3. Continue with SAM D|L|C Core Installation below.

MattairTech D|L|C Core Installation

See Beta Builds section below to install the beta, as it uses a different json file

  1. The MattairTech SAM D|L|C Core requires Arduino IDE 1.6.7 or above (including 1.8.x).
  2. In the Arduino IDE, click File->Preferences.
  3. Click the button next to Additional Boards Manager URLs.
  4. Add https://www.mattairtech.com/software/arduino/package_MattairTech_index.json.
  5. Save preferences, then open the Boards Manager.
  6. Install the Arduino SAMD Boards package. Use version 1.6.2 or higher.
  7. Install the MattairTech SAM D|L|C Core for Arduino package.
  8. Close Boards Manager, then click Tools->Board->(choose board).
  9. Select the MCU with the now visible Tools->Microcontroller menu (if present).
  10. If you do not already have the bootloader or blink sketch installed, see SAM-BA USB CDC Bootloader below.
  11. Plug in the board. The blink sketch should be running.
  12. Click Tools->Port and choose the COM port. Note that the board indicated may not match the chosen board*
  13. You can now upload your own sketch.

Currently, with MattairTech boards, USB PIDs are shared across boards (but they are different based on Tools->USB Config). This will result in Tools->Port showing "MattairTech Xeno Mini", for example, for all MattairTech boards.

Uploading the First Sketch

  1. In the Arduino IDE (1.6.7 or above), open File->Examples->01.Basics->Blink.
  2. Change the three instances of '13' to 'LED_BUILTIN'.
  3. Be sure the correct options are selected in the Tools menu (see Core Installation above).
  4. With the board plugged in, select the correct port from Tools->Port.
  5. Click the Upload button. After compiling, the sketch should be transferred to the board.
  6. Once the bootloader exits, the blink sketch should be running.

Beta Builds

Periodically, a beta is released for testing.

The beta builds are available through Boards Manager. If you want to install them:

  1. Open the Preferences of the Arduino IDE.
  2. Add this URL https://www.mattairtech.com/software/arduino/beta/package_MattairTech_index.json in the Additional Boards Manager URLs field, and click OK.
  3. Open the Boards Manager (menu Tools->Board->Board Manager...)
  4. Install MattairTech SAM D|L|C Core for Arduino - Beta build
  5. Select one of the boards under MattairTech SAM D|L|C Core for Arduino in Tools->Board menu
  6. Compile/Upload as usual

The Arduino IDE will notify the user if an update to the beta is available, which can then be installed automatically. If a particular beta is needed, just choose the version from the list. Alternatively, replace the url in step 2 with: https://www.mattairtech.com/software/arduino/beta/package_MattairTech_SAM_DLC_Core_for_Arduino-${VERSION}-beta-b${BUILD_NUMBER}_index.json or https://www.mattairtech.com/software/arduino/beta/package_MattairTech_sam_m0p-${VERSION}-beta-b${BUILD_NUMBER}_index.json (versions prior to 1.6.17-beta-b1) where ${VERSION} and ${BUILD_NUMBER} match the beta name as shown in the CHANGELOG (ie: package_MattairTech_sam_m0p-1.6.7-beta-b0_index.json). In this case, the IDE will not notify the user of updates, so this method is not recommended.

SAM-BA USB CDC Bootloader (Arduino compatible)

This bootloader is based on the Arduino Zero bootloader which is a part of the Arduino SAMD core. It provides a USB-CDC and/or TTL serial communications interface to a host running the bossac command line firmware programming utility (or the Arduino IDE) running on Windows, Linux, or OS X. Optionally, SD Card firmware loading is supported, using SDSC or SDHC cards with a FAT16 or FAT32 filesystem. This version adds support for the D51, L21, C21, and D11 microcontrollers. It also adds support for four different clock sources (two external crystals and two internal oscillator options). There are additional board definitions added, and binaries for most board/chip combinations are pre-built.

See bootloaders/zero/README.md for more technical information on the bootloader.

Features

The bootloader can be started by:

Otherwise, it jumps to application and starts execution from there. The LED will PWM fade during bootloader execution.

Bossac

Bossac is a command line utility for uploading firmware to SAM-BA bootloaders. It runs on Windows. Linux, and OS X. It is used by Arduino to upload firmware to SAM and SAMD boards. The version described here adds to the Arduino version (https://github.com/shumatech/BOSSA, Arduino branch), which in turn is a fork from the original Bossa (http://www.shumatech.com/web/products/bossa). It adds support for more SAM chips (D51, D21, L21, C21, and D11), support for four clock sources, and firmware loading from a MicroSD card.

Bootloader Firmware Installation

If you are installing the bootloader because you think you deleted/corrupted it by uploading a bad sketch in Arduino, check first by entering the bootloader manually (double-press reset) as it is probably just a broken sketch.

Bootloader Installation Using the Arduino IDE

  1. If you do not already have the MattairTech SAM D|L|C Core installed, see SAM D|L|C Core Installation above.
  2. Plug in the board. The bootloader must be running to (press reset twice within 500ms).
  3. Plug an Atmel ICE into USB, then connect it to the powered board. A green LED should light on the Atmel ICE.
  4. Click Tools->Programmer->Atmel ICE.
  5. Click Tools->Board->MattairTech Xeno Mini (or whichever board you are using).
  6. Click Tools->Microcontroller and select your MCU (if menu present).
  7. Click Tools->Burn Bootloader. Ignore any messages about not supporting shutdown or reset.
  8. Continue with driver installation above.

A running sketch may interfere with the bootloader installation process. Be sure you are running the existing bootloader or using a blank chip.

Bootloader Installation Using Another Tool (ie: Atmel Studio, openocd)

See bootloaders/zero/README.md for information.

Bootloader Binaries

The bootloaders/zero/binaries directory contains the SAM-BA bootloaders built by the build_all_bootloaders.sh script from the 'MattairTech SAM D|L|C Core for Arduino' Arduino core, which is available at https://github.com/mattairtech/ArduinoCore-samd. Each board and chip combination has two bootloaders available:

Using Bossac Standalone

See bootloaders/zero/README.md for information on using Bossac standalone.

New PinDescription Table

Technical information on the new PinDescription table format is now in the README.md that accompanies each board variant. See board variants above.

Note that in 1.6.18-beta-b1 a new compact table format was added.

The standard PinDescription table uses 12 bytes per pin. Define PIN_DESCRIPTION_TABLE_SIMPLE to use a more compact format that uses only 4 bytes per pin (currently only available for the D11 chips). In this case, the PinType, PinAttribute, and GCLKCCL columns are not used (they are not required). Additionally, the SetPortPin() and SetExtIntADC() macros are used to pack Port and Pin into the PortPin column, and ExtInt and ADCChannelNumber into the ExtIntADC column. Note that external libraries that reference the PinDescription table directly (uncommon) will no longer work. This define can be combined with the PIN_MAP_COMPACT define, which is available in variant.h of the D11 variants. This can save from 10's to over 200 bytes.

Note that a new column (GCLKCCL) was added for 1.6.8-beta-b0.

MATTAIRTECH_ARDUINO_SAMD_VARIANT_COMPLIANCE in variant.h is used to track versions. If using board variant files with the old format, the new core will still read the table the old way, losing any new features introduced by the new column. Additionally, new definitions have been added for D51, L21, and C21 support.

Each pin can have multiple functions.

The PinDescription table describes how each of the pins can be used by the Arduino core. Each pin can have multiple functions (ie: ADC input, digital output, PWM, communications, etc.), and the PinDescription table configures which functions can be used for each pin. This table is mainly accessed by the pinPeripheral function in wiring_private.c, which is used to attach a pin to a particular peripheral function. The communications drivers (ie: SPI, I2C, and UART), analogRead(), analogWrite(), analogReference(), attachInterrupt(), and pinMode() all call pinPeripheral() to verify that the pin can perform the function requested, and to configure the pin for that function. Most of the contents of pinMode() are now in pinPeripheral().

Pin Mapping

There are different ways that pins can be mapped. Typically, there is no relation between the arduino pin number used, and the actual port pin designator. Thus, the pcb must be printed with the arduino numbering, otherwise, if the port pin is printed, a cross reference table is needed to find the arduino pin number. However, this results in the least amount of space used by the table. Another method, used by default by the MT-D21E and MT-D11, maps Arduino pin numbers to the actual port pin number (ie: Arduino pin 28 = Port A28). This works well when there is only one port (or if the PORTB pins are used for onboard functions and not broken out). PIO_NOT_A_PIN entries must be added for pins that are used for other purposes or for pins that do not exist (especially the D11), so some FLASH space may be wasted. For an example of both types, see variant.cpp from the MT-D11 variant. The Xeno combines both methods, using the actual port pin designators from both PORTA and PORTB for arduino numbers 0-31 (ie: B1=1, A2=2), then using arduino numbering only above 31. For 0-31 only one pin from PORTA or PORTB can be used, leaving the other pin for some number above 31.

See Board Variants above for more technical information on the PinDescription table.

See WVariant.h for the definitions used in the table.

MattairTech Libraries

Available Now

Use Libraries Manager to install

Under Development

Possible Future

Core Future Additions/Changes

Under Development

Possible Future

Feature Requests

Please use the GitHub Issue Tracker if you would like to request a feature.

ChangeLog

The Changelog has moved to a separate file named CHANGELOG. The most recent changes are still in the 'What's New' section above.

Troubleshooting

Bugs or Issues

If you find a bug you can submit an issue here on github:

https://github.com/mattairtech/ArduinoCore-samd/issues

Before posting a new issue, please check if the same problem has been already reported by someone else to avoid duplicates.

Contributions

Contributions are always welcome. The preferred way to receive code cotribution is by submitting a Pull Request on github.

License and Credits

This core has been developed by Arduino LLC in collaboration with Atmel. This fork developed by Justin Mattair of MattairTech LLC.

  Copyright (c) 2015 Arduino LLC.  All right reserved.
  Copyright (c) 2017-2018 MattairTech LLC. All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Petit FatFS

Petit FatFs module is an open source software to implement FAT file system to small embedded systems. This is a free software and is opened for education, research and commercial developments under license policy of following trems.

Copyright (C) 2014, ChaN, all right reserved.