I implemented USB Device feature for Renesas mbed boards.
The code referenced the following code as a starting point and is implemented it by inheritting USBPhy same as other boards.
(mbed-os\features\unsupported\USBDevice\targets\TARGET_RENESAS)
A DTR line is used to signal that the host has configured a terminal and
is ready to transmit and receive data from the USB CDC/Serial device.
When this test suite is run with the use of a Linux host, a workaround has
to be used to overcome some platform specific DTR line behavior.
Every time the serial port file descriptor is opened, the DTR line is
asserted until the terminal attributes are set.
As a consequence, the device receives a premature DTR signal with a
duration of 200-500 us before the correct, long-lasting DTR signal set by
the host-side test script. (tested on the Linux kernel 4.15.0)
The solution is to wait for the first DTR spike, ignore it, and wait for
the correct DTR signal again.
Update the serial host test to set DTR low before opening a serial
port. Set DTR high once the serial object is ready. This ensures that
no data is sent by the device until the host is ready.
Despite having ECHO and ECHOCTL POSIX lflags disabled by default by
pyserial, a delay is needed for host to properly handle data received
from USB serial/CDC device.
With no delay host would echo 0x00-0x31 characters prefixed with '^'.
Ignore interrupts on disabled USB endpoints. This prevents handling
interrupts when in the wrong state.
Prior to this patch when running the serial test on a K64F the assert
on line 908 of USBDevice.cpp would sometimes be triggered. This
assert indicates that an endpoint 0 IN interrupt occurred before
the device was ready.
This occurs during the test_cdc_usb_reconnect test when the host sends
a "Set Control Line State" USB request and the device acknowledges it
just before USB is disconnected.
Although the USB spec sets the upper limit on FS isochronous endpoint
payloads to 1023 B, this value is hard to test in practice. Moreover,
not all the targets Mbed OS supports (like NUCLEO_F207ZG) are able to
handle all the endpoints set to max.
Fix the host script issues present on Windows machines.
Add 0 B payload size to bulk endpoints test.
Update halt and abort tests according to PR comments.
Add an explicit request to start reading on OUT endpoints.
When activating an endpoint assign new data rather than ORing
data to it. This ensures that values set from the previous use
do not effect the current configuration.
Update the patch "Create HAL_PCD_EP_Abort" to fix bugs.
This patch adds the low level functions USB_EPStopXfer, USB_EPSetNak,
USB_EPClearNak and the high level function HAL_PCD_EP_Abort so that
transfers can be stopped.
The functions USB_EPSetNak and USB_EPClearNak allow nak to be enabled
or disabled for an endpoint, preventing or allowing further transfers.
The function USB_EPStopXfer stops pending reads and writes started by
USB_EPStartXfer along with clearing and masking any interrupts enabled
by USB_EPStartXfer.
The function HAL_PCD_EP_Abort aborts any transfers on the given
endpoint. When this function completes the transfer interrupt
is guarenteed not to fire for this endpoint. Furthermore, the size
of data transferred during an aborted read can be found by calling
the function HAL_PCD_EP_GetRxCount.
Other notes on this Change:
1.
Prior to this patch the interrupt USB_OTG_DOEPINT_EPDISD was not
handled. When an OUT endpoint was disabled this interrupt occurred
causing the CPU to get stuck repeatedly handling this interrupt. This
is because this interrupt was unmasked but nothing cleared this
interrupt. This patch also adds code to handle and clear this
interrupt to prevent a lockup.
2.
Stopping a transfer on an OUT endpoint requires global nak OUT to
be in effect. Even with this being done, having entries in the rx fifo
prevented an OUT endpoint from being disabled. This behavior is not
mentioned in the Reference Manual.
It is undefined behavior if stalling and unstalling clears an ongoing
transfer. Abort any ongoing transfers explicitly when stalling and
unstalling so the behavior is consistent across devices.
If an IN endpoint is stalled during a transfer then the data being
sent will repeated and flood the USB bus. This patch prevents
endpoints from being stalled in the middle of a transfer by control
requests by keeping USB suspended until the setup phase of the
control request is done.
Add second constructor and reorder constructor parameters to match
other USB classes. Also remove the ready() function since there
are no calls that can only mbe made from a ready state.
Remove the endpoint parameter from endpoint callbacks. This
information is redundant because endpoints are known at
construction time because they must be in the configuration
descriptor.
Make the following fixes:
-deinit in destructor to prevent race conditions
-cancel the reset task before calling it since it may be in progress
-wait for tasks to complete without mutex held
-prevent double connect with _init flag