Newer
Older
The ATSAMD51 is an ARM Cortex-M4F microcontroller manufactured by Microchip (Atmel).

[Adafruit Feather M4](https://www.adafruit.com/product/3857)

[squidworks module](https://gitlab.cba.mit.edu/squidworks/moduleboard-atsamd51/)
## Toolchains
### Adafruit Bootloader / Platformio (or Arduino Compatible)
Since [Adafruit](https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51) has adopted the SAMD51, it is well supported by the open source community, and we can borrow their development tools.
**fair warning**
>Use of the arduino bootloader *does* assume that your circuit has a USB port available, as well as a 32.678kHz clock on the RTC Xout / Xin pins. During cycles, the bootloader (assuming it is on a Feather M4) will toggle 'D13' (PA23) as well as send Neopixel Data to (?).
To get started, find the latest build of the [adafruit bootloader] and download that (probably a `.bin` or `.elf` or `.hex` file).
We need to write this file into the micro's memory. I have been using the `Serial Wire Debug` interface, which is enabled by default on the D51 hardware (but JTAG is also available, but requires an enable pin pulled low somewhere *I think*). `SWCLK is on PA30` and `SWDIO is on PA31`.
To speak SWD, I just use the Atmel-Ice programmer, and Atmel Studio 7 (a windows application, sorry). Any programmer that speaks SWD should be capable of doing this. In Atmel Studio, go to `Tools -> Device Programming`, and select the Atmel-Ice Tool, the ATSAMD51xxxx device you'd like to program (the bootloader is written for the ATSAMD51J19A), and the SWD interface. You should be able to read the device signature. If this works, your SWD connection is all super-gucci (as they say). You can navigate to `Memories` - and write that bootloader in. OK. The device should now enumerate over USB as an Adafruit Feather M4 / FeatherBoot (or something similar).
### Platformio
To write code and load it, I use [PlatformIO](https://platformio.org/platformio-ide), which is an open source 'IOT' (embedded) programming tool written as a package for either [atom](https://atom.io/) code-editor, or [vscode](https://code.visualstudio.com/). See their doc for setting up a new project for the D51 / Feather M4.
### Real Registers in an Arduino World
One of the troubles with Arduino is that people forget that it is just a big C++ library. This means that everything under the sun (that compiles) is legal here. *That* means that we can use Arduino as a crutch, but write really nice Special Function Register code inside of the same executable. Great!