New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esp8266: put pin interrupt handler in iRAM #5962
Conversation
@peterhinch if you could test this, that would be great. |
OK, I now have a test running but it needs to run for a while as the fault was infrequent. You managed to replicate my original report here so maybe that would be worth repeating? |
This has now run for over two hours - I'm confident this has fixed it. Previously I doubt it ever ran for more than 15 minutes (without pinging). This also confirms my belief that the I2C issues were a consequence of the ISR not running - this was breaking the protocol causing the Pyboard I2C slave to fail. |
I have also run your test. I reduced the PWM frequency to 50Hz (10ms interrupt interval) as I thought 1ms rather ambitious for soft IRQ's. This has run for 30 minutes without error. On occasion it reconnected to the LAN but the code continued to run:
Code: from machine import Pin, PWM
from time import sleep
import gc
pin = Pin(13, Pin.IN)
count = 0
def cb_pin(_):
global count
count += 1
ei = pin.irq(handler = cb_pin, trigger = (Pin.IRQ_FALLING | Pin.IRQ_RISING))
PWM(machine.Pin(2), freq=50, duty=50)
while True:
sleep(1)
print(count)
gc.collect() |
That was actually something subtly different: it didn't lead to a crash, rather it hung the Python code but the "OS" was still running.
Ok, that's really great news! But let's wait a bit to merge this in case something else comes up. |
7de495e
to
b362e49
Compare
I cleaned this up a bit and removed support for |
So ports can put it in a special memory section if needed.
GPIO interrupts can occur when the flash ROM cache is in use and so the GPIO interrupt handler must be in iRAM. This commit moves the handler to iRAM, and also moves mp_sched_schedule to iRAM which is called by pin_intr_handler. As part of this fix the Pin class can no longer support hard=True in the Pin.irq() method, because the VM and runtime are too big to put in iRAM. Fixes micropython#5714.
These are needed to ensure correct operation of the MicroPython scheduler.
b362e49
to
391927c
Compare
Added a small note to the docs that the |
Add board.STEMMA_I2C on ESP QTPYs
Attempt to fix #5714