Skip to content

Commit 02af715

Browse files
angelnufpistm
authored andcommitted
Support sleeping fractions of seconds
1 parent 1e6f952 commit 02af715

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ Arduino library to support STM32 Low Power.
33

44
## Requirement
55
* [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32) version >= 1.3.0
6-
* [STM32RTC](https://github.com/stm32duino/STM32RTC)
76

87
## API
98

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

1211
* **`void idle(uint32_t millis)`**: enter in idle mode
13-
**param** millis (optional): number of milliseconds before to exit the mode. At least 1000 ms. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.
12+
**param** millis (optional): number of milliseconds before to exit the mode. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.
1413

1514
* **`void sleep(uint32_t millis)`**: enter in sleep mode
16-
**param** millis (optional): number of milliseconds before to exit the mode. At least 1000 ms. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.
15+
**param** millis (optional): number of milliseconds before to exit the mode. he RTC is used in alarm mode to wakeup the chip in millis milliseconds.
1716

1817
* **`void deepSleep(uint32_t millis)`**: enter in deepSleep mode
19-
**param** millis (optional): number of milliseconds before to exit the mode. At least 1000 ms. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.
18+
**param** millis (optional): number of milliseconds before to exit the mode. The RTC is used in alarm mode to wakeup the chip in millis milliseconds.
2019

2120
* **`void shutdown(uint32_t millis)`**: enter in shutdown mode
22-
**param** millis (optional): number of milliseconds before to exit the mode. At least 1000 ms. The RTC is used in alarm mode to wakeup the board in millis milliseconds.
21+
**param** millis (optional): number of milliseconds before to exit the mode. The RTC is used in alarm mode to wakeup the board in millis milliseconds.
22+
23+
**Note: With [STM32RTC](https://github.com/stm32duino/STM32RTC) version lower than 1.1.0, the minimum number of milliseconds is 1000 ms.**
2324

2425
* **`void attachInterruptWakeup(uint32_t pin, voidFuncPtrVoid callback, uint32_t mode)`**: Enable GPIO pin in interrupt mode. If the pin is a wakeup pin, it is configured as wakeup source (see board documentation).
2526
**param** pin: pin number

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino Low Power
2-
version=1.0.3
2+
version=1.1.0
33
author=Wi6Labs
44
maintainer=stm32duino
55
sentence=Power save primitives features for STM32 boards

src/STM32LowPower.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void STM32LowPower::enableWakeupFrom(STM32RTC *rtc, voidFuncPtr callback, void *
167167

168168
/**
169169
* @brief Configure the RTC alarm
170-
* @param millis: time of the alarm in milliseconds. At least 1000ms.
170+
* @param millis: time of the alarm in milliseconds.
171171
* @param lp_mode: low power mode targeted.
172172
* @retval None
173173
*/
@@ -202,12 +202,28 @@ void STM32LowPower::programRtcWakeUp(uint32_t millis, LP_Mode lp_mode)
202202
if (millis > 0) {
203203
// Convert millisecond to second
204204
sec = millis / 1000;
205+
206+
#if defined(STM32_RTC_VERSION) && (STM32_RTC_VERSION >= 0x01010000)
207+
uint32_t epoc_ms;
208+
millis = millis % 1000;
209+
epoc = rtc.getEpoch(&epoc_ms);
210+
211+
//Update epoch_ms - might need to add a second to epoch
212+
epoc_ms += millis;
213+
if (epoc_ms >= 1000) {
214+
sec ++;
215+
epoc_ms -= 1000;
216+
}
217+
218+
rtc.setAlarmEpoch(epoc + sec, STM32RTC::MATCH_DHHMMSS, epoc_ms);
219+
#else
205220
// Minimum is 1 second
206221
if (sec == 0) {
207222
sec = 1;
208223
}
209-
210224
epoc = rtc.getEpoch();
225+
211226
rtc.setAlarmEpoch(epoc + sec);
227+
#endif
212228
}
213229
}

0 commit comments

Comments
 (0)