ISR and saving to a file, ESP32 versus STM32F411 #16652
-
For several years I have been doing this on the ESP32 to catch watchdog timeouts: def wdt_callback():
global _wdt_counter
global _wdt_timeout
if (_wdt_counter >= _wdt_timeout):
try:
with open('errors.txt', 'a') as outfile:
outfile.write('had a wdt event' + '\n')
except OSError:
pass
print('doing a machine.reset()')
time.sleep_ms(10)
machine.reset() Trying to the same on an STM32F411 throws up the error: If I remove the try/except, saving to a file, the error disappears. Reading some old threads it seems that using a print statement is problematic, but seems OK in this case. Have I tripped-over a difference in the way ISRs behave on the two platforms? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
There is a difference between I doubt that you really use a hardware watchdog, because than the usual response would be a hard reset, |
Beta Was this translation helpful? Give feedback.
-
Now I read that the ESP32 uses soft timers, is the comment Maybe saying |
Beta Was this translation helpful? Give feedback.
-
You may convert the hard interrupt into a soft interrupt by using |
Beta Was this translation helpful? Give feedback.
There is a difference between
hard
andsoft
interrupts. Soft interrupts schedule the handler as a normal Python function. It can use the all Python functions and especially allocate memory. Hard interrupts are called by the MCU interrupt handler directly. They can use only a limited set of Python features and especially they must not allocate memory, and they cannot handle exceptions. So I assume that in your case you use a hard interrupt handler for you Timer functions. See also https://docs.micropython.org/en/latest/reference/isr_rules.htmlI doubt that you really use a hardware watchdog, because than the usual response would be a hard reset,