Floating Point Unit support

I'm making steady progress on modifying the Arduino IDE, in order to integrate the SAMD51.

There are three main issues:

1. Arduino IDE Boards Manager

The standard way to add new boards to the Arduino IDE, is to provide the web address (or URL) of a JSON file. The Arduino IDE uses this to configure its Boards Manager.

I couldn't find a JSON file in the Adafruit code and rasied the issue with them on Github. It turns out that they're currently not providing any JSON file support, so I'm currently in the process of writing my own.

I'll also eventually modify the "variant.cpp" file that defines the board's pin functions, as my SAMD51 target board pinout is closer to the Arduino Zero than Adafruit's Metro M4.

2. Atmel CMSIS

The Atmel CMSIS includes the register definitions for the microcontrollers.

The Arduino IDE also currently lacks the SAMD51 register definitions, so I've included them. These are the "samd51" directory, as well as modified "sam.h" and "samd.h" files.

3. Adafruit's Modified Bossa 1.7.0

Bossa is a program used by Arduino IDE to upload the code on to their boards using the native USB port.

Adafruit have also forked and modified Bossa Version 1.7.0, to make it compatible with the SAMD51. The bossac executable files are located in the "Tools" directory of their Metro M4 code. I've replaced the Arduino IDE's current "bossac.exe" file with the modified one. It appears to work OK with the SAMD21.

Did you see the pull request to add the SAMD51 CMSIS to Arduino CMSIS repository?

Hi dlabun,

Did you see the pull request to add the SAMD51 CMSIS to Arduino CMSIS repository?

adding support for SAMD51 by deanm1278 · Pull Request #8 · arduino/ArduinoModule-CMSIS-Atmel · GitHub

Yes I did. I guess it's likely that SAMD51 CMSIS files will be supported in the next version of the Arduino IDE, or maybe already are with the hourly builds.

For now I just got the SAMD51 files from the Adafruit's "ArduinoModule-CMSIS-Atmel" repo on Github.

By the way, I've got the boards manager going...

SAMD51 Board.jpg

SAMD51 Board.jpg

Have you figured out the differences between the SAMD5x and the SAME5x? They seem to have the same datasheet - I guess D5x is supposed to be an upgrade of D2x, while E5x is a cheaper E7x?

There's a development board for the E54... https://www.digikey.com/product-detail/en/microchip-technology/ATSAME54-XPRO/ATSAME54-XPRO-ND/7354381

Sketches on the Arduino IDE now compile for the SAMD51 without errors, but with warnings.

The warnings stem from the fact that Atmel rather than using the simple "ul" (unsigned long) suffix, as in their previous CMSIS register definitions, for example the SAMD21, they have decided instead to use _U(x), _L(x) and _UL(x) macros.

The macros themselves just use the ## preprocessor directive to move the parameter 'x' to the front and "UL" to the back:

_UL(x) x ## UL

However, the use of _U and _L naming is unfortunate, as these have already been defined in the ARM GCC Toolchain file "ctype.h", leading to a double definition that's causing the compiler warnings.

It appears that others are having the same issue:

...there is one more issue with the new header files we've just found. Chip header files like same70q21.h define _U, _L, _UL macros in the following manner

#if !defined(_UL)
#define _U(x) x ## U
#define _L(x) x ## L
#define _UL(x) x ## UL
#endif /* !defined(UL) */

However, some toolchains define _U but not _UL. That leads to a double definition of _U, _L macros.

It begs the question, why is Atmel using macro names that conflict with their own microcontoller's C++ code?

I'm trying to figure out if there's a simple workaround?

@westfw, According to Atmel the biggest difference is that the E series has the Ethernet and CAN controllers while the D series does not.

I amended the _U and _L macro names in the SAMD51 Atmel CMSIS file to _UI (unsigned int) and _SL (signed long) respectively.

A blank sketch (empty setup() and loop()) now compiles without warnings or errors.

The SAMD51D20A chips I ordered have arrived.

Adafruit have now added support for the SAMD51's hardware FPU.

Thanks for the update... I wonder if that's a sign they are going to be releasing their boards soon.

Finally managed to get the SAMD51J20A working with the Arduino IDE.

It'll certainly be interesting to see how this 120MHz, ARM-Cortex M4F microcontroller performs.

This is all thanks to the engineering effort by Adafruit, building upon the considerable work carried out by Arduino for the SAMD21 and in many ways shows the benefits, (at least in this instance), of open source development.

