cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030 High current in stop mode

Chupacabras
Associate III

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();
 
}

1 ACCEPTED SOLUTION

Accepted Solutions
Chupacabras
Associate III

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

View solution in original post

11 REPLIES 11
MM..1
Chief III

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

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.

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 ...

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?

This is example using STM32F0xx_StdPeriph_Driver

for HAL change func and parameters for hal.

Piranha
Chief II

Set DBGMCU_CR to 0 and disconnect the debugger physically.

Chupacabras
Associate III

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

Thanks for advice.

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

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.