5 years, 4 months ago.

STM32 looses IRQ when in deepsleep

I'm running MBedOS 5.11.5 on an STM32L082 connected to an A/B pulse generator (signal A on pin PA2 and B on PB2) which counts movement, handling forward/reverse direction. The idea is to generate an IRQ when A goes up and increment the counter if B is also up, or decrement it if B is down:

InterruptIn signalA(PA_2);
DigitalIn signalB(PB2);

volatile uint16_t counter = 0;

void isr_count(void)
{
    if (signalB)
        counter++;
    else
        counter--;
}

void main(void)
{
    ...
    signalA.rise(isr_count);
    ...
}

Really simple, but it gives me very inaccurate, not reproductible results when I move a part up and down with the same amplitude (I checked the A/B signals with an oscilloscope at the input of the STM32 and they're fine).

I tried to deactivate to sleep mode (by attaching an event handler to the RawSerial-casted console. Ugly but working for my PoC) and now the count is correct!

So it seems when the STM32 is going to deepsleep, interrupts are not waking it up (or not calling my ISR), which breaks my counter. I have some other tasks running with EventQueue.call_every(...) which wake it up and they're working fine.

How can I get around that if I still want to deepsleep?

Thanks!

Be the first to answer this question.