stm32duino / STM32LowPower

Arduino Low Power library for STM32
185 stars 52 forks source link

Serial is not output normally when returning from DeepSleep #67

Closed nopnop2002 closed 2 years ago

nopnop2002 commented 2 years ago

Serial is not output normally when returning from DeepSleep

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() {
  Serial.println("serial printing");
  for(int i=0;i<20;i++) LowPower.deepSleep(1000);
  //for(int i=0;i<20;i++) LowPower.sleep(1000);
  //for(int i=0;i<20;i++) LowPower.idle(1000);
  //delay(1000);
}

Problem

Serial is not output normally when returning from DeepSleep.

Serial is output normally when returning from Sleep.

Serial is output normally when returning from Idle.

Screen Shot

LowPower

fpistm commented 2 years ago

Same here than #68. Use Serial.flush(). Entering and exiting sleep mode change the clock that's why you probably seen this.

nopnop2002 commented 2 years ago

Good!! It's solved.

void loop() {
  //unsigned long nowMillis = millis();
  //Serial.println(nowMillis);
  Serial.println("serial printing");
  Serial.flush();
  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<5;i++) LowPower.idle(1000);
  //delay(1000);
}