Getting it going at this early stage of development was quite involved though, I need to:

  1. Zip up Adafruit's SAMD51 code and write a JSON file, to create a new entry in the Arduino IDE boards manager, so that the new board and code could be installed.

  2. Copy the modified "sam.h" and "samd.h", as well as add the "samd51" directory from Adafruit's Atmel CMSIS Github repository, to the Arduino IDE's Atmel CMSIS directory.

  3. Copy Adafruit's modified bossac executable found their SAMD51 code's "Tools" directory, to replace the Arduino IDE's "bossac.exe" file in its "1.7.0" directory.

  4. Upload the bootloader to the SAMD51 board using an Atmel ICE programmer and Atmel Studio (Tools->Device Programming->Memories), then selecting the path to the "samdx1_sam_ba.bin" bootloader file.

As the code is still under development, I'd suggest that it's probably easiest to wait until Adafruit's Metro M4 board becomes available and there's full support for the Arduino IDE.

In terms of hardware, I simply soldered the 64-pin, SAMD51J20A in a TQFP package to my custom board designed for the SAMD21J18A. The main difference is that SAMD51's VDDCORE pin is located two pins down with respect to the SAMD21 and that it's now recommended to connect a 4.7uF capacitor from this pin to ground, rather than the 1uF that was there for the SAMD21. This just required a slight modification replacing the capacitor and re-routing it to the new VDDCORE pin.

I'm now rewriting the "variant.cpp" files to recofigure the pin functions, as my custom board more closely matches the Arduino Zero, rather than the Metro M4.

Thanks for the update... I wonder if that's a sign they are going to be releasing their boards soon.

Adafruit are currently saying that the Metro M4 is scheduled for November. Hmm..., perhaps one to add to my Santa's wish list?

Zip up Adafruit's SAMD51 code and write a JSON file, to create a new entry in the Arduino IDE boards manager, so that the new board and code could be installed.

You don't HAVE to have a JSON file. You can still copy new directories into the hardware/ tree directly. I've got a 1.8.2 IDE with espressif ESP32 and SAMD11 boards added that way...

You don't HAVE to have a JSON file. You can still copy new directories into the hardware/ tree directly. I've got a 1.8.2 IDE with espressif ESP32 and SAMD11 boards added that way...

Thanks for this information. I didn't know that simply copying the files would work.

I did try to copy the files across at the start, but I guess I must have placed them in the incorrect directory, as they weren't picked up by the IDE and I ended up going down the unnecessary harder route, (not for the first time).

This certainly simplifies this first step.

