Atmel SAMD21J prototype
Arduino and Atmel teamed up to create the Arduino Zero, and M0 development boards. The SAMD21 series of ARM Cortex M0+ micro-controllers are an ideal upgrade from the Atmel AVR processors. The SAMD21G18A used in the Arduino has 16 times the static ram, and 4 times the flash memory of the atmega328 used in the Arduino Uno. It's a shame that nearly half of the chips available I/O lines available on the 48 pin package are not brought out to pins on the Zero/M0 boards (though quite a few of them are used to connect to the on board embedded debugger processor).
The processor is available in a 32 pin package that sports 26 I/O pins. With two of these dedicated to the 32khz crystal (which while not necessary because of the processor's on board calibrated internal R/C oscillator, is a good idea to meet the timing of the USB interface), two lines used by the USB interface, two by the SWD programming interface, and one for the A/D reference, that leaves 19 available I/O lines (the UNO has 20 brought out), although the SWD pins can be used for I/O when the chip isn't being programmed. So the 32 pin package COULD have been used on the UNO. However, the cost difference was so small, and the package size wasn't an issue, so they went with the next largest size.
The 64 pin package offers up to 56 I/O pins, and actually costs only pennies more than the 48 pin part. With the SAMD21 officially supported by the current Arduino IDE (no longer in BETA either), I got the idea into my head of tying to port the Marlin 3D printer firmware over to this part. The UNO does not have enough I/O to support typical 3D printer needs, but the 64 pin SAMD21 does.
I figured the first step would be to get a prototype development lashup working on a breadboard with the Arduino bootloader and start writing some test sketches to debug the required libraries. The first questions I had were how do I modify the Arduino bootloader to work on the larger part, how do I burn the bootloader onto the chip, and what changes do I have to make to the IDE for the larger part? As it turned out, Adafruit already had answers to those questions up on her website.
Both Adafruit and Sparkfun sell their own clones of the Arduino Zero in a smaller footprint (Sparkfun also sells a UNO compatible sized board minus the debugger port). Both companies also have the sources to their bootloader firmware and Arduino Variants on github.
After studying the source code to the bootstrap, I soon realized that the ONLY thing I'd need to do was to change the definition for the CPU type in the makefile. As it turns out there aren't any differences between the internals of the SAMD21 across the three different pinouts. In fact, all three parts might even use the same die, with unused pin pads simply not being connected.
As for the second issue, programming the chip, I had a few choices. I'd need a SWD capable programmer, and an application to drive it. Atmel recommends their Atmel-ICE and Atmel Studio. Fine, if you're running Windows, but what about Linux? OpenOCD seems to be the answer, with a compatible programmer. Atmel-ICE is a non starter on Linux though that might change eventually. The other choices are J-Link, St-Link, and OpenOCD big-banging port pins on a RaspberryPi (or Beaglebone Black). Adafruit even has a tutorial and a YouTube video on how to do this with the RPi.
I had an old Raspberry Pi (the original model B with 256MB of ram), so I loaded the latest Raspbian Jessie on it and built OpenOcd from source. I also found a used Atmel SAM-ICE on ebay (it's actually an OEM branded version of the J-Link that will only work with Atmel parts). Once I got it, it turned out that the HW was too old to support SWD, it will only play with parts that have a full JTAG interface (which the SAMD does NOT). $75 down the drain. I then bought a Chinese clone J-Link SWD (small PCB that ONLY does the J-Link SWD protocol) for about $7 off of Ebay.
Now Soldering a QFTP package with 0.5mm pin spacing isn't for the faint of heart. (I've done it before with Atmel atmega2560 chips). This time around, I used a 64pin QFTP to DIP adapter made by Schmartboard. I can't recommend the Schmartboard products enough. The chip fits into a well on the pcb, and the solder pre-tined pads are groved to match the pins. All you have to do is reheat and reflow the solder with a fin tipped soldering iron, It's nearly impossible to make a solder bridge or misalign the part. For $7 (Mouser) you get the adapter board and the pins to fit a standard breadboard. (They also sell them in a pack of two with a breadboard for $1 more than the cost of the two adapters).
For some reason, even though OpenOcd on the RPi did recognize my chip the first time I had them connected together, I could not repeat the performance to burn the bootloader as per Adafruit's instructions. So I simply swapped the configuration from the Pi to J-Link, and tried my Chinese clone programmer. Success! Next I hooked the board to my PC and opened up the Arduino IDE. I was able to get the 'blink' example working. Later I tried Adafruits SSD1306 example with a surplus I2C OLED panel, and then I interfaced an SD card and tried that sketch example. All worked fine. The only glitch is that the bootloader is a bit flaky, I sometimes have to exit the IDE and restart it to get the bootloader to connect with the IDE. Probably a timing issue, or the IDE doesn't let go of the driver and complains the port is busy. Opening and closing the serial monitor sometimes clears this as well. (And maybe Windows won't have the problem?).
My next step will be to design a proper breakout board for the SAMD21. It will have a 3.3 volt regulator, a USB socket, and I'll add a 16kb (2k byte) I2C eeprom. (The SAMD21, like most ARM parts does NOT have on board EEprom like the AVR's do. The Arduino IDE can emulate this using the program flash, but there are some issues with this.) I'm thinking of a form factor similar to the Adafruit Feather, only larger. (Horse-Feather?)
The processor is available in a 32 pin package that sports 26 I/O pins. With two of these dedicated to the 32khz crystal (which while not necessary because of the processor's on board calibrated internal R/C oscillator, is a good idea to meet the timing of the USB interface), two lines used by the USB interface, two by the SWD programming interface, and one for the A/D reference, that leaves 19 available I/O lines (the UNO has 20 brought out), although the SWD pins can be used for I/O when the chip isn't being programmed. So the 32 pin package COULD have been used on the UNO. However, the cost difference was so small, and the package size wasn't an issue, so they went with the next largest size.
The 64 pin package offers up to 56 I/O pins, and actually costs only pennies more than the 48 pin part. With the SAMD21 officially supported by the current Arduino IDE (no longer in BETA either), I got the idea into my head of tying to port the Marlin 3D printer firmware over to this part. The UNO does not have enough I/O to support typical 3D printer needs, but the 64 pin SAMD21 does.
I figured the first step would be to get a prototype development lashup working on a breadboard with the Arduino bootloader and start writing some test sketches to debug the required libraries. The first questions I had were how do I modify the Arduino bootloader to work on the larger part, how do I burn the bootloader onto the chip, and what changes do I have to make to the IDE for the larger part? As it turned out, Adafruit already had answers to those questions up on her website.
Both Adafruit and Sparkfun sell their own clones of the Arduino Zero in a smaller footprint (Sparkfun also sells a UNO compatible sized board minus the debugger port). Both companies also have the sources to their bootloader firmware and Arduino Variants on github.
After studying the source code to the bootstrap, I soon realized that the ONLY thing I'd need to do was to change the definition for the CPU type in the makefile. As it turns out there aren't any differences between the internals of the SAMD21 across the three different pinouts. In fact, all three parts might even use the same die, with unused pin pads simply not being connected.
As for the second issue, programming the chip, I had a few choices. I'd need a SWD capable programmer, and an application to drive it. Atmel recommends their Atmel-ICE and Atmel Studio. Fine, if you're running Windows, but what about Linux? OpenOCD seems to be the answer, with a compatible programmer. Atmel-ICE is a non starter on Linux though that might change eventually. The other choices are J-Link, St-Link, and OpenOCD big-banging port pins on a RaspberryPi (or Beaglebone Black). Adafruit even has a tutorial and a YouTube video on how to do this with the RPi.
I had an old Raspberry Pi (the original model B with 256MB of ram), so I loaded the latest Raspbian Jessie on it and built OpenOcd from source. I also found a used Atmel SAM-ICE on ebay (it's actually an OEM branded version of the J-Link that will only work with Atmel parts). Once I got it, it turned out that the HW was too old to support SWD, it will only play with parts that have a full JTAG interface (which the SAMD does NOT). $75 down the drain. I then bought a Chinese clone J-Link SWD (small PCB that ONLY does the J-Link SWD protocol) for about $7 off of Ebay.
Now Soldering a QFTP package with 0.5mm pin spacing isn't for the faint of heart. (I've done it before with Atmel atmega2560 chips). This time around, I used a 64pin QFTP to DIP adapter made by Schmartboard. I can't recommend the Schmartboard products enough. The chip fits into a well on the pcb, and the solder pre-tined pads are groved to match the pins. All you have to do is reheat and reflow the solder with a fin tipped soldering iron, It's nearly impossible to make a solder bridge or misalign the part. For $7 (Mouser) you get the adapter board and the pins to fit a standard breadboard. (They also sell them in a pack of two with a breadboard for $1 more than the cost of the two adapters).
For some reason, even though OpenOcd on the RPi did recognize my chip the first time I had them connected together, I could not repeat the performance to burn the bootloader as per Adafruit's instructions. So I simply swapped the configuration from the Pi to J-Link, and tried my Chinese clone programmer. Success! Next I hooked the board to my PC and opened up the Arduino IDE. I was able to get the 'blink' example working. Later I tried Adafruits SSD1306 example with a surplus I2C OLED panel, and then I interfaced an SD card and tried that sketch example. All worked fine. The only glitch is that the bootloader is a bit flaky, I sometimes have to exit the IDE and restart it to get the bootloader to connect with the IDE. Probably a timing issue, or the IDE doesn't let go of the driver and complains the port is busy. Opening and closing the serial monitor sometimes clears this as well. (And maybe Windows won't have the problem?).
My next step will be to design a proper breakout board for the SAMD21. It will have a 3.3 volt regulator, a USB socket, and I'll add a 16kb (2k byte) I2C eeprom. (The SAMD21, like most ARM parts does NOT have on board EEprom like the AVR's do. The Arduino IDE can emulate this using the program flash, but there are some issues with this.) I'm thinking of a form factor similar to the Adafruit Feather, only larger. (Horse-Feather?)