I have a problem with disabling irq on my Pico Pi with the latest version of Micropython 1.18
When I tried to use machine.disable_irq() in some code I was developing, it stopped before loading and said this:
AttributeError: 'module' object has no attribute 'disable_irq'
I then tried the code in REPL, which worked. By that, I mean that it did not give an error. It did hang the machine, so I took it as the code was executed, but wasn't something you should try in REPL.
So I made the smallest program to test it as follows:
import machine
foo = machine.disable_irq()
machine.enable_irq(foo)
This very small program worked, at least it returned to Thonny without any messages in the REPL window.
So I am trying to figure out why sometimes, it seems, the program has lost track of whether it has the
disable_irq() method. By the way, when the code failed to be accepted, I was calling disable_irq() from
a foreground program in an effort to keep an interrupt process from touching the common data what I was
wanting to make a copy of.
Any ideas?
Here is proof that 1.18 thinks it has disable_irq():
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.
import machine
help(machine)
object <module 'umachine'> is of type module
...
__name__ -- umachine
unique_id -- <function>
soft_reset -- <function>
reset -- <function>
reset_cause -- <function>
bootloader -- <function>
freq -- <function>
idle -- <function>
lightsleep -- <function>
deepsleep -- <function>
disable_irq -- <function>
enable_irq -- <function>
...
Problems with machine.disable_irq()
Re: Problems with machine.disable_irq()
It is difficult to say why this error is occurring without seeing sample code that can be used to reproduce the error. Here are some examples of how it could have been produced:
Code: Select all
>>> import micropython
>>> foo = micropython.disable_irq()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'disable_irq'
Code: Select all
>>> import machine
>>> machine.disable_irq = 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'disable_irq'
Calling machine.disable_irq() from the REPL is tricky because if interrupts are disabled for too long terrible things are likely to happen. For example, I would expect TinyUSB, which is used by the REPL, to stop functioning when interrupts are disabled.
This should work from the REPL as interrupts are only disabled for a short period of time:
Code: Select all
>>> import machine
>>> j = 0
>>> foo = machine.disable_irq(); j += 1; machine.enable_irq(foo)
>>> print(j)
1
>>>
Code: Select all
>>> import machine
>>> j = 0
>>> foo = machine.disable_irq()
>>>
I would imagine that there is a programming error somewhere in your code. As mentioned above, if you can provide a short sample program that can be used to reproduce the error someone may spot what the problem is.