My question is not how to do this specific example, but how do others do this type of activity? Looking at the code snippets that are posted, I find it hard to believe that this is manually typed in, so is there a toolset that people use for it?
I don't know which clock is configured in the default codebase.
These clock sources are selected and routed to the various peripherals, such as the ADC, AC, DAC, TCC/TC timers, SERCOM modules, RTC, WTC, etc.. via generic its generic clock system.The Arduino core code file "startup.c" already assigns the clock sources to certain generic clocks:GCLK0 - DFLL48M (also acts as the main processor clock)GCLK1 - XOSC32K if using external crystal, or OSC32K for crystalless operationGCLK2 - OSCULP32K used by the Watchdog Timer Counter (WTC)GCLK3 - OSC8MHowever, neither the clock sources or the generic clocks are set to run on standby (RUNSTDBY) by default. To do this, it's necessary to set the RUNSTDBY bit for the clock source, possibly the generic clock and the peripheral itself.
Finally, if you intend to run a number of peripherals during sleep mode then it's necessary to keep the SAMD21's internal voltage regulator in normal mode. By default it will enter low power mode, but this means it won't be able to power all the peripherals. This is detailed here: https://forum.arduino.cc/index.php?topic=691880.0.
I don't know if you can actually save much power by configuring fewer clocks. The usual power-saving technique is to avoid routing clocks to the peripherals, rather than actually disabling the clocks.You CAN look at that, you know. It even has unusually good comments!https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/startup.c#L24
At a minimum, you'll need an external 32K crystal to generate the 48MHz CPU clock, and the RTC. This means at least two clock generators, one for the main clock, and one for the RTC. Now if you need some of the other peripherals (USART/SPI/etc), you'll need another clock generator, so that makes it three.You can't use the RTC clock generator since it has to be at 1 Hz (in Calendar mode at least)