Speaking of the SAMD51, I've been putting together this spreadsheet describing the available pin functions:
Google Docs SAMD51 Pinout
I find it especially useful to be able to sort on a particular columns; otherwise it's mostly a copy of the table from section 6.1 of the manual.
(Light gray sections are incomplete, and/or copied from a similar SAMD21 spreadsheet (and thus perhaps inaccurate.)

Thank you for your spreadsheet. With the port pins in ascending order, I find it much easier to read than the datasheet table.

So far I've successfully tried out the I2C Wire library and SerialUSB with the SAMD51. I managed to get it reading back raw accelerometer/gyroscope values from a MPU-9250 sensor, using the I2C bus in fast mode (400kHz) and displaying them on the Arduino IDE console.

I also replicated the test that Limor Fried did in her Adafruit video about the SAMD51, using successive calls to the OUTTGL (output toggle) register, to bit bang the GPIO output at 30MHz!

The SAMD51 also offers more in the way of timers and channels, the SAMD51J20A has 6, 16-bit TC timers (TC0...TC5) with two channels each. In addition, it has 5 TCC timer channels for PWM (TCC0..TCC4), with 6, 4, 3, 2 and 2 channels respectively. This is in addition to the standard on-chip Systick and RTC timers.

There is one issue however and it's to do with the SERCOM Tx pin on the SAMD51. On each SERCOM there are are 4 pads (0..3) that in the case of the USART configuration can be assigned to TX, RX, CTS and RTS, and for the SPI configuration to SCLK, MISO, MOSI and SS.

The SERCOM peripherals' pads are located on the same pins on both the SAMD21 and SAMD51 devices. On the SAMD21 it's possible to mix 'n' match practically any SERCOM signal to any pad. On the SAMD51 however, while the RX/MISO signal can be assigned to any pad, the USART's TX output is limited to the pin at pad 0 and the SPI's MOSI can only output on the pin at pads 0 or 3.

The consequence is that if you're designing a custom board using SAMD51, it limits the flexibility of which pins you can use as a USART TX or SPI MOSI. It also reduces the viability of the SAMD51 as a simple plug in replacement for the SAMD21.

Overall though, I guess this slight reduction in pin flexibility is a small price to pay for the SAMD51's increase in performance.

The SERCOM peripherals' pads are located on the same pins on both the SAMD21 and SAMD51 devices. On the SAMD21 it's possible to mix 'n' match practically any SERCOM signal to any pad. On the SAMD51 however, while the RX/MISO signal can be assigned to any pad, the USART's TX output is limited to the pin at pad 0

Huh. I had noticed that UART TX was limited to Pad0, but not that this was different than the SAMD21. (come on. a Sercom should be the same on all devices! Grr...) Even on the D21, you only have a choice between Pad0 and Pad2, so it's still not great...

Looks like Adafruit are in the process of manufacturing their prototype Metro M4 boards: Adafruit Prototyping League tackles the Metro M4 #ManufacturingMonday (video) « Adafruit Industries – Makers, hackers, artists, designers and engineers!.

From their Gibhub SAMD51 repo, it also looks like they're also planning on a Feather M4. I believe that these initial boards will use the SAMD51J19A, 64-pin device with 512K flash and 192K RAM.

Adafruit's code now allows you to seamlessly upload code to the SAMD51 via the native USB port using the Arduino IDE. I've now ported the firmware from my SAMD21, Arduino Zero based flight controller over to the SAMD51 and have successfully flown the new microcontroller in a tricopter frame. I'm using the SAMD51J20A, 64-pin device with 1M flash and 256K RAM.

The SAMD51 is similar to the SAMD21 pinout in terms of power and port pins, except for a three way swap of the VDDCORE, PA27 and VSW pins, used for microcontroller's internal regulated supply. Like the SAMD21 it also uses the same 32.768kHz crystal.

Internally the SAMD51 uses a digital frequency locked loop to generate a 48MHz clock source, this is then divided down and ramped up to 100MHz and 120MHz using two fractional digital phase locked loops. All these clocks are available as sources for the microcontroller's internal peripherals. Having the 48MHz clock source is nice, as it allows peripherals to be clocked at the same rate as the SAMD21. The 100MHz clock is necessary, as this is the maximum clocking frequency of some of the internal peripherals such as the SERCOM modules. The 120MHz clock drives the processor core.

From an Arduino point of view the code runs exactly the same as the SAMD21, just around 2.5 times faster. If your sketch uses a lot of single precision floating point calculations, it'll run faster still, on account of the microcontroller's hardware FPU (Floating Point Unit).

For those using register manipulation, some of the peripherals like the SERCOM remain almost identical to the SAMD21, while others remain strangely familiar, but different. The TC timers for example are now more akin to the TCC timers in terms of operation.

The SAMD51 isn't just a turbo-charged version of the SAMD21 though. It has more memory, dual ADC and DAC, multiple interrupt handlers per peripheral, more timers and timer channels, plus a number of other specialised on-board peripherals not available on the SAMD21. The only main disadvantage that I've found with respect to the SAMD21, is the lack of flexibility with regard to multiplexing of the SERCOM's transmit pin, but this is only really a circuit board layout issue.

The other nice thing about the SAMD51 and SAME51 families is that they're available 48, 64, 100 and 128-pin packages. This makes it possible to produces various sizes of board, while leveraging a single SAMD code base. In this regard, Adafruit have also mentioned about making a Mega sized board with the SAMx51 100-pin variant.

westfw, GREAT JOB ON THE MAPPING.

Using it to review my own. i know it's a few months later but do you still use it.
maybe it's usefull to you : PA12 & PA13 alternate COM show a different PAD#
not done yet but wanted to know if you are actively using it.

I was just about to start a schematic with the SAMD21G and will most likely use the J version now.
Making sure my board would also work with the D51/E5x

E

PA12 & PA13 alternate COM show a different PAD#

Ah. Pad 1/0 instead of Pad 0/1. Thanks for the update!

wanted to know if you are actively using

No. I didn't even get very far on the "which pins would go where, best, for a due-sized board" idea that I was thinking about.
I've decided my short term interest is in some of the 5V ARM chips, like SAMC and MKE02

@westfw, nice job on the spreadsheet. It looks like you corrected PA12/13 COM (O23:24) as per the docs. N23 and N24 should be swapped as well since TX is only available on pad 0.

Has anyone verified that PA12/13 SERCOM4 pads were actually swapped or was this a documentation error? That's a pretty good OOPS if they physically swapped since you would have to make board level changes if using SERCOM4.

@westfw, did you do a similar spreadsheet for the D21? It would be nice to compare the D21 and D51 via spreadsheet.

Robin