millis() does not return the correct time
nopnop2002 opened this issue · 1 comments
nopnop2002 commented
My Envitonment
STM32F103(8MHz Xtal) + platformIO
Platform Manager
================
Platform ststm32
--------
Checking platformio/ststm32 15.2.0 [Up-to-date]
Checking platformio/toolchain-gccarmnoneeabi 1.70201.0 @ >=1.60301.0,<1.80000.0 [Up-to-date]
Checking platformio/framework-arduinoststm32 4.20100.211028 @ ~4.20100.0 [Up-to-date]
Checking platformio/framework-arduinoststm32-maple 3.10000.201129 @ ~3.10000.0 [Up-to-date]
Checking platformio/tool-stm32duino 1.0.1 @ ~1.0.1 [Up-to-date]
Checking platformio/tool-openocd 2.1100.211028 @ ~2.1100.0 [Up-to-date]
Checking platformio/tool-dfuutil 1.9.200310 @ ~1.9.190708 [Up-to-date]
My config
[platformio]
default_envs = blackpill_f103c8
[env:blackpill_f103c8]
platform = ststm32
board = blackpill_f103c8
framework = arduino
lib_deps =
https://github.com/stm32duino/STM32LowPower
https://github.com/stm32duino/STM32RTC
My code
#include <Arduino.h>
#include "STM32LowPower.h"
void setup() {
LowPower.begin();
Serial.begin(115200);
Serial.println("serial (same as 1)");
Serial.println("*****");
}
void loop() {
unsigned long nowMillis = millis();
Serial.println(nowMillis);
//Serial.println("serial printing 2");
//for(int i=0;i<20;i++) LowPower.deepSleep(1000);
//for(int i=0;i<10;i++) LowPower.sleep(1000);
for(int i=0;i<10;i++) LowPower.idle(1000);
//delay(1000);
}
Problem
millis() does not return the correct time.
idle can stop the clock.
Screen Shot
fpistm commented
In fact, there is no issue here as when you enter in one of the sleep mode the interrupt are disabled.
Line 259 in c2e8d13
For IDLE mode the systick is simply disabled:
Lines 234 to 239 in c2e8d13
As millis relies on the systick it is normal it is not incremented during the sleep.
You can use the RTC to compensate it if you need.