How to fix script hanging?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
cduran
Posts: 80
Joined: Thu Mar 17, 2016 4:52 pm

How to fix script hanging?

Post by cduran » Wed Aug 17, 2016 4:41 pm

I'm using MP as an embedded scripting engine for my firmware. I find that when there is an error in a script that MP waits in a loop and basically hangs my firmware. Is there a way to set micropython to just exit so that my firmware can continue regardless of script issues?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: How to fix script hanging?

Post by dhylands » Wed Aug 17, 2016 5:20 pm

I think that there is only a couple of places in the code where it does this, and these tend to be rather fatal errors.
One is the fatal error handler:
https://github.com/micropython/micropyt ... c#L82-L100
which should be accompanied by flashing LEDs.

With a serial REPL connected you can often see the message which would indicate more about why its failing.

Another place that this can happen (without the LEDs) is if an interrupt is enabled for which no handler has been written:
https://github.com/micropython/micropyt ... #L133-L135

It seems reasonable to me to have an option to have the system reset (like the RESET button was pushed) if one of these situations was encountered.

Another, more common approach is to use the Watchdog timer to trigger a system reset. Then if the system hangs for any reason at all you'll get a reset.
See this thread: viewtopic.php?f=5&t=226&p=5499#p5499

cduran
Posts: 80
Joined: Thu Mar 17, 2016 4:52 pm

Re: How to fix script hanging?

Post by cduran » Wed Aug 17, 2016 5:27 pm

For my purpose I rather that MP exit and let my firmware continue running. The firmware functions have much higher priority than the mp scripts, and they can't be halted due to script errors.

cduran
Posts: 80
Joined: Thu Mar 17, 2016 4:52 pm

Re: How to fix script hanging?

Post by cduran » Wed Aug 17, 2016 5:43 pm

I'm also using the Minimal implementation of MP

Post Reply