Timer callback gets stuck when thread is running - RP2040 #10700
Unanswered
EliAaron
asked this question in
RP2040 / Pico
Replies: 1 comment 3 replies
-
I will try you program later. Seeing |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
There seems to be a problem using the Timer and a thread simultaneously. The timer randomly gets stuck after a few seconds. The higher the frequency of the timer, the quicker it gets stuck.
Note: I am using MicroPython v1.19.1 where rp2 memory corruption bug in thread was fixed.
I came across these two links which seem to be about the same issue, with no solution:
Timer callback stops with uart thread
Problem with machine.Timer() and _thread on Raspberry Pi Pico (RP2040)
I posted a question on the MicroPython forum:
Timer gets stuck when thread is running - RP2040.
Reproducible example
I wrote a simple example that demonstrates the problem and is easy to reproduce with any Pico board.
In the example, the Pico LED is toggled in a thread and a timer runs with a callback that prints an incrementing counter.
The problem may be about interrupts and threads
I suspect the core of the problem is not specific to timers and threads, it is about interrupts and threads.
The reason I write this is because I encountered a similar problem In two other cases:
Non blocking writes with I2S on a second thread: I wrote a WAV player that uses the I2S object. the streaming of the output was does on a second thread. I tried to speedup the streaming by using none blocking writes:
When I did not use a thread, it worked fine. When I did use a second thread, it would get stuck after a few seconds.
Input pin interrupts when second thread is running: I configured pins with interrupt handlers
When I had a thread running in the background (streaming WAV with I2S), the callbacks would randomly strop getting triggered after a few seconds. The more frequent the irq calls, the faster it would get stuck.
I tried using:
and
There was some difference (I don't remember) but the irq always would stop getting triggered after a few seconds.
A simple example can be written to check the problem with pin interrupts and threads but I am currently working on a different project...
Beta Was this translation helpful? Give feedback.
All reactions