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

Calling Serial.end() on STM32L073RZTx results in high power consumption #119

Open
CropWatchDevelopment opened this issue Mar 3, 2025 · 1 comment

Comments

@CropWatchDevelopment
Copy link

CropWatchDevelopment commented Mar 3, 2025

Please, before reporting any issue

Any questions/feedback/suggestions should be discussed on the stm32duino forum:

⚠ When reporting any issue, please try to provide all relevant information to help on its resolution.

Describe the bug
After calling begin() on HardwareSerial ports, running end() does not fully stop, and clean up the serial port.

Steps to reproduce the behavior:
Flash first code example, see a power useage of 25uA
Flash 2nd code sample, see power usepage of ~300uA

Expected behavior
The 1st example's current consumption should equal that of the 2nd

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Linux Mint
  • IDE version: PlatformIO
  • Upload method: [e.g. SWD] STLINK v2's SWD

Hardware (please complete the following information):

  • Board Name: STM32L073RZTx
  • Extra hardware used if any: PowerProfiler 2

Additional context
Add any other context about the problem here.

Code example 1, Power consumption ~25uA:

#include <Arduino.h>
#include "STM32LowPower.h"

// Create HardwareSerial objects
HardwareSerial Serial1(USART1);
HardwareSerial Serial2(USART2);
HardwareSerial Serial4(USART4);

void setup()
{
  // // Initialize serial ports for a short period
  // Serial2.begin(115200);
  // Serial1.begin(9600);
  // Serial4.begin(9600);

  // // // End the serial ports
  // Serial2.end();
  // Serial1.end();
  // Serial4.end();

  LowPower.begin();
  LowPower.deepSleep(20000);
}

void loop()
{
  // Nothing to do here
}

Code Example 2, Calls both Begin() and End() however, this example runs at ~500uA:

#include <Arduino.h>
#include "STM32LowPower.h"

// Create HardwareSerial objects
HardwareSerial Serial1(USART1);
HardwareSerial Serial2(USART2);
HardwareSerial Serial4(USART4);

void setup()
{
  // Initialize serial ports for a short period
  Serial2.begin(115200);
  Serial1.begin(9600);
  Serial4.begin(9600);

  // // End the serial ports
  Serial2.end();
  Serial1.end();
  Serial4.end();

  LowPower.begin();
  LowPower.deepSleep(20000);
}

void loop()
{
  // Nothing to do here
}

FINALLY,
running this example rund at around 1mA:

#include <Arduino.h>
#include "STM32LowPower.h"

// Create HardwareSerial objects
HardwareSerial Serial1(USART1);
HardwareSerial Serial2(USART2);
HardwareSerial Serial4(USART4);

void setup()
{
  // Initialize serial ports for a short period
  Serial2.begin(115200);
  Serial1.begin(9600);
  Serial4.begin(9600);

  // // // End the serial ports
  // Serial2.end();
  // Serial1.end();
  // Serial4.end();

  LowPower.begin();
  LowPower.deepSleep(20000);
}

void loop()
{
  // Nothing to do here
}
@CropWatchDevelopment CropWatchDevelopment changed the title Calling Serial.end() not working on Calling Serial.end() on STM32L073RZTx results in high power consumption Mar 3, 2025
@fpistm
Copy link
Member

fpistm commented Mar 3, 2025

Hi @CropWatchDevelopment
This is normal as when you call end only the USART RCC are disabled.
Anyway the pins used by the Serial still configured mainly the GPIO clock, it could not be disabled because it do not know if another pins on the same GPIO port are used or not.
So it is up to the application to disabled those clocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants