Skip to content

STM32 Low Power library #1

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

Closed
wants to merge 5 commits into from
Closed

STM32 Low Power library #1

wants to merge 5 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 20, 2017

This library allows to enter the board in Low Power mode.

Low Power mode:

  • idle
  • sleep
  • deepSleep
  • shutdown

Possibility to:

  • configure a pin as wake up source
  • use a Serial to wake up the board
  • use a Wire to wake up the board (not implemented yet)
  • use the RTC to wake up the board in n milliseconds

This library is based on the low power driver and the RTC library.

fpr added 2 commits December 11, 2017 16:59
Signed-off-by: fpr <[email protected]>
@ghost ghost requested review from LMESTM, fpistm and VVESTM December 20, 2017 13:01

/**
* @brief Enable a wire interface as a wakeup source.
* @param serial: pointer to a TwoWire

Choose a reason for hiding this comment

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

@param serial: pointer to a TwoWire
=> @param wire: pointer to a TwoWire


/**
* @brief Attach a callback to a RTC alarm.
* @param serial: pointer to a STM32RTC

Choose a reason for hiding this comment

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

=> @param rtc: pointer to a STM32RTC

Copy link
Member

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

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

Few comments and questions raised

LowPower_EnableWakeUpUart(&(serial->_serial), callback);
}

#if 0
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment or limitation description rather than code behind #if 0

* @param millis: delay before leave the idle mode.
* @retval None
*/
void STM32LowPower::idle(uint32_t millis)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't the idle / sleep function return something ? en error in case something went wrong ?

Copy link
Author

Choose a reason for hiding this comment

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

We can't because HAL functions don't return status.

Copy link
Member

Choose a reason for hiding this comment

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

ok


void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
Copy link
Member

Choose a reason for hiding this comment

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

I would rather propose to write loop like:

digitalWrite(LED_BUILTIN, HIGH);
LowPower.deepSleep(500);
digitalWrite(LED_BUILTIN, LOW);
LowPower.deepSleep(500);

README.md Outdated

* **`void begin()`**: configure the Low Power

* **`void idle(uint32_t millis)`**: enter sleep mode
Copy link
Member

Choose a reason for hiding this comment

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

to describe idle / sleep / deepsleep and shutdown modes, I think we also need to define associated HW states (clocks / internal memories / voltage supplies / peripherals ...) and latencies for each of the state.

Something like :
In Idle mode : low wake-up latency (µs range) (e.g. ARM WFI), mémories and voltage supplies are retained. minimal Power saving mainly on the core itself.
In sleep mode : medium latency (ms range), clocks are gated to reduced. memories and voltage supplies are retained. If supported, Peripherals wake-up is possible (UART, I2C ...).
In deep sleep mode: higher wake-up latency ( ), Most memories content are lost and and voltage supplies are shut down. Available with internal clock input (LSI).
In shutdown mode: high wake-up latency (posible hundereds of ms or second timeframe ), voltage supplies are cut except always-on domain, memory content are lost and system basically reboots. . Only available with external clock input (LSE).

When writing this, I am wondering whether the mapping to STM32 low power modes could be changed to:

  • idle => sleep WI ok
  • sleep => could be sleep with PWR_LOWPOWERREGULATOR_ON
  • deep_sleep => could be stop mode
  • shutdown => standby / shutdown mode depending whether LSE is available or not.

I am open to discussion ...

Copy link
Author

Choose a reason for hiding this comment

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

Description can't be very detailed because depends on chip used.

When writing this, I am wondering whether the mapping to STM32 low power modes could be changed to:

  • idle => sleep WI ok
  • sleep => could be sleep with PWR_LOWPOWERREGULATOR_ON
  • deep_sleep => could be stop mode
  • shutdown => standby / shutdown mode depending whether LSE is available or not.

We will lose a part of the compatibility with the Arduino Low Power library. But why to not rename all methods to be more compliant with STM32 low power mode names:

  • idle => sleep
  • sleep => stop
  • deep_sleep => standby
  • shutdown

LSE is only required for shutdown. LSI is still available with standby.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand you point about breaking compatibility, can you explain more ?

My view is that if the boards has LSE, you will use shutdown. If the board doesn't have LSE, then you will use LSI. So you would either use LSE or LSI, not both of them. This choice can be done at the variant level so that Arduino application will always use shutdown().

Copy link
Author

Choose a reason for hiding this comment

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

Ok I understood. We will make the changes.
We just need to study how know if LSE is available or not. Something automatic if possible.

@ghost ghost requested a review from LMESTM January 17, 2018 13:40
fpr added 3 commits March 15, 2018 16:30
@ghost
Copy link
Author

ghost commented Mar 15, 2018

Hi @fpistm
PR up to date.

@fpistm fpistm added invalid This doesn't seem right and removed review on going labels May 23, 2018
@fpistm fpistm removed their request for review May 23, 2018 08:28
@fpistm fpistm closed this May 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants