-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
CircuitPython version
Adafruit CircuitPython 9.1.0 on 2024-07-10; Adafruit ItsyBitsy ESP32 with ESP32Code/REPL
NoneBehavior
When pasting more than about 500 characters into the REPL, either normal mode or CTRL-E paste mode, some of the characters being pasted get dropped.
Description
I started trouble shooting this in issue #9362 by pasting a 12.5K python script into the REPL using the Ctrl-E paste mode. The basic observation was:
When I paste code to a Ctrl-E repl of the ItsyBitsy ESP32 it consistently starts dropping characters after 255 characters. After skipping about 275 characters, another 124 characters are correctly received and then 937 characters are dropped followed by another 152 properly transmitted characters, etc.....
Additional information
I was able to improve the size of the file that could be pasted without error by decreasing the UART baud rate or increasing the console_uart_rx_buf size.
By commenting out the console echo of the pasted data, I was able to successfully paste the entire 12.5K script without error.
I also made a modification to common_hal_busio_uart_write module in ports/espressif/common-hal/busio/UART.c which I believe prevented the routine from waiting for the UART to become available when transmitting (echoing to the display) a character. This mod resulted in intermittent characters not being echo'd, however the REPL did receive the entire file without error. Increasing the SOC_UART_FIFO_LEN from 128 to 250 had the same result, I'm guessing this prevented the uart_ll_get_txfifo_len function from ever reporting the transmit buffer as full so the uart_writes were not held up.
After a lot of hacking and staring my current theory about what's happening is that the UART rx interrupts are coming in so fast and frequently that the UART is not able to echo the characters back out to the console. I think this results in the FIFO receive buffer filling up which causes ESP-IDF to disable the uart interrupts. That allows the transmit buffer to empty and display the first buffer full of characters, however while the interrupts are disabled, any characters being pasted are lost. The ESP-IDF then re-enables the interrupts when there is FIFO buffer space again and the cycle repeats.
Without the ability to get flow control to the CH9102 chip, I can't think of a great solution to this issue especially since it seems to be limited to the ESP32 boards. It should be noted that the issue doesn't impact RAW REPL mode, presumably because it doesn't echo data and therefore attempt to simultaneously use the UART for RX and TX functions.