Skip to main content
Chupacabras
Associate II
March 15, 2022
Solved

STM32F030 High current in stop mode

  • March 15, 2022
  • 11 replies
  • 4923 views

I would like to put STM32F030K6T6 into STOP mode (low power mode), in which there should be current consumption around 5 μA.

But whatever I do the current consumption is around 450 μA in stop mode.

There is basically nothing else on the PCB, it's as simple as possible.

The board without MCU consumes 7 μA, that is quiescent current of LDO. So in the end I would expect to get 12 μA (7 + 5 μA).

When I place there MCU the consumption is around 2-3 mA in normal mode and 450 μA in stop mode.

All pins are set to analog input with no pull-ups, which is recommended config. All peripherals are disabled (like ADC, IWDG, I2C, SPI, timer, etc.). Only RTC is enabled.

I tried it with all pins set to output, it did not help either.

What do I do wrong?

int main(void) {
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_RTC_Init();
 while (1) {
 goto_stop();
 HAL_Delay(3000); // 3 seconds of full power
 }
}
void goto_stop(void) {
 
 RTC_DateTypeDef sDate;
 sDate.Date=1;
 sDate.Month=RTC_MONTH_JANUARY;
 sDate.Year=22;
 sDate.WeekDay=RTC_WEEKDAY_MONDAY;
 // HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);
 
 if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 
 RTC_TimeTypeDef sTime;
 sTime.Seconds=0;
 sTime.Minutes=0;
 sTime.Hours=0;
 // HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);
 
 if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 
 
 HAL_NVIC_EnableIRQ(RTC_IRQn);
 
 
 RTC_AlarmTypeDef sAlarm;
 sAlarm.Alarm=RTC_ALARM_A;
 sAlarm.AlarmTime.Seconds=20;
 sAlarm.AlarmTime.Minutes=0;
 sAlarm.AlarmTime.Hours=0;
 // sAlarm.AlarmMask=RTC_ALARMMASK_SECONDS | RTC_ALARMMASK_MINUTES | RTC_ALARMMASK_HOURS;
 sAlarm.AlarmMask=RTC_ALARMMASK_HOURS | RTC_ALARMMASK_DATEWEEKDAY;
 // HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD);
 
 sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
 sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
 sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
 
 if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 
 
 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
 
 
 __HAL_RCC_GPIOA_CLK_DISABLE();
 __HAL_RCC_GPIOB_CLK_DISABLE();
 __HAL_RCC_GPIOC_CLK_DISABLE();
 __HAL_RCC_GPIOD_CLK_DISABLE();
 __HAL_RCC_GPIOF_CLK_DISABLE();
 
 
 HAL_SuspendTick();
 
 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
 
 SystemClock_Config();
 
 HAL_ResumeTick();
 
}

This topic has been closed for replies.
Best answer by Chupacabras

I put it aside for couple of days. Now I got back to it.

And it works OK without changing anything. 20 μA in stop mode (LDO + MCU), and 2.6 mA in run mode.

When I flash firmware, disconnect SWD connector, push reset, it consumes 450 μA in stop mode.

I have to completely disconnect power, and connect back power, after that stop mode consumes 20 μA.

Then I found an option in flashing settings "Enable debug in low power modes" which is checked by default. I unchecked it and now it works even after flashing and I do not have to completely disconnect power.

0693W00000KdHicQAF.png

11 replies

MM..1
Super User
March 15, 2022

Place some pin toggle debug and disconnect debuger and power off after flash sw.

Chupacabras
Associate II
March 15, 2022

I already tried it with SWD connector plugged, and unplugged. No change. There's no other cable/connector.

What do you mean by that pin toggle?

MCU runs 3 seconds in full speed, then 20 seconds in stop mode. So it seems it runs as expected. Except the current consumption.

MM..1
Super User
March 16, 2022
SWD progg setup DBG registers to debug in low power mode where current is up.
You need disconnect power source and reconnect it.
And pin toggle I mean before enter STOP place GPIO low and after STOP high, then you can check with scope ...
And too
/* Enable PWR APB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);


RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOF , ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;


GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Disable GPIOs clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA |RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOF, DISABLE);
config used ...
Piranha
Principal III
March 17, 2022

Set DBGMCU_CR to 0 and disconnect the debugger physically.

Chupacabras
Associate II
March 19, 2022

Thanks for advice.

I found the culprit. It was not the DBGMCU->CR register. See my answer.

Chupacabras
ChupacabrasAuthorBest answer
Associate II
March 19, 2022

I put it aside for couple of days. Now I got back to it.

And it works OK without changing anything. 20 μA in stop mode (LDO + MCU), and 2.6 mA in run mode.

When I flash firmware, disconnect SWD connector, push reset, it consumes 450 μA in stop mode.

I have to completely disconnect power, and connect back power, after that stop mode consumes 20 μA.

Then I found an option in flashing settings "Enable debug in low power modes" which is checked by default. I unchecked it and now it works even after flashing and I do not have to completely disconnect power.

0693W00000KdHicQAF.png

Piranha
Principal III
March 20, 2022

That means both answers (mine and your) are correct. When that setting is enabled, at connection the debugger sets the respective bits in DBGMCU_CR register.

Still take a note that DBGMCU_CR register is not reset by system reset. That means it will be reset only by removing the power and waiting for the capacitors to discharge. Depending on the schematics and power consumption, for some devices it can take many seconds or even minutes.

Chupacabras
Associate II
March 20, 2022

I tried

DBGMCU->CR=0;

before, it did not help.

Well, actually I was not able to flash with this line in the code.