Lower memory SAMD21 variant

I would like to make my own board with using the SAMD21E17 (lower memory/flash variant of the SAMD21E18). Starting with the Adafruit Trinket M0 bootloader, I created a new device and updated the linker script. This builds and boots on my device, showing me the UF2 MSC volume.

I then created a new variant and updated flash_with_bootloader.ld and flash_without_bootloader.ld to have the smaller memory map:

  FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00020000-0x2000 /* First 8KB used by bootloader */
  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00004000

I compiled a program that works on my board when it has the SAMD21E18 (32 KB/256KB memory) in the Arduino 1.8.13 SDK and saved the .bin file. Flashing with latest release of BOSSA:

C:\Program Files (x86)\BOSSA>bossac.exe -p com5 -w -v -R --offset=0x2000 bias_with_offset.ino.trinket_m0-e17.bin Write 44716 bytes to flash (699 pages) [==============================] 100% (699/699 pages) Done in 8.488 seconds Verify 44716 bytes of flash [==============================] 100% (699/699 pages) Verify successful Done in 1.422 seconds

At this point the board disconnects and does not reconnect. Current meter shows the current dropping to zero, so I guess its crashed on boot.

I'm not sure how to troubleshoot the problem. I saw some posts suggesting that BOSSA might have compatibility issues, but since it is able to verify the code, I think that is probably not the issue. Is there something else I need to change?

@mgiacomelli2 Here's a link to a discussion about the SAMD21G17A bootloader considerations: https://forum.arduino.cc/t/128k-vs-256k-atsamd21/577071.

@mgiacomelli2 It might also be worth checking out Rabid Prototype's Tau board core code. It uses the SAMD21E17A as well: https://rabidprototypes.com/product/tau/.

Thanks, I read through that thread initially, and it was helpful in figuring out where to look. However, there is apparently more since it doesn't seem like anyone in that thread solved the issue. I have also been digging through the Tau files, but they're hard to compare since its based on a much older fork of the Arduino Zero, while their board is configured with an external oscillator so I cannot directly test their binaries. They also distribute their own version of BOSSA, which is old, but unclear if it is modified.

I'm going to keep digging into the code, but since the bootloader seems to be working, I was hoping I could figure out why it crashes running sketches.

The old Tau BOSSA seems to work differently. Rather then crash, it reboots back to the bootloader. Mounting the MSC drive, I can copy the current.UF2 file and see that the Arduino sketch was written to the flash. However, it doesn't seem to actually run.

Dumb question, but is there a way to install the bootloader and sketch together rather then flashing the bootloader and then sending the sketch over?

for SAMD21E17D any bootloader available?

The SAMD21E18A is supported, (Adafruit Trinket M0 and Qt PY).

Is there a special reason for using the SAMD21E17D?

17D was the only chip available in stock
i tried with 17A bootloader but not worked

@nijupp24 Do you have a particular Arduino compatible board that you've based your custom design on?

Yes , i designed a custom board ,i already tried with couple of 17A bootloader i was able to load it but programming time arduino is giving error (comx no device found)

i think the error coming because i used 17A bootloader and 17D ic???

I spent a weekend trying to get the bootloader running on the 17. After a lot of hacking I could get the UF2 partition to load, but it would always crash when trying to run a sketch. I never figured out what the problem was.

Did you move the address of the double tap reset "magic number" to the last 4 bytes of RAM?

So how are you going about programming the board?

Are you using the Arduino IDE and if so, which board type from the Board's Manager do you select to program it?

Yes, I updated that and several other things in both of the bootloader memory maps. This enabled the bootloader to work (without that it just crashes on start, probably because the magic number generates an exception when writing to nonexistent memory), but I never got sketches working.

I was using 2 below boards path in Arduino which will support 17A ic

  1. Tau | Rabid Prototypes

  2. GitHub - wagiminator/SAMD-Development-Boards: Collection of SAMD Development Boards, Programmers, Tools and Firmware

Bootloader programming through j link via Atmel studio 7

Hi @nijupp24

Does your custom board use an external 32.768kHz crystal?

It's just that I noticed that the Tau/Firecricket use an external crystal. However, it's also possible to alternatively run microcontroller from its internal 32.768kHz oscillator. If your board is running crystalless then it's necessary to specify this in the bootloader's board definition file.

yes i also used a 32kHz

Hi @mgiacomelli2

Creating a new variant and updating the linker scripts in itself isn't enough, unless you're just modifying the files of an existing board. It necessary to also create a new entry for your new board in the Arduino IDE.

It's a bit out-of-date, by here's a guide that shows you what it entails: https://forum.arduino.cc/t/adding-custom-zero-based-boards-to-the-arduino-ide/394499.

There's another guide here: https://www.instructables.com/Arduino-IDE-Creating-Custom-Boards/

@nijupp24 I've attached a binary for a minimal SAMD21 bootloader for a device with 16KB RAM with only native USB support. It has neither LED status outputs nor auxiliary serial port upload. It also boots crystalless, irrespective of whether your board's got a crystal or not.

I've successfully tested it on my SAMD21G18A based custom board, using it to upload a "Blink" sketch, including double tap reset to put the microcontroller into bootloader mode. So I can confirm that it all works.

samd21_sam_ba.zip (4.7 KB)