I use a SAMD21 without an external crystal, by using its internal 32kHz oscillator and transform it with DFLL to 48 MHz.
The processor wakes up normally with GCLK0 on 1 MHz, so I first activate GCLK1 with 32 kHz, switch the processor to it so I can turn off and reconfigure GCLK0 to DFLL 48 MHz, and then switch the processor back to GCLK0. (this is the same method the Arduino Zero does, with the single exception that it uses the external 32k resonator, while I use the internal one)
I now have GCLK0 running on 48 MHz and driving the CPU. I also use the generic clock 2 on 1 MHz for PWM, UART, and other things. So far so good. I debug it with SWD, with the use of an XPlained Pro board where the microcontroller has been removed and the SWD lines go directly to my board.
Everything worked fine. Until I wanted to set up the generic clock 3.
REG_GCLK_GENCTRL = 0x000003; // disable gclk3 to allow changes REG_GCLK_GENDIV = 0x000103; // set division to 1 REG_GCLK_GENCTRL = 0x010603; // activate gclk3 with 8 MHz After uploading the software, the microcontroller became unresponsive and I can no longer access it via SWD. I had a spare board, and foolishly tried it as well. The same thing happened.
The error says
error: Could not activate interface, but found DAP with ID 0x....
It suggests erasing the flash and names deep sleep as a possible cause. I can erase the flash successfully. However, no other operation is possible.
My first guess was that I somehow messed up the clock settings, the CPU needs a running clock to be able to be accessed via SWD, and it cannot do so for the lack of a resonator. So I took out the resonator from the XPlainedPro, and installed it into my board the exact same way it was in the XPlainedPro, including its capacitor.
It didn't solve my problem.
I've seen this error in a few threads, but usually it's about JTAG not working while SWD continues to work.
I there a way to save my controllers, or are they bricked?