After much experimentation, I think a lot of the errors I found that uploading the bootloader and getting Windows to reliably detect the device requires proper placement of decoupling capacitors. I followed the decoupling capacitor guidelines carefully in the SAMD21 datasheet, and this solved my problem.
I also once encountered the "Unable to enter programming mode" problem when I accidently swapped the SWDIO and SWCLK pin connections with the Atmel ICE programmer.
Hey @AwakingDragon,
Could you please provide more information on how you got it to work? I am getting the same error when I try to program "Failed to write segment at 0x0 to target for memorytype base" and I am getting this error when I try to verify "Verifying Flash...Failed! address=0x0000 expected=0x50 actual=0xff". Could you please direct me to the page in SAMD21 datasheet where it gives information on where to place the decoupling capacitors? I have been going through the datasheet but have not been able to find anything. Sorry, i am beginner at this. Thank you.
Unfortunately, the datasheet is a bit vague about the actual value of the capacitors, but suggestions are provided on Table 37-17. You can also emulate the setup which was used in the design of the Adafruit Feather M0, schematic found here: Adafruit Learning System