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

Fix #150: switch timed Sleep() to use STOP mode #156

Merged
merged 4 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
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
59 changes: 13 additions & 46 deletions src/lib/stm32/stm32l0/CatenaStm32L0Rtc.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,16 @@
/* CatenaStm32L0Rtc.cpp Wed Jan 03 2018 11:04:33 chwon */

/*

Module: CatenaStm32L0Rtc.cpp

Function:
Class CatenaStm32L0Rtc

Version:
V0.7.0 Wed Jan 03 2018 11:04:33 chwon Edit level 4

Copyright notice:
This file copyright (C) 2017 by

MCCI Corporation
3520 Krums Corners Road
Ithaca, NY 14850

An unpublished work. All rights reserved.

This file is proprietary information, and may not be disclosed or
copied without the prior permission of MCCI Corporation.
See accompanying LICENSE file.

Author:
ChaeHee Won, MCCI Corporation October 2017

Revision history:
0.6.0 Fri Oct 13 2017 15:19:30 chwon
Module created.

0.6.0 Fri Dec 01 2017 13:55:23 chwon
Remove debug code.

0.6.0 Wed Dec 06 2017 15:32:22 chwon
Change clock division setting.

0.7.0 Wed Jan 03 2018 11:04:33 chwon
Need to call HAL_RTCEx_EnableBypassShadow() to support USB.

*/

#ifdef ARDUINO_ARCH_STM32
Expand All @@ -47,10 +20,7 @@ using namespace McciCatena;

/****************************************************************************\
|
| Manifest constants & typedefs.
|
| This is strictly for private types and constants which will not
| be exported.
| Manifest constants & typedefs.
|
\****************************************************************************/

Expand All @@ -59,22 +29,19 @@ using namespace McciCatena;
|
| Read-only data.
|
| If program is to be ROM-able, these must all be tagged read-only
| using the ROM storage class; they may be global.
|
\****************************************************************************/


/****************************************************************************\
|
| VARIABLES:
| Variables.
|
| If program is to be ROM-able, these must be initialized
| using the BSS keyword. (This allows for compilers that require
| every variable to have an initializer.) Note that only those
| variables owned by this module should be declared here, using the BSS
| keyword; this allows for linkers that dislike multiple declarations
| of objects.
\****************************************************************************/


/****************************************************************************\
|
| Overrides for "weak" definitions in core HAL.
|
\****************************************************************************/

Expand Down Expand Up @@ -109,7 +76,7 @@ void HAL_RTC_MspInit(
__HAL_RCC_RTC_ENABLE();
/* USER CODE BEGIN RTC_MspInit 1 */
HAL_NVIC_SetPriority(RTC_IRQn, TICK_INT_PRIORITY, 0U);
HAL_NVIC_EnableIRQ(RTC_IRQn);
HAL_NVIC_EnableIRQ(RTC_IRQn);
/* USER CODE END RTC_MspInit 1 */
}
}
Expand All @@ -121,7 +88,7 @@ void HAL_RTC_MspDeInit(
if (hRtc->Instance == RTC)
{
/* USER CODE BEGIN RTC_MspDeInit 0 */
HAL_NVIC_DisableIRQ(RTC_IRQn);
HAL_NVIC_DisableIRQ(RTC_IRQn);
/* USER CODE END RTC_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_RTC_DISABLE();
Expand Down Expand Up @@ -210,13 +177,13 @@ bool CatenaStm32L0Rtc::begin(bool fResetTime)
Serial.println("HAL_RTC_SetTime() failed");
return false;
}

/* Sunday 1st January 2017 */
Date.WeekDay = RTC_WEEKDAY_SUNDAY;
Date.Month = RTC_MONTH_JANUARY;
Date.Date = 0x1;
Date.Year = 0x0;

if (HAL_RTC_SetDate(
&this->m_hRtc,
&Date,
Expand Down
40 changes: 5 additions & 35 deletions src/lib/stm32/stm32l0/CatenaStm32L0_Sleep.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
/* CatenaStm32L0_Sleep.cpp Wed Oct 31 2018 10:57:42 chwon */

/*

Module: CatenaStm32L0_Sleep.cpp

Function:
Home for CatenaStm32L0::Sleep()

Version:
V0.11.0 Wed Oct 31 2018 10:57:42 chwon Edit level 1

Copyright notice:
This file copyright (C) 2018 by

MCCI Corporation
3520 Krums Corners Road
Ithaca, NY 14850

An unpublished work. All rights reserved.

This file is proprietary information, and may not be disclosed or
copied without the prior permission of MCCI Corporation
See accompanying LICENSE file.

Author:
ChaeHee Won, MCCI Corporation October 2018

Revision history:
0.11.0 Wed Oct 31 2018 10:57:42 chwon
Module created.

*/

#ifdef ARDUINO_ARCH_STM32
Expand All @@ -39,10 +21,7 @@ using namespace McciCatena;

/****************************************************************************\
|
| Manifest constants & typedefs.
|
| This is strictly for private types and constants which will not
| be exported.
| Manifest constants & typedefs.
|
\****************************************************************************/

Expand All @@ -52,23 +31,13 @@ using namespace McciCatena;
|
| Read-only data.
|
| If program is to be ROM-able, these must all be tagged read-only
| using the ROM storage class; they may be global.
|
\****************************************************************************/



/****************************************************************************\
|
| VARIABLES:
|
| If program is to be ROM-able, these must be initialized
| using the BSS keyword. (This allows for compilers that require
| every variable to have an initializer.) Note that only those
| variables owned by this module should be declared here, using the BSS
| keyword; this allows for linkers that dislike multiple declarations
| of objects.
| Variables.
|
\****************************************************************************/

Expand All @@ -95,8 +64,9 @@ Name: CatenaStm32L0::Sleep()

void CatenaStm32L0::Sleep(uint32_t howLongInSeconds)
{

this->m_Rtc.SetAlarm(howLongInSeconds);
this->m_Rtc.SleepForAlarm(CatenaStm32L0Rtc::SleepMode::Standby);
this->m_Rtc.SleepForAlarm(CatenaStm32L0Rtc::SleepMode::StopWithLowPowerRegulator);

// add the number of ms that we were asleep to the millisecond timer.
// we don't need extreme accuracy.
Expand Down