Author Topic: STM32L0xxx - check if STOP mode was exited?  (Read 854 times)

0 Members and 1 Guest are viewing this topic.

Offline poorchavaTopic starter

  • Super Contributor
  • ***
  • Posts: 1673
  • Country: pl
  • Troll Cave Electronics!
STM32L0xxx - check if STOP mode was exited?
« on: May 20, 2021, 06:33:11 am »
I have an STM32L010 and I'm using the STOP mode with wake-up by EXTI. Is there a way to determine within the IRQ if STOP mode was just exited? I know there is such flag for STANDBY mode, but I can't see one for the STOP mode and I need this information to fix some config issues that appear when goin low power (eg. setting clock back to PLL mode).

Any idea how to do it? ST doesn't seem to have an example code for the STOP mode for this uC family.
I love the smell of FR4 in the morning!
 

Online abyrvalg

  • Frequent Contributor
  • **
  • Posts: 837
  • Country: es
Re: STM32L0xxx - check if STOP mode was exited?
« Reply #1 on: May 20, 2021, 06:56:19 am »
That can be solved the other way: disable IRQ, do WFE, reinit clocks and pins (you may want to set some pins to specific states before WFE to reduce currents), enable IRQ. See https://m0agx.eu/2021/04/16/stm32-stop-mode-exti-wakeup-example-without-hal/
 

Offline poorchavaTopic starter

  • Super Contributor
  • ***
  • Posts: 1673
  • Country: pl
  • Troll Cave Electronics!
Re: STM32L0xxx - check if STOP mode was exited?
« Reply #2 on: May 20, 2021, 10:18:45 am »
I should probably rephrase: I have an EXTI IRQ, which is used both at normal runtime (basically, it's hooked up to keypad) and to wake the uC up. I'm looking for something, to determine within EXTI IRQ code if the uC was in STOP mode before IRQ happened or not.

Currently, I'm just checking the PLL status bits, and if it's off I assume this is due to uC being in STOP mode before, and reinitialize the peripherals. I was looking for some cleaner solution, as this seems a bit of a hack.

The STOP mode entry etc works just fine. The only thing is that all possible pending IRQs need to be menally cleared before WFI, and that includes SysTick.
I love the smell of FR4 in the morning!
 

Online abyrvalg

  • Frequent Contributor
  • **
  • Posts: 837
  • Country: es
Re: STM32L0xxx - check if STOP mode was exited?
« Reply #3 on: May 20, 2021, 11:21:40 am »
But if you reinit everything right after WFE and before enable_irq - you don’t need to care about reinit in EXTI ISR, it’s already done.
 

Online abyrvalg

  • Frequent Contributor
  • **
  • Posts: 837
  • Country: es
Re: STM32L0xxx - check if STOP mode was exited?
« Reply #4 on: May 20, 2021, 12:22:19 pm »
Ah, I see now, you’re using WFI to sleep, not WFE - that’s why you need to clear all pending IRQs. With WFE you have more control on wake up sources (if you don’t set SEVONPEND bit on NVIC the IRQs will be ignored and the only wake source will be EXTIs marked as events in EXTI_EMR register), plus it adds an additional latch between IRQs (if you use them for wake up, SEVONPEND is set) and wake up - the event register that can be cleared with SEV-WFE sequence (that’s the part of "magic sequence" in my example above) without clearing all possible IRQs.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf