STM32G0 getting most out of the STOP mode  - Page 1
Forum section: electronics / general

author: Veketti
author_rank: Regular Contributor
timestamp: February 10, 2024, 02:41:37 pm
content: Moved this to new thread. So this is about STM32G070, STOP –mode, peripherals and current consumption.In case of battery powered device every possibility to lower current consumption is welcome. On my tests I set the MCU to stop1 mode for five seconds by:Code:HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);And according to STM training material, ADC is disabled when stop0 or 1 mode is active. However I addedCode:HAL_ADC_DeInit(&hadc1);and it further reduced current consumption. Why is that, it shouldn't have any effect as it is disabled anyway? Should I also init the GPIO ports as analog before stop mode to further reduce current consumption or what do you recommend? And should all the peripherals like i2C, UART etc. be deinitialized before going to stop mode?Also noticed that I need to disable TIM6 and TIM7 interrupts when going to STOP mode, when STM training material states that only LPTIM1 and 2 are functional on stop mode? TIM6 and TIM7 are basic timers. So need to do this, otherwise it will wake up constantly:Code:HAL_NVIC_DisableIRQ(TIM6_IRQn);HAL_NVIC_DisableIRQ(TIM7_IRQn);I cannot seem to find clear explanation what are these LPTIM's from the reference manual, or are some of the TIMx counted... Sorry, many questions. Hopefully somebody could clarify.. Thank you.

author: Jope
author_rank: Regular Contributor
timestamp: February 11, 2024, 01:38:21 am
content: Quote from: Veketti on February 10, 2024, 02:41:37 pmIf you take a look at the source code forHAL_ADC_DeInit(), you will notice this line:Code:/* Disable ADC internal voltage regulator */LL_ADC_DisableInternalRegulator(hadc->Instance);This will reduce power consumption further.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 11, 2024, 02:25:51 am
content: If you enter a Stop mode with the PWR_STOPENTRY_WFI option, any interrupt can wake the MCU up.To further understand why TIM6 and/or TIM7 are able to generate interrupt conditions in Stop mode, you'll need to tell us how these timers are configured and what clock source they use.(Unless I've missed it, I haven't found a mention of these 'LPTIM' timers in the STM32G070 doc, so are you sure? I think they exist on some other series of STM32, you may have read stuff about these in another doc, but for a different series of MCU. Similarly, nothing says that timers are stopped in Stop mode. Again if I missed it, let me know. But possibly you've read stuff that would deal with another series.)In Stop mode, the LSE (and/or LSI) oscillators keep running, so if TIM6 and/or TIM7 use LSE or LSI as a clock source and they are not disabled, they *will* wake up the MCU in your case.One option to avoid spurious wake-ups from interrupt sources, if you don't need any interrupt to wake it up, is to use the PWR_STOPENTRY_WFE option instead. Then you'll need to set up the wakeup source properly (event).

