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:

MEMORY
{
  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?