Page 1 of 1

RTC Alarm and interrupt - how does pyp.ExtInt work?

Posted: Tue Feb 12, 2019 7:34 am
by Hanilein
I have a decent complex piece of code around the RTC alarm, and it is working fine - apart from the interrupts.

I use pyb.ExtInt():
AlarmIntAB = pyb.ExtInt(17, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE, AlarmCallBack)
but the interrupts do not fire.
They do, however, when I set the EXTT_RTSR bit manually. That is, why I know the code itself is ok.

This is a dump of the registers for the external interrupts after pyb.ExtInt() has been called:

Code: Select all

EXTI_IMR  00000000 00000000 00100100 01000001
EXTI_RTSR 00000000 00000000 00100100 01000001
EXTI_FTSR 00000000 00000000 00000000 00000000
The bit 17 is clearly not set, as one would expect in the EXTI_RTSR line at least.

after calling AlarmIntAB.enable(), bit 17 is set - at least in the Interrupt Mask Register, but not in the Rising Trigger Selection Register.

Code: Select all

EXTI_IMR  00000000 00000010 00100100 01000001
EXTI_RTSR 00000000 00000000 00100100 01000001
EXTI_FTSR 00000000 00000000 00000000 00000000
Consequently no Interrupt.

But as soon as I set that bit manually:
stm.mem32[stm.EXTI + stm.EXTI_RTSR] |= 0b00000000000000100000000000000000 # Enable rising edge

It works like a charm.

Conclusion: pyb.ExtInt() sets the Alarm Callback, and resets(!) the IMR Register bit. The Rising and Falling Trigger Selection registers are ignored, regardless the second parameter setting.

What am I doing wrong?

Many thanks for your patience.

Re: RTC Alarm and interrupt - how does pyp.ExtInt work?

Posted: Wed Feb 13, 2019 10:47 pm
by dhylands
I took a look at this and it looks like there is a bug in the ExtInt module for non-GPIO lines.

I have a patch in progress, which you can find in the fix-exti branch of my tree:
https://github.com/dhylands/micropython/tree/fix-exti

The commit with the changes is this one:
https://github.com/dhylands/micropython ... 35eca6b684

I used this file to test it:
https://github.com/dhylands/upy-example ... c_alarm.py

It still doesn't work on the L4, so I need to figure out why (I know that the RTC_Alarm is line 18 rather than 17 on the L4, but there's something else going on as well). But since you were interested in the F4 I thought I'd share what I've got so far.

Dave Hylands

Re: RTC Alarm and interrupt - how does pyp.ExtInt work?

Posted: Thu Feb 14, 2019 8:09 am
by Hanilein
Thank you, Dave. Much appreciated. :)

Re: RTC Alarm and interrupt - how does pyp.ExtInt work?

Posted: Fri Feb 15, 2019 12:14 am
by dhylands
I put together a PR here:
https://github.com/micropython/micropython/pull/4503

and tested using this version of rtc_alarm.py:
https://github.com/dhylands/upy-example ... c_alarm.py

Re: RTC Alarm and interrupt - how does pyp.ExtInt work?

Posted: Tue Feb 19, 2019 5:19 am
by dhylands
The changes have been merged into the latest master on github.