Thanks for the heads up about modemmanager, @dhylands, although I had already eliminated this as a possible reason - it was uninstalled beforehand.
I changed the bootClearUart.py routine to wait on the junk characters as shown below.
Code: Select all
from machine import UART
from time import sleep
waitBefore = True
delayPeriod = 0.1
clearUart = UART(0, 115200)
if waitBefore:
while not clearUart.any(): # stop for at least one character
sleep(delayPeriod)
burst = b""
while clearUart.any():
burst += clearUart.read()
if not clearUart.any(): # wait for a gap in the burst of at least 0.1 secs
sleep(delayPeriod)
del clearUart
If waitBefore is False, (you dont' hang on for characters in order to clear them), junk UART characters are visible later when you access the REPL.
However, if waitBefore is True, the routine hangs waiting for characters in bootClearUart.py and it's only after you connect to the REPL that the first character is sent by screen/miniterm and the other junk characters are sent preceding it. Since boot.py was blocked waiting to clear them, the REPL then doesn't see them. However to achieve this boot.py is hung waiting for the first character and main.py is not run until you type something into the REPL.
The burst of characters sent when you type your first character into the REPL can be introspected like this...
Code: Select all
>>> from vgkits.util.bootClearUart import burst
>>> burst
b'\xc0\xc8\x85\xe5\x8a^H\xcc'
Latest suspicion is that they are (non-zeroed?) CH340 buffer contents in the linux driver, or possibly somewhere else in the chain but they are not flushed from the client side until you type your first character in screen/miniterm. Alternatively there is something screwy about stability of the RX which unique to startup on this board layout (and its power arrangements) and leading to transient noise. The board looks like...
. Otherwise there should be no difference between these boards and any other 1Meg EP8266.
At this point if I want main.py routines to be run on this board...
* without blocking waiting for the first character
AND
* without causing junk characters to be sent
...it seems like I have two options...
1) Create my own image with a modified
main.c with an extra pyexec_frozen_module('bootClearUart.py') after
but before
This would invoke the (hanging) logic to clear the UART after main.py, and would do no harm except throwing away the first character when you finally decide to run the REPL, since boot.py and main.py are not blocked waiting. Given the latest upip.py cannot be loaded and run on ESP8266 as a source module, and given I plan to distribute a
set of modules on the board a bespoke image may be a good idea to defeat memory issues for learners anyway.
2) Accept there is always junk and advise users to always start their session with a CTRL+C to get a prompt (and ignore anything shown on screen). This is now a reasonable fallback as it is consistent, and probably advisable whatever state the REPL is in.