Author Topic: STM32G0 getting most out of the STOP mode  (Read 18507 times)

0 Members and 1 Guest are viewing this topic.

Offline VekettiTopic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: fi
STM32G0 getting most out of the STOP mode
« on: February 10, 2024, 02:41:37 pm »
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: [Select]
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 added
Code: [Select]
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: [Select]
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.
« Last Edit: February 10, 2024, 02:53:51 pm by Veketti »
 

Offline Jope

  • Regular Contributor
  • *
  • Posts: 111
  • Country: de
Re: STM32G0 getting most out of the STOP mode
« Reply #1 on: February 11, 2024, 01:38:21 am »

And according to STM training material, ADC is disabled when stop0 or 1 mode is active. However I added
Code: [Select]
HAL_ADC_DeInit(&hadc1); and it further reduced current consumption. Why is that, it shouldn't have any effect as it is disabled anyway?

If you take a look at the source code for HAL_ADC_DeInit(), you will notice this line:
Code: [Select]
/* Disable ADC internal voltage regulator */
    LL_ADC_DisableInternalRegulator(hadc->Instance);

This will reduce power consumption further.
 
The following users thanked this post: Veketti, SiliconWizard

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15975
  • Country: fr
Re: STM32G0 getting most out of the STOP mode
« Reply #2 on: February 11, 2024, 02:25:51 am »
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).
 
The following users thanked this post: Veketti

Offline VekettiTopic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: fi
Re: STM32G0 getting most out of the STOP mode
« Reply #3 on: February 11, 2024, 07:55:54 am »
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.pdf

If 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?
« Last Edit: February 11, 2024, 08:01:10 am by Veketti »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6438
  • Country: es
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15975
  • Country: fr
Re: STM32G0 getting most out of the STOP mode
« Reply #5 on: February 11, 2024, 08:31:38 am »
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?

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

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

If 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)?

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

« Last Edit: February 11, 2024, 08:37:53 am by SiliconWizard »
 
The following users thanked this post: Veketti

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6438
  • Country: es
Re: STM32G0 getting most out of the STOP mode
« Reply #6 on: February 11, 2024, 09:28:46 am »
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.
« Last Edit: February 11, 2024, 09:36:22 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: Veketti

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28525
  • Country: nl
    • NCT Developments
Re: STM32G0 getting most out of the STOP mode
« Reply #7 on: February 11, 2024, 02:40:15 pm »
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.
« Last Edit: February 11, 2024, 02:45:09 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline unreal

  • Newbie
  • Posts: 3
  • Country: us
Re: STM32G0 getting most out of the STOP mode
« Reply #8 on: February 11, 2024, 04:15:47 pm »
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.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6438
  • Country: es
Re: STM32G0 getting most out of the STOP mode
« Reply #9 on: February 11, 2024, 05:08:54 pm »
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.
« Last Edit: February 11, 2024, 05:32:20 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline unreal

  • Newbie
  • Posts: 3
  • Country: us
Re: STM32G0 getting most out of the STOP mode
« Reply #10 on: February 11, 2024, 09:38:05 pm »
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.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6438
  • Country: es
Re: STM32G0 getting most out of the STOP mode
« Reply #11 on: February 12, 2024, 05:13:51 am »
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.
See this.
« Last Edit: February 12, 2024, 05:18:40 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline VekettiTopic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: fi
Re: STM32G0 getting most out of the STOP mode
« Reply #12 on: February 18, 2024, 04:46:15 pm »
...
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.
...

Indeed 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: [Select]
__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 sleep

Maybe that PWR wakeup flag clear is unnecessary, but it seems it is not at least harming anything.
 
The following users thanked this post: SiliconWizard


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf