2022-03-15 02:05 AM
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();
}
Solved! Go to Solution.
2022-03-19 12:41 PM
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.
2022-03-15 09:55 AM
Place some pin toggle debug and disconnect debuger and power off after flash sw.
2022-03-15 10:21 AM
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.
2022-03-15 11:01 PM
2022-03-16 02:53 AM
Functions like "RCC_APB1PeriphClockCmd" are unknown.
I'm using HAL generated code.
Which libraries do I need to import so I can use those functions?
2022-03-16 10:11 AM
This is example using STM32F0xx_StdPeriph_Driver
for HAL change func and parameters for hal.
2022-03-17 01:37 PM
Set DBGMCU_CR to 0 and disconnect the debugger physically.
2022-03-19 12:41 PM
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.
2022-03-19 12:43 PM
Thanks for advice.
I found the culprit. It was not the DBGMCU->CR register. See my answer.
2022-03-19 12:45 PM
Thanks for advice.
I found the culprit. It was not the registers you mentioned. See my answer.
Actually I tried HAL equivalents to std library functions you suggested, it was not it.