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

[USB Serial/JTAG Driver] use time-limited blocking for TX (IDFGH-8776) #10208

Conversation

chipweinberger
Copy link
Contributor

@chipweinberger chipweinberger commented Nov 18, 2022

Older PR: #10099

Tested working on a ESP32-S3.

Uses Ivan's suggestions for Usb Serial JTAG TX with the driver.

Instead of introducing this new function, would it instead make more sense to fix the TX-blocking-indefinitely behavior?

This is already done in usb_serial_jtag_tx_char with the TX_FLUSH_TIMEOUT_US check, we exit and drop the character if the flush doesn't happen for too long.

Seems like the same behavior could be achieved in usbjtag_tx_char_via_driver, by passing pdMS_TO_TICKS(TX_FLUSH_TIMEOUT_US / 1000) instead of portMAX_DELAY?

@chipweinberger
Copy link
Contributor Author

chipweinberger commented Nov 18, 2022

This PR was reopened due to renaming the branch.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Nov 18, 2022
@github-actions github-actions bot changed the title [USB Serial/JTAG Driver] use time-limited blocking for TX [USB Serial/JTAG Driver] use time-limited blocking for TX (IDFGH-8776) Nov 18, 2022
@chipweinberger chipweinberger force-pushed the user/chip/usb-serial-jtag-time-limited-blocking-tx-try-2 branch from fa12dd3 to de6fb9f Compare November 23, 2022 09:12
@chipweinberger
Copy link
Contributor Author

@igrr bump.


// try to send without blocking
if (xRingbufferSend(sjtag->tx_ring_buf, (void*) (src), size, 0)){
goto success;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: 4 spaces of indentation, and a space before the opening curly brace on the line above.

(Please try to adjust the code so it looks like the rest of the code nearby.)

if (xRingbufferSend(sjtag->tx_ring_buf, (void*) (src), size, ticks_to_wait)){
goto success;
} else {
sjtag->tx_blocking_attempts++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this variable is only ever compared to zero, can it be a boolean?

Copy link
Contributor Author

@chipweinberger chipweinberger Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could, but I found this variable name easier to reason about. perhaps: bool tx_has_tried_blocking;? lmk what you think of that name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_tried_blocking sounds understandable.

@@ -53,26 +53,26 @@ The USB Serial/JTAG Controller is able to put the {IDF_TARGET_NAME} into downloa
Limitations
===========

There are several limitations to the USB console feature. These may or may not be significant, depending on the type of application being developed, and the development workflow.
There are several limitations to the USB Serial/JTAG console feature. These may or may not be significant, depending on the type of application being developed, and the development workflow.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if mentioning JTAG here is less confusing. The JTAG part seems to have nothing to do with the CDC console?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USB console to me sounds ambiguous. Does it also refer to the USB OTG CDC Console?

"USB Serial/JTAG Console" != "USB OTG CDC Console". No?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically they are both "CDC", just implemented using two different peripherals. I thought that the title of the document makes it clear which one we are talking about, but maybe someone would land into the middle of the document from a Google search.

Let's keep the changes you made. If i get disagreement about this during the internal review, i will let you know.


3. The behavior between an actual USB-to-serial bridge chip and the USB Serial/JTAG Controller is slightly different if the ESP-IDF application does not listen for incoming bytes. An USB-to-serial bridge chip will just send the bytes to a (not listening) chip, while the USB Serial/JTAG Controller will block until the application reads the bytes. This can lead to a non-responsive looking terminal program.
3. The behavior between an actual USB-to-serial bridge chip and the USB Serial/JTAG Controller is slightly different. A USB-to-serial bridge chip will just send the bytes to a (not listening) chip, while the USB Serial/JTAG Controller will do a one-time wait of up to 50 milliseconds hoping for the terminal to read the bytes. This can add what appears to be a short "pause" in your ESP-IDF application.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the phrase "A USB-to-serial bridge chip will just send the bytes to a (not listening) chip," talks about the data transfer from PC to the ESP. The second part of the sentence now talks about the data transfer from ESP to PC.

I think the original sentence about PC terminal being unresponsive when the ESP doesn't "listen" is still valid here. You can expand the paragraph to explain the delay behavior for the transfer in the other direction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. confusing. maybe I can improve the wording.

@igrr
Copy link
Member

igrr commented Dec 8, 2022

Just a few minor notes @chipweinberger, looks good otherwise!

@chipweinberger chipweinberger force-pushed the user/chip/usb-serial-jtag-time-limited-blocking-tx-try-2 branch from b21b1df to e68d81e Compare December 8, 2022 08:13
@keenanjohnson
Copy link

+1 and thanks all for fixing this as it resolves some usb issues I have seen with the s3. Let me know if there is anything I can do to help push this along.

@igrr igrr added the PR-Sync-Merge Pull request sync as merge commit label Dec 14, 2022
@igrr
Copy link
Member

igrr commented Dec 14, 2022

sha=e68d81e25518650c7c1e1f9f7cbb2ed26f4128cf

@chipweinberger
Copy link
Contributor Author

@igrr, when will this land on master? I've never really understood what PR-Sync-Merge means or what happens from here.

@chipweinberger
Copy link
Contributor Author

bump :)

@espressif-bot espressif-bot assigned mythbuster5 and unassigned igrr Feb 24, 2023
@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new Status: Selected for Development Issue is selected for development Resolution: NA Issue resolution is unavailable labels Feb 24, 2023
@chipweinberger
Copy link
Contributor Author

Closing. Merged.

720b8d9

@chipweinberger chipweinberger deleted the user/chip/usb-serial-jtag-time-limited-blocking-tx-try-2 branch May 20, 2023 10:50
@chipweinberger chipweinberger restored the user/chip/usb-serial-jtag-time-limited-blocking-tx-try-2 branch May 20, 2023 10:50
@chipweinberger chipweinberger deleted the user/chip/usb-serial-jtag-time-limited-blocking-tx-try-2 branch May 20, 2023 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Sync-Merge Pull request sync as merge commit Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants