Problems uploading bootloader to ATSAMD21 and programming with Arduino

Hi guys, I have a custom board with an Atmel ATSAMD21E18A. I'm using a JLink and Atmel Studio to upload this bootloader. Arduino IDE recognises the board as Atmel ATSAMD21E18A (Native USB Port), but when I try to upload a sketch, it says 100% finished and the board disappears from USB devices and does not re-appear until I re-upload the bootloader again. Ie. I can't get any Arduino sketches to work. I have also tried the Adafruit Feather M0 bootloader, which doesn't appear in the USB devices at all upon insertion. I can successfully get Atmel Studio examples to work though. What am I doing wrong?

Hi Fyod,

I've used the Arduino/Genuino Zero's bootloader on a custom board using the larger ATSAMD21J18A without any issues.

I uploaded the bootloader via the SWD port using the Arduino IDE.

I'm not having a problem with the bootloader per-se. Rather the Arduino sketch upload. Here's my procedure: MCU shows up in Atmel Studio Bootloader Tool, correct ID, correct 3.3V voltage. 1] Upload bootloader (from link above) via SWD in Atmel studio, board resets and shows up in USB devices 2] Unplug JLink, unplug board 3] Open Arduino 4] Plug-in board, shows up in ports in Arduino IDE as Atmel ATSAMD21E18A (Native USB Port). In windows device I see Bosso USB device. 5] In Arduino IDE choose Atmel ATSAMD21E18A (Native USB Port) as the device to upload to and the port 6] Upload basic blink sketch, 100% upload confirmed by Arduino IDE

After this procedure I get the USB removal sound in Windows. If I remove and plug the board back in, it is not identified by Windows at all. If I use Atmel Studio to upload one of their ATSAMD21 LED blink examples, it works fine and is identified by Windows every time.

It seems as if the Arduino sketch overwrites the bootloader and thus Windows cannot identify the device. But I don't understand why the Adafruit Feather bootloader does nothing at all either.

Here’s the output id its any help.

Sketch uses 8832 bytes (3%) of program storage space. Maximum is 262144 bytes.
Atmel SMART device 0x1001000a found
Device       : ATSAMD21E18A
Chip ID      : 1001000a
Version      : v2.0 [Arduino:XYZ] Aug 10 2016 16:46:23
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : none
Security     : false
Boot Flash   : true
BOD          : true
BOR          : true
Arduino      : FAST_CHIP_ERASE
Erase flash
done in 0.837 seconds

Write 9088 bytes to flash (142 pages)

[=============                 ] 45% (64/142 pages)
[===========================   ] 90% (128/142 pages)
[==============================] 100% (142/142 pages)
done in 0.057 seconds

Verify 9088 bytes of flash with checksum.
Verify successful
done in 0.013 seconds
CPU reset.

The device signature is 0x1001030A in Atmel Studio.

So it looks like I am actually able to upload sketches. It may have been possible the whole time, I just wasn't aware that it had uploaded and run the program due to no auto-reboot. Thus the problem is that the MCU doesn't auto-reboot after upload and also the blink example (edited for my correct LED pin) isn't doing anything. This is via Native USB. Though I can get back into bootloader mode by double pressing the reset button. It does auto-reboot and blink when using the Atmel Studio blink example, programmed via JLink SWD pins.

What could be causing this?

So upon further research it seems I may have a bad 32.768kHz ex. clock.
Can anyone confirm this could be the culprit?

Fyod: So upon further research it seems I may have a bad 32.768kHz ex. clock. Can anyone confirm this could be the culprit?

Yes. It can be. I too had a lot of problems with my atsamd21g18a board and the culprit was the crystal.

It was indeed the crystal ;)