author: Veketti
author_rank: Regular Contributor
timestamp: February 11, 2024, 07:55:54 am
content: From G070 datasheets the first chapter mentions about the two low power timers. See first attachment. But that's all there is about them. Whether that's not correct?In the STM32G0 power control ppt there is also picture which describes what features are available and what features not in STOP mode (see picture #2). There timers are gray and LPTIM1 & 2 are available.Document:https://www.st.com/resource/en/product_training/STM32G0-System-Power-control-PWR.pdfIf I understand this configuration correctly standard timers like TIM6 & 7 in my case are clock source HSI and it shouldn't be running on STOP1 mode (see picture #3)?So confusing. Is the documentation misleading?

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 11, 2024, 08:17:08 am
content: This might be useful:https://www.st.com/resource/en/product_training/STM32G0-System-Power-control-PWR.pdf

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 11, 2024, 08:31:38 am
content: Quote from: Veketti on February 11, 2024, 07:55:54 amThat may be a copy-paste from another datasheet, but clearly there's no mention of them in the rest of the datasheet. Similarly, there's no mention of a LPUART, while you see one on the architecture image you posted.Quote from: Veketti on February 11, 2024, 07:55:54 amWell, judging from the clock distribution diagram, all timers are clocked via SYSCLK (and then prescalers), which itself can be any of the clock sources, including LSE and LSI.But if you have selected HSI for SYSCLK, it should be HSI. Right.(Note that the datasheets for the STM32 are only giving a very high-level view of everything. You need to also refer to the reference manuals to get more detailed information (ref. RM0454)I haven't found any mention of the LPTIM timers in there either, so I doubt they actually exist on this series.)My guess now with your description is that one of the 2 timers may have generated a pending interrupt flag *before* you enter the Stop mode, and then, if the corresponding interrupts are not disabled, the MCU will wake up immediately - not from interrupts that would have been generated when the MCU is in Stop mode, but just before entering it. It could help to have a look at the IRQ handler functions you have written for both timers. To further test it, you could try clearing the interrupt flags of both timers just before calling HAL_PWR_EnterSTOPMode() instead of disabling the 2 interrupts, and see if it still wakes up.Once you made sure there can't be any pending interrupt from these timers before entering Stop mode, one other thing to consider is the following:"Some peripherals with wakeup capability can enable the HSI16 RC during Stop mode,so as to get clock for processing the wakeup event. "Check that you haven't configured some peripheral with such a capability. (I think that can be the USART for instance.) For this case, what you can test is set the clock to HSE instead (hoping you have an external crystal) - if the MCU doesn't wake up anymore while the timers interrupts are still enabled, then it may be due to this last point.

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 11, 2024, 09:28:46 am
content: He probably refers to a generic ST application note, not the RM or datasheet.BTW LPUART & LPTIMERS do exist but not officially. Same as G030 vs G041.But I agree, the RM and app notes are not very good in this subject, very little details about low power modes.RM0454 page 94 clearly states that ADC and TIMx aren't available in STOP modes... so why should you need disabling them in first place?Again, the freaking ST docs disease.

author: nctnico
author_rank: Super Contributor
timestamp: February 11, 2024, 02:40:15 pm
content: I've also been messing around with getting STOP mode working on the STM32G0 but the documentation is incomplete on how to do this. And the examples are way too limited to show how to get STOP mode working for a real piece of firmware. The device I'm working on can wake up a couple of times and then crashes.

author: unreal
author_rank: Newbie
timestamp: February 11, 2024, 04:15:47 pm
content: There is no LPTIM on value line G0, you'd have to get G071.The only timer source capable of waking from STOP is RTC wakeup timer or one of RTC alarms.

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 11, 2024, 05:08:54 pm
content: Oh yeah it does exist, here's the proof of it running on the most basic one, G30F6P6.You have to choose a higher end device, in this case I selected the G041F8, then adjust the RAM/FLASH size in linker script so it matches your lower end device.Mine is stopping normally, I enabled all timers (1,2,3,14,16,17) in interrupt mode, as expected only LPTIM1 is waking up the system.BTW this little device is a monster, ran at 150MHz no problem!If you're playing with this, add a failsafe input that skips clock setup when set high/low, otherwise if you go too far it will instantly crash, the programmer won't be able to communicate anymore.

author: unreal
author_rank: Newbie
timestamp: February 11, 2024, 09:38:05 pm
content: Noice. I wonder if DAC is present too?Still, I wouldn't rely on that for anything touching production.Anyway, I got all my low power timing needs covered with RTC. I managed to coax it to wakeup, keep calendar and source milis() all at the same time. With two high resolution async timers using alarms to spare. It required setting PREDIV_A to a low value (1 or 2) and BYPSHAD=1, which costs maybe 1uA tops. LPTIM would come handy if I wanted to output PWM in STOP mode.

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 12, 2024, 05:13:51 am
content: DAC? I don't think it's in the G030, the die is different.Different products with same dies are more likely to have the same specs as the highest-end one.G070 and G071 do share the same die (DIE460) so the DAC is probably there.The STM32G081 also uses the same die, so the're even more features to be unlocked. The only device locked will probably be the AES peripheral.Seethis.

author: Veketti
author_rank: Regular Contributor
timestamp: February 18, 2024, 04:46:15 pm
content: Quote from: SiliconWizard on February 11, 2024, 08:31:38 amIndeed this was the case. I added following before going to sleep and removed the disableIRQ lines for the timers and now the timers don't wake it up anymore.Code:__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF); // clear interrupt flags before going to sleep__HAL_TIM_CLEAR_FLAG(&htim6, TIM_FLAG_UPDATE); // clear interrupt flags before going to sleep__HAL_TIM_CLEAR_FLAG(&htim7, TIM_FLAG_UPDATE); // clear interrupt flags before going to sleepMaybe that PWR wakeup flag clear is unnecessary, but it seems it is not at least harming anything.