← index #7372Issue #2259
Related · medium · value 1.597
QUERY · ISSUE

py: settrace is incompatible with Interrupt Handlers

openby amirgonopened 2021-06-08updated 2021-06-09
py-core

When MICROPY_PY_SYS_SETTRACE is enabled, bytecode execution allocates RAM, which is forbidden on interrupt handlers.

https://github.com/micropython/micropython/blob/4d9e657f0ee881f4a41093ab89ec91d03613744d/py/vm.c#L142-L149

https://github.com/micropython/micropython/blob/e9e9c76ddf131f8e50b0ae2d44501d3cd88537ef/py/profile.c#L315-L318

CANDIDATE · ISSUE

Integer math exceptions in interrupt handlers

closedby noelhensonopened 2016-07-23updated 2016-07-24

This issue may be a bug. It may also just be something that users need to be aware of when writing interrupt handlers.

I have been having issues on several projects where performing simple math in interrupt handlers causes "MemoryError: memory allocation failed, heap is locked" exceptions. In my cases, I have been using pyb.micros() timer values to make relative timing measurements between events. The problem is appeared to be intermittent but is actually based on the timer values when pyb.micros() is near maxint (0x3fffffff).

The problem shows with both variable and array integers:
x = 0
or
x = array.array('i',[0])

Repro:

import intException
intException.doit()

This should yield this error message:

Uncaught exception in ExtInt interrupt handler line 4
Traceback (most recent call last):
  File "intException.py", line 17, in testint
MemoryError: memory allocation failed, heap is locked

intException.zip

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied