ATSAMD21E15 Board Variant

I found some inexpensive SAMD21E15B chips with 32kb/4kb flash/ram... that sent me down a rabbit hole. I made a development board here.

I'd like to program them in the Arduino environment... here's what I've tried...

[u]Arduino Road[/u] First I tried selecting the Adafruit trinket board (its a ATSAMD21E18). Same pin out with 256kb/32kb flash/ram... but when I flashed the chip with the build file there was no USB enumeration or visual indication it was working.

I copied the trinket m0 board variant to a new folder and made minor changes.(great tutorial). I adjusted the linker memory addresses for flash/ram going from 256/32 to 32/4 (flash/ram). Shown without bootloader option below. These all compiled but with no USB enumeration or visual indication it was working.

256/32kb flash/ram

FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000

32/4kb flash/ram

FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x0004000
  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00001000

I left the below board file lines the same?


Modifying the below line to SAMD21E15 creates errors relating to SERCOM and USB.. Seems some of the Arduino SAMD core files are missing SAMD21E15 support. -DADAFRUIT_TRINKET_M0 -D__SAMD21E18A__ -DARM_MATH_CM0PLUS {build.usb_flags}


WVariant.h:239:36: error: 'TCC_INST_NUM' was not declared in this scope
SERCOM.h:215:3: error: 'Sercom' does not name a type
SAMD21_USBDevice.h:175:2: error: 'UsbDevice' does not name a type
SAMD21_USBDevice.h:178:34: error: 'UsbDeviceDescriptor' does not name a type
SAMD21_USBDevice.h:32:27: error: class 'USBDevice_SAMD21G18x' does not have any field named 'usb
... and a few more

[u]Atmel Studio[/u] Atmel 7 supports uploading Arduino board files only so the closest is the Arduino Zero (SAMD21G18). Maybe no advantage. For this chip I'd also have to modify the pins to match the SAMD21E15 and modify the size of the chip.

this way

holy crap. it worked. that was a little cleaner approach. I'll post the board variant files soon. thank you!!!

so... not 100% necessary but it would be cool to set up the bootloader. The standard genuino.bin doesn't work. It must just be these 2-3 LED pin definitions that could just be deleted. Haven't ran the MAKE command yet. Anything other necessary changes stick out?

wowa… hold up! I’m ending development on this chip.

The SAMD21E15 only has 32kb of flash. Fine for 8bit architecture but not for 32bit SAMD21 architecture!!

The below bit of code (about 50 lines) uses 332 bytes (12%) in for the UNO but compiles over 9,000 bytes (9248 bytes (56%)) for the SAMD21E15, SAMD21E16, SAMD21E17, etc

That means that I should have gone with the SAMD21E17 or SAMD21E18 with 128 or 256kb respectively.

digitalWrite(2, HIGH);  
digitalWrite(2, LOW);    

I’ll post my working board variant files here but I’m not working on any version with a bootloader for the SAMD21E15 32kB chip.

to burn the bootloader you need a programmer. if you have a programmer, you don't need a bootloader :-)

The SAMD21E15 only has 32kb of flash. Fine for 8bit architecture but not for 32bit SAMD21 architecture!!

The below bit of code (about 50 lines) uses 332 bytes (12%) in for the UNO but compiles over 9,000 bytes (9248 bytes (56%)) for the SAMD21E15

That's not as bad as it sounds - a sketch has a fair about of "fixed overhead" (an empty Zero sketch is 10k.) So you're seeing THAT rather than some huge "50 lines of code bloats to 9k of code" multiplier for 32bit RISC. You should be able to fit a pretty significant sketch into the 10k you have left... But yeah, most ARM libraries (not just the Arduino code, BTW) pretty much assume that you'll have lots of memory, and don't bother being very inefficient. (adding a tiny bit of floating point will use up another 9k.) (and 8k for a bootloader? Sheesh!)

cool, thanks for the info.

Yeah I ran out of memory after using adafruit_sensor.h library together with a tiny accelerometer library. It barely fit into 16kB after deleting some print statements. I hear the code is not efficient but it's what I'm used to!

Have you tried uploading code from the Arduino IDE?


i tried to flash a custom board using the SAMD21E17 MCU. As a bootloader I used the adafruit Trinket M0 bootloader (basically a atmel-ba with flash drive).

I did a setup similar to yours by modifying boards.txt and variant files to my needs. As that didn't work at all I found this threat and tried your setup with the blink example. When i try to upload I get an error message.

Sketch uses 10840 bytes (66%) of program storage space. Maximum is 16384 bytes.
Open On-Chip Debugger 0.10.0+dev-gf0767a31 (2018-06-11-13:36)
Licensed under GNU GPL v2
For bug reports, read
debug_level: 0
embedded:startup.tcl:60: Error: Can't find C:\Users\FMEC4TQ\Documents\Arduino\hardware\my_boards\samd/variants/samd21e15/{build.openocdscript}
in procedure 'script' 
at file "embedded:startup.tcl", line 60
the selected serial port at file "embedded:startup.tcl", line 60
 does not exist or your board is not connected

Any ideas what needs to be modified? Do I need to flash an other bootloader? [edit] read on your github page a bit and realized that you rely on SWD programming. Is it possible to flash via usb using bootloader as well? I guess I need to modify boards.txt. Is there any good documentation on that topic?

Cu Knochi