chip/stm32: Fix for "deadlock" in UART forwarding

uServo, C2D2 or HyperDebug can get into a state in which the host
computer does not receive any serial characters via USB, despite the DUT
producing output on its UART.

The above happens if the character queue is filled and overflow BEFORE a
USB connection is established.  As the queue is already full, further
UART activity from the DUT does not result in the queue consumer being
notified.  On the consumer end, the queue is inspected only in the
function `usb_stream_deferred()`, which is called after every USB
transfer.  However, when the USB connection was established
`usb_stream_event()` would have set the TX endpoint to NAK (meaning no
data available for the host to receive), so there will be no USB
activity, and hence `usb_stream_deferred()` will never be called.  (At
least, not until a character is sent "the other way", by e.g. typing
in a CCD prompt.)

This CL modifies `usb_stream_event()` such that on USB connection
establishment/reset, it will inspect the character queue, and set the TX
endpoint to either VALID or NAK, depending on whether characters are
available in the queue.

BRANCH=servo
BUG=https://github.com/lowRISC/opentitan/issues/19564
TEST=observe HyperDebug able to perform serial flash of Ti50
TEST=make tast TAST_EXPR=gscdevboard.GSCTPM.*  (in ti50/common)

Change-Id: I5eb9c425afe6c1b7738253e9878c4e59299e0354
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/5415475
Tested-by: Jes Klinke <jbk@chromium.org>
Commit-Queue: Jes Klinke <jbk@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Jett Rink <jettrink@google.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
(cherry picked from commit 9503ba1529)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/5420395
This commit is contained in:
Jes B. Klinke 2024-04-02 13:34:25 -07:00 committed by Chromeos LUCI
parent 28911168a2
commit 15781b110e
1 changed files with 1 additions and 1 deletions

View File

@ -136,7 +136,7 @@ void usb_stream_event(struct usb_stream_config const *config,
config->state->rx_waiting = 0;
STM32_USB_EP(i) = ((i << 0) | /* Endpoint Addr*/
(2 << 4) | /* TX NAK */
(tx_write(config) ? EP_TX_VALID : EP_TX_NAK) |
(0 << 9) | /* Bulk EP */
(rx_disabled(config) ? EP_RX_NAK : EP_RX_VALID));
}