Go Down

Topic: ATSAMD21E15 Board Variant (Read 691 times) previous topic - next topic

hydronics

Mar 08, 2019, 09:01 pm Last Edit: Mar 08, 2019, 09:02 pm by hydronics
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...

Arduino Road
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
Code: [Select]

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


32/4kb flash/ram
Code: [Select]

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


I left the below board file lines the same?

Code: [Select]
adafruit_trinket_m0.upload.offset=0x2000
adafruit_trinket_m0.vid.0=0x239A
adafruit_trinket_m0.pid.0=0x801E
adafruit_trinket_m0.vid.1=0x239A
adafruit_trinket_m0.pid.1=0x001E
 


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.

Code: [Select]
adafruit_trinket_m0.build.extra_flags=-DCRYSTALLESS -DADAFRUIT_TRINKET_M0 -D__SAMD21E18A__ -DARM_MATH_CM0PLUS {build.usb_flags}

Errors:
Code: [Select]

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



Atmel Studio
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.


hydronics

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

hydronics

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?

https://github.com/arduino/ArduinoCore-samd/blob/master/bootloaders/zero/board_definitions_genuino_zero.h

hydronics

#4
Mar 10, 2019, 05:06 am Last Edit: Mar 10, 2019, 05:08 am by hydronics
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.

Code: [Select]

SerialUSB.println("hello");
Serial1.println("hello");
digitalWrite(2, HIGH); 
delay(500);               
digitalWrite(2, LOW);   
delay(500);               
SerialUSB.println("hello");
Serial1.println("hello");


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.

https://github.com/hydronics2/samd21_QFP_reference_PCB


Juraj

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

westfw

Quote
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!)

hydronics

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!

Go Up