The dead bootloader problem

Suppose you have an Arduino SAMD21 board without the Atmel Embedded Debugger (EDBG), like these:

SAMD21 Mini Breakout without EDBG
SAMD21 Mini Breakout without EDBG

SAM 15x15 board without EDBG
SAM 15x15 board without EDBG

During programming, it happens quite often that the native port doesn't work anymore. The reason is that the sketch disrupts the native port.

Example

We assume that the SAMD21 board is properly installed and that everything works fine. The sketch below makes the native USB port unresponsive:

  • Connect the native port.
  • Select "Native USB Port" with the Tools menu
  • Select the correct port with the Tools menu.
  • Upload the sketch below.
  • Open the Tools menu.
  • The board is no longer recognized by your PC and the Tools>Port menu is grayed out:
  • SAMD21 Arduino bootloader virus
    SAMD21 Arduino bootloader virus

void setup() 
{ 
}
void loop()
{ pinMode(28, INPUT); // native USB D-
}

Fix it with double-tapping the reset button

There is a method that helps: double-tap the reset button. The port should now be available and visible again, but... note that it will work on your nerves because it often still doesn't work and you have to try again. 

If double-tapping doesn't work

Tools ­ > Board ­> select your board again even if it is clearly already selected.
or
Tools ­> Port and select the COM port again.
or
Sometimes it is even necessary to temporarily use another USB port of your computer. 
or
Often there are duplicate ports, for instance COM5 and COM7, of which only one is the right one. Each time you have to switch between them; this is very annoying.

It would be nice if the Arduino software can be improved here.

Protection of native USB port

If the native USB port pins are left out of the variant.cpp file, it appears that the USB port still works, but the pins are no longer available as I/O pins, this reduces the vulnerability. Experience shows that it is still be possible to disable the native USB port. The SAM 15x15 variant.cpp file has been changed accordingly:

//{ PORTA, 24, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DM 
//{ PORTA, 25, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DP 

Add the program pins

To be sure that you are always be able to reburn a malfunctioned bootloader, you have to make these three pins accessible by a connector: SWDIO, SWCLK and RESET.

Links

Do you have any comments? Please let me know.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.