Micropython-main-boot: Difference between revisions

From pymate.io wiki
Jump to navigation Jump to search
No edit summary
Line 4: Line 4:
[[file:micropython-startup.png]]
[[file:micropython-startup.png]]


== Virtual Machine Initialization ==
=== Virtual Machine Initialization ===
Among the various initialization tasks, the firmware will open the USB-Serial communication channel.
Among the various initialization tasks, the firmware will open the USB-Serial communication channel.


Line 15: Line 15:
From now, any Python {{fname|print()}} statement, as well as error, will be reported to the USB-Serial line.
From now, any Python {{fname|print()}} statement, as well as error, will be reported to the USB-Serial line.


== boot.py script ==
=== boot.py script ===


Loading the {{fname|boot.py}} is the first operation performed by the virtual machine.
Loading the {{fname|boot.py}} is the first operation performed by the virtual machine.
Line 33: Line 33:
* When using tools like Thonny, MPRemote, etc then boot.py execution time will be added to each connection attempt.
* When using tools like Thonny, MPRemote, etc then boot.py execution time will be added to each connection attempt.


== main.py script ==
=== main.py script ===


The {{fname|main.py}} script is the file containing the user program to execute at startup.
The {{fname|main.py}} script is the file containing the user program to execute at startup.
Line 39: Line 39:
If the file is missing or script produce an error then the virtual machine jump to the next step (interactive REPL session).  
If the file is missing or script produce an error then the virtual machine jump to the next step (interactive REPL session).  


== REPL session ==
=== REPL session ===


The interactive REPL session is always the final execution step of the MicroPython virtual machine.
The interactive REPL session is always the final execution step of the MicroPython virtual machine.
Line 53: Line 53:


This can be solved by setting the MicroPython {{fname|Watchdog}}. The watchdog will resets the Pymate when activities are unexpectedly halted. }}
This can be solved by setting the MicroPython {{fname|Watchdog}}. The watchdog will resets the Pymate when activities are unexpectedly halted. }}
== Python Mainloop ==
xxx

Revision as of 15:53, 28 April 2026

Startup Sequence

When powered up, the PymateIO initialize the MicrPython virtual machine which executes the following steps.

Micropython-startup.png

Virtual Machine Initialization

Among the various initialization tasks, the firmware will open the USB-Serial communication channel.

The USB-Serial is defined as standard input & standard output (usually named stdin & stdout).

The MicroPython virtual machine starts and the USB-Serial is defined as standard input & standard output (usually named stdin & stdout).

The REPL get initialized and attached to the standard input/outpout (so the USB-Serial).

From now, any Python print() statement, as well as error, will be reported to the USB-Serial line.

boot.py script

Loading the boot.py is the first operation performed by the virtual machine.

The virtual machine jump to the next step if the file is not available.

The role of the boot.py script is to perform a quick hardware initialization at startup.

It is also a good place to mount additionnal file systems.

The boot.py script should be short and executes its content as fast as possible. The MicroPython virtual machine will stays locked as long as the boot.py have not terminated its processing.

Remarks:

  • Interacting with MicroPython is almost impossible during the processing of boot.py .
  • When using tools like Thonny, MPRemote, etc then boot.py execution time will be added to each connection attempt.

main.py script

The main.py script is the file containing the user program to execute at startup.

If the file is missing or script produce an error then the virtual machine jump to the next step (interactive REPL session).

REPL session

The interactive REPL session is always the final execution step of the MicroPython virtual machine.

That means that interactive REPL will get actives when:

  • No main.py file is available.
  • main.py terminates its execution.
  • An error occurs in main.py (which interrupts the script execution).
Remarks:

From automation perspective, a PLC should never stays "inactive" when an error occurs.

This can be solved by setting the MicroPython Watchdog. The watchdog will resets the Pymate when activities are unexpectedly halted.

Python Mainloop

xxx