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

cpu/stm32f0: add periph_pm support #9521

Merged
merged 2 commits into from
Mar 19, 2019
Merged

Conversation

vincent-d
Copy link
Member

Contribution description

Add stm32f0 support in stm32_common pm driver.
Tested with a nucleo-f091rc. Didn't check the actual power consumption yet.

Issues/PRs references

None

@vincent-d vincent-d added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: cpu Area: CPU/MCU ports labels Jul 9, 2018
@vincent-d vincent-d requested review from aabadie and kaspar030 July 9, 2018 12:03
@vincent-d
Copy link
Member Author

Tested on a custom device (stm32f091 based) and works!

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

minor readability question

defined(CPU_FAM_STM32F4)
#define PM_EWUP_CONFIG (PWR_CSR_EWUP)
#elif defined(PWR_CSR_EWUP8)
#define PM_EWUP_CONFIG (PWR_CSR_EWUP8 | PWR_CSR_EWUP7 | PWR_CSR_EWUP6 | \
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe readability can be improved by using a static inline?

static const unsigned _pwr_ewup_config(void)
{
unsigned tmp = 0;
#if defined(PWR_CSR_EWUP8)
tmp |= PWR_CSR_EWUP8;
#endif
#if defined(PWR_CSR_EWUP7)
tmp |= PWR_CSR_EWUP7;
#endif
...
#if defined(PWR_CSR_EWUP1)
tmp |= PWR_CSR_EWUP1;
#endif

return tmp;
}

... then use PWR->CSR = _pwr_ewup_config() below.

This should optimize to a single value even when assigning a volatile register.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll give a try

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@vincent-d
Copy link
Member Author

Ping

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* Copyright (C) 2018 OTA keys S.A.
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the authors list order, I think the copyright order should be reversed. Otherwise this gives the impression that OTA Keys initially contributed this file, which is not true.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@aabadie
Copy link
Contributor

aabadie commented Aug 8, 2018

Apart from the copyright comment, the changes look good and work (tested on nucleo-f070rb).

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

ACK

@kaspar030's comment is addressed, so please also squash

@vincent-d
Copy link
Member Author

Squashed

@aabadie
Copy link
Contributor

aabadie commented Aug 8, 2018

Thanks @vincent-d. Now let's wait for @kaspar030's approval (and merge ? :) )

@vincent-d
Copy link
Member Author

Ping @kaspar030

@smlng
Copy link
Member

smlng commented Dec 21, 2018

please rebase, I'll to find a device for testing

@smlng
Copy link
Member

smlng commented Dec 21, 2018

if good, we can dismiss @kaspar030 review

@kaspar030 kaspar030 dismissed their stale review December 21, 2018 12:43

comment addressed

@vincent-d
Copy link
Member Author

Rebased and adapted stm32l0 implementation

@vincent-d
Copy link
Member Author

rebased

@aabadie
Copy link
Contributor

aabadie commented Mar 13, 2019

Ah yes, sorry ;) I'll have a look later.

#endif
PWR->CSR |= _ewup_config();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think activating all wake-up pins available by default is a good choice. On nucleo boards WKUP2 is connected to user button and VDD which triggers wakeup from STANDBY mode immediately (except for stm32l433rc) (#11167). On other nucleo boards you have wkup pins connected to other peripherals which can also trigger weird resets.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be better if this was handled or at least over-writable for every board. Since wiring is very board specific enabling this for all boards using this cpu is prone to conflicts (in some stml4 base boards uart is connected to a wake-up pin too.) IMO default configuration should be no wkup-pin enabled (cpu can allways wake up from RTC), and then when enabling a wkup pin makes sense, this should be handled on board configuration files. Thoughts @aabadie @vincent-d @kaspar030 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's actually how it's implemented. One can define PM_EWUP_CONFIG to enable the pins depending on their needs.

Copy link
Contributor

@fjmolinas fjmolinas Mar 13, 2019

Choose a reason for hiding this comment

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

Your are right, sorry I didn't read the code properly. I like it!

@aabadie
Copy link
Contributor

aabadie commented Mar 13, 2019

I'll give a last try to this PR tomorrow and will merge it. After I'll adapt #11173.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

I tested this PR on nucleo-f091rc and STOP mode works although consumption seems quite high (~2mA instead of 7 in normal run mode). By default, the STANDBY mode doesn't work because all wakeup pins are enabled which causes troubles.

This is why I don't like the current default behaviour with wake-up pins. See my comment below.

tmp |= PM_EWUP_CONFIG;
#elif defined(PWR_CSR_EWUP)
tmp |= PWR_CSR_EWUP;
#else
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be done differently.
In the current state, if the user doesn't provide a define for PW_EWUP_CONFIG, then this function will activate all wake-up pins.
This results in an invalid default STANDBY configuration for most of the nucleo boards in this case. For example, on nucleo-f091rc, with this default configuration, the STANDBY mode doesn't work unless one builds the application with CFLAGS=-DPM_EWUP_CONFIG=0.

What about having the possibility to provide the PM_EWUP_CONFIG in the board periph_conf.h and include this file in pm.c ?
Then there's no need for this function, just use the following snippet in the STANDBY case, below:

PWR->CSR |= PM_EWUP_CONFIG

And provide a default PM_EWUP_CONFIG to 0 somewhere in the periph_cpu_common.h file.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this has been inherited from the previous versions which used to enable all wake-up pins.

I don't mind changing to use PM_EWUP_CONFIG only.

@vincent-d
Copy link
Member Author

I changed the wake-up pins config, and refactored even more.

@aabadie
Copy link
Contributor

aabadie commented Mar 18, 2019

Thanks for updating @vincent-d, it looks much better like this :)

I think the history of commits should be reworked: one commit introducing the pm code refactoring and one adding the support for F0. That would make history cleaner.

I'll give a try asap.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

Tested on F0, F4, L0 and L1. It works.

ACK, please squash (see #9521 (comment) for a better git history proposal)

@vincent-d
Copy link
Member Author

@aabadie done!

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

ACK

@aabadie aabadie merged commit d7b3091 into RIOT-OS:master Mar 19, 2019
@vincent-d vincent-d deleted the pr/stm32f0_pm branch March 19, 2019 17:29
@danpetry danpetry added this to the Release 2019.04 milestone Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants