2025-04-29 3:08 PM
Hi.
I am programming a board with STM32G0, which is battery powered. All processor pins are used. Overall, the device works without any problems. In normal operation mode, only STM draws about 3.5mA. However, I wanted to put the device to sleep and:
1. In Shutdown mode, STM draws 40nA (according to the documentation), and the entire device 720uA, which is satisfactory for me, but I want to be able to wake it up from a dozen or so GPIO pins, so I tried to start Stop mode and:
2. In Stop mode, STM draws 600nA (more than the documentation indicates, but still quite good). I have the ENABLE pins of the additional LDO and charge pump connected to the PB9 pin through 100R resistors, which are on the PCB and power other systems. There is also a 4k7 pull-down on the ENA pins. During normal operation, PB9 is in a high state, and before sleep it is set to a low state to turn these systems off. And here comes the problem: when I leave PB9 in the high state before switching to Stop mode, the current drawn by STM is 600nA, while when I switch it to the low state (which is what I ultimately want to do), the current increases (!) to 11mA (yes).
I tried: switching other GPIO pins and they have no effect on it, reconfiguring PB9 from push-pull to open drain, enabling/disabling pull-up/pull-down. Finally, I physically disconnected PB9 at the processor pin and... STM still draws 11mA. I admit I'm confused. Connecting/disconnecting ST-Link has no effect on current. Current measurement is made direct before STM32.
Im entering Stop mode by code below:
HAL_GPIO_WritePin(PUMP_ENA_GPIO_Port, PUMP_ENA_Pin, GPIO_PIN_RESET);
HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
I've searched the internet but I can't find any solutions, can you suggest anything? Because for me the behavior is at least strange. Best regards :)
Solved! Go to Solution.
2025-05-07 11:27 PM
So the reason for the higher current draw in STOP (11mA) mode than in RUN (3mA) mode was that I didn't do SPI_DeInit before putting the processor to sleep, while before putting the processor to sleep I turned off the power supply of the Slave IC that was connected to this SPI.
However, EXTI interrupts from PA0, PA1 and PA2 don't work because I already have interrupts from PB0, PB1 and PB2 enabled and you can't enable interrupts on pins with the same numbers in two different ports - trivial :)
Thanks :)
2025-04-30 6:03 AM
Welcome to the forum.
Please see How to write your question to maximize your chances to find a solution for best results.
@VeryLatte wrote:I am programming a board with STM32G0
Sounds like this is a custom design, so please post the schematics.
2025-05-02 7:37 AM
Hello @VeryLatte
Could try to disable clock for GPIOB.
__HAL_RCC_GPIOB_CLK_DISABLE(); // Disable clock for GPIOB if not needed
2025-05-06 3:24 PM
Hello everyone. Thanks for your answers.
I started to unsolder GPIO one by one, and after unsoldering SPI pins the current dropped - I simply forgot to DeInit this SPI. After DeInit SPI and setting pins not needed during sleep to MODE_ANALOG, STM32 itself draws 4.5uA, so the result is satisfactory to me.
However, another problem appeared that I am currently struggling with: I have connected several buttons giving high state as active to several GPIOs, I set them all as EXTI inputs from rising edge with pull-down used to wake up STM32. All are connected identically, but interestingly only those on PA0, PA1 and PA2 do not wake up the processor. The one connected to PA3 works correctly (which shows that the EXTI2_3 group is initialized). In general, the pins are functional (I observed the IDR register and they also work when I upload the software in which I use them as MODE_INPUT) and the configuration looks the same as for the working ones (I checked the MODER registers, etc.). I thought it was a problem of the lack of the HAL_GPIO_EXTI_IRQHandler() function for these pins, but that's not the reason either because these functions are there, and their lack for the working pins does not block waking up. I currently have no ideas, but I will fight with it. If only PA0 and PA1 (EXTI0_1 group) were not working, I would look for interrupts in the configuration, but since PA2 is not working either, and PA3 (EXTI2_3 group) is working, I am a bit confused.
2025-05-07 1:06 AM
@VeryLatte wrote:STM32 itself draws 4.5uA, so the result is satisfactory to me.
Excellent - please mark that as the solution.
See: https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256
@VeryLatte wrote:However, another problem appeared...
Please start a new thread for a new question.
Post a link here so that people can find it.
2025-05-07 3:15 AM
Hello @VeryLatte
It works fine on my side.
I set PA0 and PA1 as EXTI and I can wakeup the MCU using the two pins.
Below is my configuration :
/* GPIO configuration for Pin A1 */
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; // Configure for rising edge interrupt
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI0_1_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
void EXTI0_1_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
}
2025-05-07 11:27 PM
So the reason for the higher current draw in STOP (11mA) mode than in RUN (3mA) mode was that I didn't do SPI_DeInit before putting the processor to sleep, while before putting the processor to sleep I turned off the power supply of the Slave IC that was connected to this SPI.
However, EXTI interrupts from PA0, PA1 and PA2 don't work because I already have interrupts from PB0, PB1 and PB2 enabled and you can't enable interrupts on pins with the same numbers in two different ports - trivial :)
Thanks :)