Atmel SAMD21 Bootloader Issues

Hi @Callum_Austin11

Looks like the upload was successful, but the bootloader code encountered a problem.

Please find attached a minimal bootloader for the G15A, native USB only, runs crystalless, irrespective of whether your board has a crystal or not, plus all LEDs are disabled:

samd21_sam_ba.zip (4.7 KB)

Thanks for that bootloader. I used atmel studio 7 to upload it using an external EDBG Chip. So now going back to arduino IDE. It shows up on the port, (COM 6 Arduino Zero Native Port). However, when I go to upload a sketch I get this on the output; (Just trying to upload simple Blink Example Sketch)

Forcing reset using 1200bps open/close on port COM6
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
Uploading using selected port: COM6
C:\Users\SMS\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3/bossac.exe -i -d --port=COM6 -U true -i -e -w -v C:\Users\SMS\AppData\Local\Temp\arduino_build_180595/Blink.ino.bin -R 
Set binary mode

readWord(addr=0)=0x20000ffc
SAM-BA operation failed
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10011524
version()=v2.0 [Arduino:XYZP] Oct 20 2021 15:22:27
chipId=0x10010024
Connected at 921600 baud
readWord(addr=0)=0x20000ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10011524
Atmel SMART device 0x10010024 found
write(addr=0x20000800,size=0x34)
writeWord(addr=0x20000830,value=0x10)
writeWord(addr=0x20000820,value=0x20001000)
Device       : ATSAMD21G15B
readWord(addr=0)=0x20000ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10011524
Chip ID      : 10010024
version()=v2.0 [Arduino:XYZP] Oct 20 2021 15:22:27
Version      : v2.0 [Arduino:XYZP] Oct 20 2021 15:22:27
Address      : 8192
Pages        : 384
Page Size    : 64 bytes
Total Size   : 24KB
Planes       : 1
Lock Regions : 16
Locked       : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security     : false
Boot Flash   : true
readWord(addr=0x40000834)=0x7000a
BOD          : true
readWord(addr=0x40000834)=0x7000a
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 0.109 seconds

Write 11440 bytes to flash (179 pages)
write(addr=0x20000c00,size=0x1000)
An error occurred while uploading the sketch

Hi @Callum_Austin11

Might I ask if you're using a SAMD21G15A or SAMD21G15B?

It's just that the bossac.exe that I provided in the link only supports the former.

Hi Martin, Yes im using the SAMD21G15B

@Callum_Austin11 It looks like the latest version 1.9.1 of Shumatech's orginal Bossa supports the SAMD21G15B: https://github.com/shumatech/BOSSA/releases/tag/1.9.1.

Here's the executable:

Removed

Hopefully this should work. Bossa checks the microcontroller's device ID, so (any given version of it) is quite particular about which devices it supports.

Hi Martin, I downloaded the new bossac.exe like you said.
Still no succession, get this on the output now;

Forcing reset using 1200bps open/close on port COM6
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
PORTS {COM4, COM6, } / {COM4, COM6, } => {}
Uploading using selected port: COM6
C:\Users\SMS\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3/bossac.exe -i -d --port=COM6 -U true -i -e -w -v C:\Users\SMS\AppData\Local\Temp\arduino_build_428772/Blink.ino.bin -R 
bossac.exe: extra arguments found
Try 'bossac.exe -h' or 'bossac.exe --help' for more information
An error occurred while uploading the sketch

Hi @Callum_Austin11

Just to comfirm, did the bootloader upload successfully using the programmer?

Do you get a valid COM port in the Arduino IDE, if you double tap the board's reset button?

Hi Martin, Yes I do get a valid COM port, Shows as COM 6 (Arduino Zero (native USB port))

Hi @Callum_Austin11

I tested this version of bossac.exe on my SAMD21G18A board and it generates the same error. There must be an issue with this particular exexcutable.

Ah I see, is there an earlier version that can be used?

What I stated was wrong.

It looks like the bossac.exe that I orginally linked to does support the SAMD21G15B: https://forum.arduino.cc/t/lower-memory-samd21-variant/890009/37.

This also works with my custom SAMD21G18A board.

I think it's worth going back to that version. From your upload output, it looks like it has something to do with the microcontroller's memory.

Thats okay martin, at least we've figured out that issue out. The original bootloader you gave me, how would you upload that to the chip, would you also use Atmel Studio or would you do it through Arduino IDE? I'm not entirely sure where to put the file or access it if done from the Arduino IDE.

I'd do that through Atmel Studio, using the menu Tools->Device Programming, select your programmer, then click on the "Apply" button followed by the "Read" button, to detect your target device.

Go to the memories section and in the top text box enter the path to the bootloader binary. This should then erase, program and verify the bootloader upload.

Okay thats good, I've done exactly that. So the bootloader you've created is for the Arduino Zero Native Port, I know this is sounding picky, but is there anyway to change it so the bootloader is for the Arduino MKRZERO instead? If its too much to ask then I'll make do.

So I don't think the USB part is working. I've had the EDBG Chip connected the entire time and when you turn that off, COM 6 disappears even though I still have a USB connected directly to the SAMD21G15B Chip?

I believe you just need to change the BOARD_ID on line 60 in the Makefile from "arduino_zero" to "arduino_mkrzero", this should then switch the boards definition file over to the MKR Zero's.

Once the bootloader's uploaded, you should be able to remove the programmer and upload from the Arduino IDE over the microcontroller's native USB port.

Yeah that bit doesn't work, it doesn't like it when you remove the programmer. Even though you select COM 6 on the port when uploading sketches it seems as though it uploads through the programmer still

I uploaded the modified bootloader and used the replacement bossac.exe, together with Arduino SAMD core setup for 32KB flash and 4KB RAM on my SAMD21G18A custom board.

It all functioned successfully, so it should work OK.

I'll install the SAMD Package again on Arduino IDE, then go through the steps again. I'll let you know how I get on tomorrow. Should I try a brand new chip and see if that works as well?