What about the bootloader?

how does code execute when you are plugged into the USB,

I think I've answered my own question, if there is no user code the BL is entered, if the is user code that's entered instead. This is good because you no longer have an delay while the BL decides if it should run or not as is currently the case with Arduinos.

For this reason you have to clear the flash before you can get access to the BL.

The Due board does have an ERASE button that can be used for this purpose, but that would be a pain to do every time so I looked at the schematic.

There's a FET across the switch that is controlled by ATMEGA16U2, so the USB chip can erase the SAM before programming. This is part of the standard download procedure as I understand it.

Mystery solved.


Rob