Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/periph_pm: use button as a wake-up source #12710

Merged
merged 1 commit into from
Dec 5, 2019

Conversation

benpicco
Copy link
Contributor

@benpicco benpicco commented Nov 14, 2019

Contribution description

To test if GPIO interrupts can wake the CPU from sleep, configure BTN0 (if available) as a wake-up source.

Pressing the buttong should wake up the CPU.

Testing procedure

On samr21-xpro enter set 0 to enter the deepest sleep mode.
You will find that the CPU does not react to UART input anymore.
Press the button on the board.

A Button pressed. message should be printed and the CPU should return to the previous operation mode.

Issues/PRs references

During #12615 it was discussed why GCLK0 wasn't used for the EIC controller. My speculation for the use of the 32kHz clock was that it might still work in deep sleep mode.
This tests confirms that assumption.

With

--- a/cpu/sam0_common/periph/gpio.c
+++ b/cpu/sam0_common/periph/gpio.c
@@ -188,7 +188,7 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
        internal or external 32 kHz */
     GCLK->CLKCTRL.reg = (EIC_GCLK_ID |
                          GCLK_CLKCTRL_CLKEN |
-                         GCLK_CLKCTRL_GEN_GCLK2);
+                         GCLK_CLKCTRL_GEN_GCLK0);
     while (GCLK->STATUS.bit.SYNCBUSY) {}
 #else /* CPU_FAM_SAML21 */
     /* enable clocks for the EIC module */

the CPU won't wake up from Deep Sleep when the button is pressed.

A drawback of the slow clock is that fast interrupts are lost. This is a real problem I observed with the at86rf215 driver.
A solution would be to switch the EIC clock to GCLK2 when entering Deep Sleep.

@benpicco benpicco added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: tests Area: tests and testing framework labels Nov 14, 2019
@benpicco benpicco requested review from basilfx and dylad November 14, 2019 16:54
@keestux
Copy link
Contributor

keestux commented Nov 14, 2019

Tested with sodaq-one. Indeed it wakes up when pressing the button (after set 0)

Repeated the test using GCLK0 in gpio.c, then it does not respond to the button press.

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 15, 2019
To test if GPIO interrupts can wake the CPU from sleep, configure
BTN0 (if availiable) as a wake-up source.

Pressing the buttong should wake up the CPU.
@benpicco benpicco force-pushed the tests/periph_pm-button branch from 7cc649b to 05db5c6 Compare December 4, 2019 15:20
@benpicco benpicco requested a review from vincent-d December 4, 2019 15:48
Copy link
Member

@vincent-d vincent-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick test on a nucleo board, it works as expected.

ACK

@benpicco benpicco merged commit bcacd8e into RIOT-OS:master Dec 5, 2019
@benpicco benpicco deleted the tests/periph_pm-button branch December 5, 2019 14:08
@fjmolinas fjmolinas added this to the Release 2020.01 milestone Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants