stm32/usbd_cdc_interface: Don't wait in usbd_cdc_tx_always if suspended.
stm32/usbd_cdc_interface: Don't wait in usbd_cdc_tx_always if suspended.

MCUs with device-only USB peripherals (eg L0, WB) do not implement (at
least not in the ST HAL) the HAL_PCD_DisconnectCallback event.  So if a USB
cable is disconnected the USB driver does not deinitialise itself
(usbd_cdc_deinit is not called) and the CDC driver can stay in the
USBD_CDC_CONNECT_STATE_CONNECTED state.  Then if the USB was attached to
the REPL, output can become very slow waiting in usbd_cdc_tx_always for
500ms for each character.

The disconnect event is not implemented on these MCUs but the suspend event
is.  And in the situation where the USB cable is disconnected the suspend
event is raised because SOF packets are no longer received.

The issue of very slow output on these MCUs is fixed in this commit (really
worked around) by adding a check in usbd_cdc_tx_always to see if the USB
device state is suspended, and, if so, breaking out of the 500ms wait loop.
This should also help all MCUs for a real USB suspend.

A proper fix for MCUs with device-only USB would be to implement or somehow
synthesise the HAL_PCD_DisconnectCallback event.

See issue #6672.

Signed-off-by: Damien George <99e6b749acbfbe2a596df99e91d24d6e1fdbee00@micropython.org>

henriknelson/micropython,bvernoux/micropython,adafruit/circuitpython,adafruit/circuitpython,bvernoux/micropython,bvernoux/micropython,henriknelson/micropython,adafruit/circuitpython,henriknelson/micropython,henriknelson/micropython,adafruit/circuitpython,bvernoux/micropython,henriknelson/micropython,adafruit/circuitpython,adafruit/circuitpython,bvernoux/micropython