Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"could not complete raw paste" on SeeedStudio XIAO-ESP32C3 #8658

Open
aivarannamaa opened this issue Nov 25, 2023 · 29 comments
Open

"could not complete raw paste" on SeeedStudio XIAO-ESP32C3 #8658

aivarannamaa opened this issue Nov 25, 2023 · 29 comments

Comments

@aivarannamaa
Copy link

aivarannamaa commented Nov 25, 2023

CircuitPython version

Adafruit CircuitPython 9.0.0-alpha.5 on 2023-11-15; Seeed Studio XIAO ESP32C3 with ESP32-C3FN4

also 8.2.8 and 8.1.0

Code/REPL

> mpremote cp data.json :

Behavior

Similar issue was discussed in the context of Thonny (#7158), but the problem is reproducible also with mpremote (version 1.21.0).

Tried CP 8.2.8 and 9.0.0a5 on macOS Sonoma, Windows 11 and Ubuntu 23.10, also tried CP 8.1.0 on Ubuntu. All these tests failed in similar way -- mpremote would start writing the file but after a while wouldn't get raw paste confirmation from the device (it times out while trying to read a single byte).

I tried to upload this file: https://raw.githubusercontent.com/thonny/thonny/397679cd8f7eb11b20ba9075c694337f5aace54b/data/circuitpython-variants-esptool.json

When I cancelled the wait I got tracebacks like this (the first line shows the mpremote command line I used):

% mpremote cp data.json :
cp data.json :
 ... copying   6% [#-------------------]^CTraceback (most recent call last):
  File "/Users/aa/python_stuff/thonny/venv312/bin/mpremote", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/main.py", line 528, in main
    handler_func(state, args)
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/commands.py", line 159, in do_filesystem
    state.transport.filesystem_command(
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/transport_serial.py", line 476, in filesystem_command
    op(src2, dest2, progress_callback=progress_callback)
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/transport_serial.py", line 420, in fs_put
    self.exec("w(" + repr(data) + ")")
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/transport_serial.py", line 285, in exec
    ret, ret_err = self.exec_raw(command, data_consumer=data_consumer)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/transport_serial.py", line 271, in exec_raw
    self.exec_raw_no_follow(command)
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/transport_serial.py", line 249, in exec_raw_no_follow
    return self.raw_paste_write(command_bytes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/transport_serial.py", line 225, in raw_paste_write
    data = self.read_until(1, b"\x04")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/mpremote/transport_serial.py", line 118, in read_until
    data = self.serial.read(min_num_bytes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aa/python_stuff/thonny/venv312/lib/python3.12/site-packages/serial/serialposix.py", line 565, in read
    ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

Description

No response

Additional information

@aivarannamaa
Copy link
Author

aivarannamaa commented Nov 25, 2023

The same device (SeeedStudio XIAO-ESP32C3) is having problems also when trying to write files via the plain raw-REPL mode or via plain paste mode. In paste mode the echo starts going slightly off after a while, in raw mode the OK confirmation does not appear.

Nevertheless, I don't think the problem is specific to writing files. I changed the file writing procedure to a no-op, but made sure that the amount of serial communication stayed the same. The problem still persisted.

@bill88t
Copy link

bill88t commented Nov 26, 2023

Oh, the ESP32-Cx serial implementation is at fault here, no doubt about that.
The same flush desync/incomplete bug from what I can tell.

@tannewt tannewt added this to the Long term milestone Nov 28, 2023
@aivarannamaa
Copy link
Author

The problem persists in CP 9.0b0.

I wonder why is this issue in the "Long term" milestone? Is it too hard to be handled sooner or is it considered low priority?

@tannewt
Copy link
Member

tannewt commented Jan 29, 2024

I wonder why is this issue in the "Long term" milestone? Is it too hard to be handled sooner or is it considered low priority?

Thanks for retesting! It's a low priority because we only have one C3 board from Adafruit. It is hard to know difficulty until after it has been debugged and fixed.

@berkut0
Copy link

berkut0 commented Mar 29, 2024

I have a cheap board from the Chinese market and couple my own with mini modules.

Can confirm that 8.2.10 is installable and usable, but any 9+ versions have serious problems to work on ESP32-C3 (or just with Thonny, not completly sure)

I can describe the problem this way: by selecting different boards you can get about three states. Or it works and you can write to the console, but it hangs and reboots. Or it does not connect through Thonny. Or it is not recognised by the system at all as a normal device.

update: it is almost impossible to upload files on board with any version of CP:

adafruit-circuitpython-bundle-8.x-mpy-20231207\lib\adafruit_display_text_init_.mpy (4850 bytes)
PROBLEM IN THONNY'S BACK-END: Exception while handling 'upload' (thonny.plugins.micropython.mp_back.ProtocolError: Could not complete raw paste).
See Thonny's backend.log for more info.
You may need to press "Stop/Restart" or hard-reset your CircuitPython device and try again.

@RetiredWizard
Copy link

This is not a solution by any means but if you're keen on getting something working.... I have been able to use these board by uploading files using a serial transfer program similar to the way mpremote works. It's a little unfinished as I got it working "well enough" and left it at that. The UI is a bit weird but once you get used to it, works ok.

https://github.com/RetiredWizard/Serial-File-Manager

@SeanTheITGuy
Copy link

I have used ampy and the web file.manager without issue on c3 devices. With 8.2 through 9.1-beta.

@RetiredWizard
Copy link

Nice, I knew about ampy (https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy) once but completely forgot about it.

@UnexpectedMaker
Copy link

I've also been experiencing this on my TinyC6 and had to use a modified version of the Serial-File-Manager by @RetiredWizard to be able to communicate with my C6 boards running CP when under test on my test jigs.

It would be great if we could work out what this is as it seems to be specific to the Espressif serial UART setup in their C3/C6 chips, so will likely effect the H2, C61 and C5.

@berkut0
Copy link

berkut0 commented Mar 30, 2024

There is a non-zero chance that @aivarannamaa can fix something in Thonny and it will work. But it would be good to understand exactly what the problem is. There seem to be solutions that work. (But I suspect that the problem lies with Ampy itself)

I like the web file manager solution, thanks a lot for the tip, I'll give it a try

@RetiredWizard
Copy link

Since the C3 was on my mind, I pulled one out for a project I was working on yesterday. I did use ampy to get the initial settings.toml file loaded, but once it was connected to WiFi, I used the Web Workflow for everything. The File Browser to transfer files, the Internet based full code editor and associated internet based serial interface (not the CP hosted serital console) and everything went very smoothly. I was even able to use the Web Workflow feature of Circup to check and update the libraries on the device. It was an enjoyable workflow to use although I don't believe, other than Circup for the libraries the Web Workflow can be used to transfer files via a script (yet?).

Using Web Workflow is definitely another option to consider until the current serial UART isses are resolved.

@berkut0
Copy link

berkut0 commented Mar 31, 2024

Can confirm that Web Workflow can be a sort of workaround.
BUT! I am having trouble getting into the editor. It just writes to me:

Uh oh! It looks like you may be offline. You can go to the file browser if you'd like to work with files without connecting to the internet.

I'm not sure how to use CircUp in the case of Web Workflow, it only tries to detect serial connections. Would be great if you could share how you achieve this.

@UnexpectedMaker
Copy link

I've been doing some thorough testing of Ampy with my TinyC6 on my test jig setup - and I can confirm the issue is still present, but it's it succeeds more often than it fails.

90% of the time it works and I can PUT files on the TinyC6.
70% of the time I can RUN a file on the device

The rest of the times a RUN hangs and a PUT fails, or the device locks up serial comms after a task completes.

This is way better than what I have been experiencing with mpremote and shell which both fail > 80% of the time, but I'd love to work out why this is happening, so all tools can work 100% of the time.

I'm unable to use a web-worlflow for my use case - it needs to be USB based serial comms.

@berkut0
Copy link

berkut0 commented Mar 31, 2024

As there is some variety of very valuable in terms of makers chips, perhaps it is worth considering creating a new thread topic? Or maybe change the name to this one?

@UnexpectedMaker
Copy link

As there is some variety of very valuable in terms of makers chips, perhaps it is worth considering creating a new thread topic? Or maybe change the name to this one?

Well, the C3 and C6 both use the same UART peripheral, so whatever works or doesn't work for one, will be the same for the other, and all new chips from Espressif that use the same peripheral, like the C5, C61 and I believe the H2 + H4 will also have the same issues, so I think it's relevant token this here and not part multiple threads.

@RetiredWizard
Copy link

RetiredWizard commented Mar 31, 2024

I'm not sure how to use CircUp in the case of Web Workflow, it only tries to detect serial connections. Would be great if you could share how you achieve this.

circup --host xx.xx.xx.xx --pasword xxxx update

BUT! I am having trouble getting into the editor. It just writes to me:

It may not be applicable to you, but I found the C3 board I was using had less WiFi range than most boards I use and the Web Editor would sometimes give me that error when I wasn't close enough to the router.

EDIT: I just re-read your message and the error you indicated actually suggests that your host machine can't reach the internet to get the full code editor and not a C3 WiFi range issue. In early testing I remember getting that message but I don't remember why it was happening. I haven't seen it recently.

@tannewt tannewt modified the milestones: Long term, 9.x.x Apr 1, 2024
@berkut0
Copy link

berkut0 commented Apr 2, 2024

@RetiredWizard The problem lies in my browser settings. They're too restrictive. I've created a special profile to work with C3, although it's a rather controversial solution.

@dhalbert
Copy link
Collaborator

dhalbert commented Apr 5, 2024

Research this in esp-idf issues. See if increasing our buffer size would help.

@RetiredWizard
Copy link

RetiredWizard commented Apr 6, 2024

The larger buffer may help, but it looks to me like there's an XOFF/XON functionality missing. Once the buffer is full, the data seems to continue to flow and just get lost.

I was trying to paste code into the REPL (after pressing CTRL-E) on an ESP32 Sunton board today and had to break the copy/pastes into smaller blocks because attempting to copy the whole file, about 24 lines of code, didn't work. The first few lines seem to paste fine but then some of the characters were dropped from the remaining text. The display board may exaggerate the issue because the speed of the REPL appears to be reduced dramatically when it's being displayed on the attached display.

@dhalbert
Copy link
Collaborator

dhalbert commented Apr 7, 2024

USB-serial converters don't need to literally send XON/XOFF in-band, usually, because they are able just to stall the USB transfer to do flow control. However, that is apparently not enabled or something on these C3 builds. I haven't looked at the code yet.

@dhalbert
Copy link
Collaborator

dhalbert commented Apr 11, 2024

Does anyone have a simpler reproduction case that involves just pasting into the REPL or similar, and not using a file manager? I tried pasting long lines, and they seem fine with 9.0.3 on the QT Py ESP32-C3.

@RetiredWizard
Copy link

Did you mean ESP32-S3? I think this issue shows up on chips that don't support the Circuitpy drive, i.e. ESP32, ESP32-C3, ESP32-C6.

@dhalbert
Copy link
Collaborator

Did you mean ESP32-S3? I think this issue shows up on chips that don't support the Circuitpy drive, i.e. ESP32, ESP32-C3, ESP32-C6.

No, sorry, that was a typo, and is fixed to C3.

@bill88t
Copy link

bill88t commented Apr 11, 2024

For me, plain ESP32 has been rock solid. I have only had issues on ESP-Cx.

@RetiredWizard
Copy link

I've tried with both a QTPY Esp32-C3 and a SeeedXIAO-ESP32C3 to paste directly into the REPL after pressing CTRL-E, and the smaller pastes ~1.5k surprised me by working fine. When I tried pasting a larger python script (about 12.5k) the paste failed and left the board in a weird state. It didn't recognize Control keys and each key press seemed to process a bit of the paste buffer.

I also tried an ItsyBitsy ESP32 and the paste into the REPL (CTRL-E) failed on the smaller 1.5K file but didn't leave the board in the strange state so perhaps there is a different issue on the ESP32.

@dhalbert
Copy link
Collaborator

The USB-serial-jtag peripheral on the C3/C6 seems to have almost no configurable options. The doc seems to imply it will do USB stalling until its FIFO is read: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/usb-serial-jtag-console.html#data-buffering. But that is a rather high-level description of what is going on.

@RetiredWizard
Copy link

Does the USB-to-Serial bridge chip mentioned here refer to a chip on these development boards?

This is in contrast to using a USB-to-Serial (UART) bridge chip, which always ingests the bytes and sends them to a (possibly not listening) ESP32-C3.

If so, is this saying there is no flow control between these chips and the C3?

@UnexpectedMaker
Copy link

Does the USB-to-Serial bridge chip mentioned here refer to a chip on these development boards?

This is in contrast to using a USB-to-Serial (UART) bridge chip, which always ingests the bytes and sends them to a (possibly not listening) ESP32-C3.

If so, is this saying there is no flow control between these chips and the C3?

There are no external chips. The Serial JTAG bridge is inside the C3/C6. It's a native peripheral.

@dhalbert
Copy link
Collaborator

Chapter 30 in https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf describes the peripheral. It is fairly autonomous in what it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants