1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/samd21: clean up 'disabled GCLK' magic

It turns out hooking up an unused peripheral to a disabled GCLK
leads to surprising power savings.

Name the GCLK to be more explicit (and since not all members of
the extended samd2x family have a GCLK7).

Turns out we can just use a non-existing GCLK ID for this, this
even saves us a real GCLK that we can use for something else.

Also make sure to disable *all* peripherals by using
`GCLK_CLKCTRL_ID_Msk` instead of relying on a magic value.

Looks like we previously missed some, since this leads to some
additional power savings:

master:     4.22 mA
this patch: 4.09 mA
This commit is contained in:
Benjamin Valentin 2020-10-02 22:40:57 +02:00
parent 57f5341275
commit 91604d0217
2 changed files with 3 additions and 2 deletions

View File

@ -252,8 +252,8 @@ static void clk_init(void)
#endif
/* redirect all peripherals to a disabled clock generator (7) by default */
for (int i = 0x3; i <= 0x22; i++) {
GCLK->CLKCTRL.reg = ( GCLK_CLKCTRL_ID(i) | GCLK_CLKCTRL_GEN_GCLK7 );
for (unsigned i = 0x3; i <= GCLK_CLKCTRL_ID_Msk; i++) {
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(i) | GCLK_CLKCTRL_GEN(SAM0_GCLK_DISABLED);
while (GCLK->STATUS.bit.SYNCBUSY) {}
}
}

View File

@ -60,6 +60,7 @@ enum {
SAM0_GCLK_1MHZ, /**< 1 MHz clock for xTimer */
SAM0_GCLK_32KHZ, /**< 32 kHz clock */
SAM0_GCLK_1KHZ, /**< 1 kHz clock */
SAM0_GCLK_DISABLED = 0xF, /**< disabled GCLK */
};
/** @} */