mpremote: Writing fails when using mount and using multibyte characters.
I'm on MicroPython v1.21.0 on 2023-10-06; PORTENTA with STM32H747
The following script runs fine when executing it on the board e.g. mpremote connect id:3871345 run ./examples/demo.py
with open("foo.txt", 'w', encoding='utf-8') as file:
file.write("🔢 Data" + '\n')
file.write("🔢 Data" + '\n')
with open("foo.txt", 'r', encoding='utf-8') as file:
data = file.read()
print(data)
It correctly prints
🔢 Data
🔢 Data
However, when running it after mounting the current directory, it fails. e.g. mpremote connect id:387134 mount . run ./examples/demo.py
It prints
Local directory . is mounted at /remote
ta
ta
🔢 Da🔢 Da
Please note that the ta output is created by the write() function which shouldn't produce any output to the console.
If I modify the above example to write the following data, it stalls:
file.write("🔢 Data" + '\n' + "🔢 Data")
Looks like an issue with how multi byte characters are handled when using mount.
mpremote with mount fails on ESP32
Re-installed mpremote today - tail end of pip3:
Successfully installed mpremote-0.0.5
ESP32 works OK, with ctrl-d resetting the ESP uneventfully if there is no mount.
With a mount, ctrl-d kills mpremote. In the following, when the REPL appeared I pressed ctrl-d:
>>> [adminpete@capybara]: ~/temp
$ mpremote mount .
Local directory . is mounted at /remote
Connected to MicroPython at /dev/ttyUSB0
Use Ctrl-] to exit this shell
>
MicroPython v1.16 on 2021-06-28; ESP32 module with ESP32
Type "help()" for more information.
>>>
MPY: soft reboot
Traceback (most recent call last):
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/main.py", line 452, in main
do_repl(pyb, args)
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/main.py", line 332, in do_repl
do_repl_main_loop(
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/main.py", line 259, in do_repl_main_loop
pyb.soft_reset_with_mount(console_out_write)
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/pyboardextended.py", line 612, in soft_reset_with_mount
self.exec_(fs_hook_code)
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/pyboard.py", line 465, in exec_
ret, ret_err = self.exec_raw(command, data_consumer=data_consumer)
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/pyboard.py", line 456, in exec_raw
self.exec_raw_no_follow(command)
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/pyboard.py", line 453, in exec_raw_no_follow
raise PyboardError("could not exec command (response: %r)" % data)
mpremote.pyboard.PyboardError: could not exec command (response: b'R\x01')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/adminpete/.local/bin/mpremote", line 8, in <module>
sys.exit(main())
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/main.py", line 455, in main
do_disconnect(pyb)
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/main.py", line 208, in do_disconnect
pyb.umount_local()
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/pyboardextended.py", line 620, in umount_local
self.exec_('uos.umount("/remote")')
File "/home/adminpete/.local/lib/python3.8/site-packages/mpremote/pyboard.py", line 467, in exec_
raise PyboardError("exception", ret, ret_err)
mpremote.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 1, in <module>\r\nOSError: [Errno 22] EINVAL\r\n')