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?
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?
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.
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.
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.
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.
@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.