Stm32 LowPower… deep sleep burning 40mA

Hello, I'm trying to use an STM32 (blue pill) with some other modules (including an external RTC). The idea is to make the stm go into deepsleep and wake it up once every day to do its business.

I use the latest STM32 Core and the Stm32 LowPower library.
The minimum relevant code example is as follows

#include <Wire.h>
#include <STM32LowPower.h>
#include <RTClib.h>
#define CLOCK_INTERRUPT_PIN PB13
volatile bool ipt=false;
RTC_DS3231 rtc;
void setup() {
//  alt=false;
pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP);
rtc.begin();
  rtc.clearAlarm(1);
  rtc.clearAlarm(2);
  rtc.disableAlarm(2);
 LowPower.begin();
  LowPower.attachInterruptWakeup(digitalPinToInterrupt(CLOCK_INTERRUPT_PIN), onAlarm,FALLING,DEEP_SLEEP_MODE);
}

void loop(){
 LowPower.deepSleep();
 delay(1000);
 if(ipt)
 {
 ipt=false;
 doStuff();
 }
}
void doStuff(){
// irrelevant: this works as expected
}

void onAlarm(){
  rtc.clearAlarm(1);
  ipt=true;
}

I tried measuring the current going to the bluepill, then I see it steady around 38mA (using a keithley dm6500), and it never falls down (upon waking up and "doing stuff" I mean, the real stuff it has to do it jumps up to 70mA).

What am I doing wrong? I think 40mA is way too high for a deep sleep.

Cheers

There are examples for STM32 here (official STM32 core)
https://github.com/stm32duino/STM32LowPower/tree/main/examples

And you must remember if you are using a BluePill, the LEDs, the USB, any serial connection, and any chip Pull-ups can consume a significant current.

For the older core known as Roger's core, some measured current results are here:
https://stm32duinoforum.com/forum/viewtopic_f_28_t_4485.html#p52026

thanks for your reply.
I understand that the LED is consuming about 6mA (3.3V across 510R).
I have no serial enabled, nor I have the usb connected.
The deepsleep example in the folder you mentioned was what I used as the base idea for what I did.

Also, to be clear, I did not measure the psu current, but the current directly into the 3.3V pin of the pill…
Am I doing something wrong?

Thanks

Not anything wrong, but I suspect the uC is not consuming the current. BluePills have been known to have various issues: wrong resistors, bridged solder joints, even non-STM microcontrollers. I suspect you should try to put the uC into reset mode and see if the current drops.

Over on the STM32duino.com forum, you may be able to get some help from Frederic who's team wrote the core wrappers.

thanks. I'm heading there.

Cheers