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

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Hanilein
Posts: 26
Joined: Thu Jul 12, 2018 11:40 am
Location: Christchurch, New Zealand

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

Post by Hanilein » Tue Feb 12, 2019 7:34 am

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.
Ivo Gorny

User avatar
dhylands
Posts: 3115
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

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

Post by dhylands » Wed Feb 13, 2019 10:47 pm

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

Hanilein
Posts: 26
Joined: Thu Jul 12, 2018 11:40 am
Location: Christchurch, New Zealand

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

Post by Hanilein » Thu Feb 14, 2019 8:09 am

Thank you, Dave. Much appreciated. :)
Ivo Gorny


User avatar
dhylands
Posts: 3115
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

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

Post by dhylands » Tue Feb 19, 2019 5:19 am

The changes have been merged into the latest master on github.

Post Reply