Closed congyue closed 1 month ago
Hi @congyue, thanks for reporting the issue. I will have a look at it as soon as possible.
Because I have other problems with the JTAG output, I scrolled through the driver code and have spotted this:
if (p_usb_serial_jtag_obj->fifo_status == FIFO_IDLE) {
portENTER_CRITICAL(&p_usb_serial_jtag_obj->spinlock);
atomic_store(&p_usb_serial_jtag_obj->fifo_status, FIFO_BUSY);
sent_data = usb_serial_jtag_write_and_flush(src, size);
portEXIT_CRITICAL(&p_usb_serial_jtag_obj->spinlock);
}
checking fifo_status only outside the lock is wrong, as it could be set between the check and acquiring the lock.
I'm seeing this issue too without using console
if I call usb_serial_jtag_driver_install
. If i remove that the issue goes away, but of course I can't read bytes from the serial_jtag anymore.
@johnboiles Are you referring to #14031? I still don't understand the exact cause of that but my guess is that wr_done is set twice, once from the actual writer and once from the driver ISR and the second one somehow discards the data. I wish espressif would extend the driver to support unbuffered write (with busy-waiting) when tx_buffer_size is set to 0.
I generally get output but it skips characters. Maybe 5% of characters.
I did notice a couple of times that output stopped altogether until a reboot. I didn't try to figure out the pattern. It might have been when I sent some bytes in the output stopped.
I expect both above spinlock bug and this issue can be fixed by this commit once it lands 5.2.3 release. Let's check it out!
@congyue, It seems that the issue persists even with the recent changes to the usb serial jtag driver you mentioned. It may not occur as often as it used to, but I can still see that once in a while, a character is skipped. As of now, I haven't been able to find the root cause of this skipping but I am still working on it.
@SoucheSouche Thanks for the update and spending time on it!
Just want to highlight again that the issue only happens if the caller task of printf is on the different core that the usb_serial_jtag ISR registered to. So there is an easier way to repro the issue:
Right now my workaround is to register the ISR to core 1 and make sure all important tasks are also pinned to core 1. But looking forward to know if this can be root caused!
FWIW, seems the root cause of the issue in the current master source is in the fsync implementation: it still pokes the hardware directly rather than ask the driver to (wait for a) flush. Should be a fix incoming soon.
Answers checklist.
General issue report
Hi Espressif team,
I have searched and read extensively about past issues on USB serial JTAG, (like https://github.com/espressif/esp-idf/issues/12518, https://github.com/espressif/esp-idf/issues/12628, https://github.com/espressif/esp-idf/issues/12605, https://github.com/espressif/esp-idf/issues/9318), most of them have been fixed in 5.2.2 but none of them directly related to this one.
First of all, here is my setup:
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
in sdkconfig.defaultI have prepared sample code to reproduce the issue:
It can be considered as a refactor of the usb_serial_jtag_echo project to use
read()/write()
VFS interface instead of the driver API.Expected behavior
The firmware suppose to simulate a shell and taking commands from input, then print a simulated output to the screen, e.g.
Most of the time this is fine and the issue is hard to be noticed when typing manually.
To make the issue easier to reproduce, I'm using this host script to stress testing the USB_serial_jtag input/output
Actual behavior
With the help of above script, sometimes I can see the output would randomly skip one byte:
Findings
fsync(fileno(stdout))
would make the situation worseI also noticed that below modification would cause the issue disappear:
echo_task
onPRO_CPU_NUM
instead.init_console();
function to the beginning ofecho_task()
Both approaches indicate the code perform better when the writing thread and interrupt both registered on the same core.This symptom is hard to find and it could lead to hard-to-debug issues on factory provisioning and automation test when relying on the USB port. It would be great if it can be root caused and fixed in future version!
@igrr @mythbuster5