There is a lot you can do with the clocks on a Cortex M0+ MCU, however, this is far from trivial. Additionally, I have not seen any example where the main clock is adjusted on the fly (other than stopping it to enter sleep).
The RTCCounter library does not provide any power management functionality. That is outside the scope of the library which is design to provide a timing functionality.
On p124-125 of the datasheet, Tables 15.3 and 15.4 provide the information about the idle modes.
You can control the idle level or deep sleep with the following:
You will need to set the following bit to enable deepsleep, and clear it for any of the idle modes:
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
Additionally, the idle level can be set using:
PM->SLEEP.bit.IDLE = PM_SLEEP_IDLE(2); // Idle 2
I’m not sure if what effect these modes will have on the USB component. Also even if the device resumes the USB connection after waking up from an idle state, you will likely lose connection to the device unless you are running software (terminal or logger) which can auto-reconnect.
You can switch off the USB before entering sleep with this:
USBDevice.detach();
Just be careful as you may have to do other tests to see if the USB is currently attached/connected.
Additionally, you can for a resume after waking up with:
USBDevice.attach();
USB->DEVICE.CTRLB.bit.UPRSM = 0x01u;
while (USB->DEVICE.CTRLB.bit.UPRSM);
Again this might cause issues if you aren’t connected as I believe it will wait until a connection with a host is established.