Skip to content

STM32 : minor update in sleep HAL file #3742

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

Merged
merged 2 commits into from
Feb 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions targets/TARGET_STM/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,33 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include "sleep_api.h"
#include "rtc_api_hal.h"

#if DEVICE_SLEEP

#include "cmsis.h"
#include "us_ticker_api.h"
#include "sleep_api.h"
#include "rtc_api_hal.h"
#include "hal_tick.h"

extern void HAL_SuspendTick(void);
extern void HAL_ResumeTick(void);

void hal_sleep(void)
{
// Stop HAL systick
// Stop HAL tick to avoid to exit sleep in 1ms
HAL_SuspendTick();
// Request to enter SLEEP mode
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
// Restart HAL systick

// Restart HAL tick
HAL_ResumeTick();
}

void hal_deepsleep(void)
{
// Stop HAL systick
// Stop HAL tick
HAL_SuspendTick();
uint32_t EnterTimeUS = us_ticker_read();

// Request to enter STOP mode with regulator in low power mode
#if TARGET_STM32L4
Expand All @@ -74,12 +79,16 @@ void hal_deepsleep(void)
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
#endif /* TARGET_STM32L4 */

// Restart HAL systick
// Restart HAL tick
HAL_ResumeTick();

// After wake-up from STOP reconfigure the PLL
SetSysClock();

TIM_HandleTypeDef TimMasterHandle;
TimMasterHandle.Instance = TIM_MST;
__HAL_TIM_SET_COUNTER(&TimMasterHandle, EnterTimeUS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that ticker is restarted and we resume the ticker from the last known timestamp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi

Does this mean that ticker is restarted and we resume the ticker from the last known timestamp?

During deepsleep period, ticker is stopped, then ticker is reset during the clock configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. For future reference, this type of details is often worth having in the commit message, for a reader (I just guessed this without looking at the reference manual ).

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: This is one of the things we should cover in the API docs, as deepsleep in many cases would stop us ticker clocks/resets, thus should it resume time or not (currently user's assumption must be made).


#if DEVICE_LOWPOWERTIMER
rtc_synchronize();
#endif
Expand Down