I just finished reading Krizzli's post on difficulty uploading. I am having a similar problem, but it has a bit more history. I designed a PCB based around the SAMD21 MCU (full disclosure: I ripped off the schematic from the SparkFun Eagle schematic and added extra components such as the TFT screen) and had it manufactured. I flashed an Arduino bootloader using a j-link debugger and Microchip Studio. I was able to connect to USB using COM 6. Everything worked fine.
I made a few minor revisions to the next iteration of the PCB (moved a couple components slightly for more separation around the screw holes, added an analog channel) and had the second PCB fabricated. I flashed the bootloader as above, connected to the USB (COM 5) and uploaded my sketch. However, as soon as I finished uploading, I got an error on my Desktop that the USB device had malfunctioned and could no longer be recognized. I re-flashed the bootloader, re-uploaded my sketch, and, same problem once again: USB device not recognized as soon as I uploaded the sketch. I had 5 PCB's manufactured in each run- they all do the same thing.
Anyways, I had an old PCB that I could work with so, I've been developing my code on that.
Fast forward to today and now the original PCB is doing the same thing after months of working fine as are other PCB's from the same production run.
2 points to note:
I used a 4 pin crystal instead of a 2 pin as done on the sparkfun board.
When everything worked, it connected to COM 6. Just before I upload a sketch and everything fails, my computer recognizes the device on COM 5 or COM 4.
So, I've been trying to solve this problem for months now, and given my history of screwing stuff up, assumed that there was a hardware issue in my design. I just tried a hail mary by eliminating libraries. It seems like when I call the Adafruit BME280 pressure function (including the library is OK), everything fails. I've gone back and forth 3 times now uploading sketches without calling the function, and then calling the function and the only constant is that the bootloader fails when I call the function. However, the BME280 did work earlier.
I then uploaded the sketch with the BME 280 function to a SparkFun SAMD21 mini development board, and sure enough, it fried the bootloader. However I did not hook up a pressure sensor, but I can't see the bootloader failing just because it's calling an address (BME280) that doesn't exist.
I think it's safe to conclude that the Adafruit_BME280.h library has intermittent issues. I barely know anything about hardware, and even less about software, so if someone wants to explain why this would happen, I'd love the lesson.
I ve had a similar issue a couple of times with custom PCBs with (a) atmega1284p MPU and the Mightycore as well as atmega32u4 mcu as an arduino nano.
In both above cases, following a sketch upload, the USB port stopped functioning as if there was no bootloader .
I never figured out why had this happened, but burning the bootloader again solved the issue in all cases.
It appears that, for some reason, the sketch seems to corrupt the bootloader.
This is probably a different issue than your case but I thought I d mention it in case there is some relevance.
PS: Interesting design! I am now waiting for my custom PCBs to arrive from China for my first attempt to built a SAMD21 based system along with a 5 inch tft touch screen, flash memory, sd card etc.
No reason to think it is a hardware issue - in fact, by uploading to it usccessfully once, you have ruled out the possibility of a hardware problem!
It sounds to me like a bug in the code/library is doing something that causes the nativer-USB-capable chip to crash such that it is unalbe to respond to normal USB requests, so the computer notices that it is failing to respond to communication attempts and doesn't display or stops displaying it as a USB device. ASine it is no longer functioning in that capacity.