Arduino M0 doesn't load code, how to flash bootloader?

I picked up an Arduino M0 the other day to do a simple project with and I realized when I got home that the box was open. Evidently, the previous person to use the board completely messed up the bootloader and the device isn't recognized on either of my computers in or out of bootloader mode (pressing the reset button twice). I borrowed an Arduino Mega 2560 so I can use it to flash the bootloader with SPI, as my friend told me it's an easy process, but literally every guide is different. I want to make sure I am doing this correctly with a 2560 as the programmer, and an M0 as the target. Hopefully the fact that they use different architectures isn't a problem.

Also, all the guides I saw did not even use any of the 6 SPI pins on either board, for SPI flashing. That makes no sense to me. Why would the pins be there if they aren't used?

Also I am a super noob about microcontrollers and I only use them to accomplish specific tasks. I won't understand if you use very technical language. I do understand all the Adafruit guides I have read, for reference.

Hi Kekerino,

Don't use the Arduino Mega as a programmer. For one thing the Mega works at 5V, while the SAMD21 micro-controller on the Arduino M0 is only 3.3V tolerant. Plugging in the Mega will very probably damage your Arduino M0 board. The other thing is that the Arduino M0, unlike the AVR Arduinos such as the Uno and Mega, isn't programmed via its SPI port, but rather the 2x5 way, 1.27mm pitch SWD connector.

It might be just that the sketch that was last uploaded on to the M0 board has crashed or stalled. This sometimes prevents code from being uploaded via the native USB port. As you mention, to overcome this it's necessary to first put the M0 into bootloader mode by double tapping the reset button, (two times in quick succession). On entering bootloader mode your computer will change COM port. In the Arduino IDE just go to Tools->Port in the menu and select the new COM port, then hit the upload button as normal.

If this fails to work then the last resort is to burn the bootloader. On the Arduno M0 you'll require some form of ICE programmer that you hook up via the SWD port, such as the Atmel ICE Basic. Other programmers for Atmel's ARM micro-controllers are also available. If however you've got the Arduino M0 Pro then things are much easier, as the programmer is built in to its on-board EDBG chip. In the Arduino IDE just go to Tool->Programmer and select Atmel EDBG, then Tools->Burn Bootloader.