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
Add the classes Task, TaskBase and TaskQueue. TaskQueue queue is an
interface class which can be implemented by anything which can run
code. Task and TaskBase are concrete classes which allow callbacks
to be posted to a TaskQueue to be run.
Only assert if disabled endpoints are used when USBDevice is
configured. USBDevice can leave the configured state due to a
reset at any time, which disables all endpoints. Because this
can happen at any time, thread processing could be performing
any endpoint operation. The endpoint operation should return
failure and do nothing in this case, rather than asserting
as this is not an application error.
An assert should only be triggered when an invalid endpoint is
used after the use of USBDevice acknoledges the switch to
configured mode by complete_set_configuration.
In specific this PR fixes the assert caused with the following
sequence:
-ISR: OUT event sent
-ISR: USB reset event
-ISR: USB configure request start
-Thread: OUT event processed on thread and next read starts
***endpoint is used while disabled causing an invalid assert***
-Thread: reset event processed
-Thread: configure event processed
This patch fixes this problem by making the following changes:
1. Operations done on disabled endpoints only assert when in the configured state
2. Adding and removing endpoints is only allowed when
the flag _endpoint_add_remove_allowed is set
3. The flag _endpoint_add_remove_allowed is set on the set
configuration request and cleared if the request is aborted or
fails
Remove calls to unlock which are not preceded by calls to lock.
Also move the location of the unlock underflow assert so unbalanced
unlocking during post processing is caught.
Fix the following warnings:
-[Warning] USBTester.cpp@45,0: #1299-D: members and base-classes will
be initialized in declaration order, not in member initialisation
list order
-[Warning] USBTester.h@41,0: #1300-D: ~USBTester inherits implicit
virtual
-[Warning] USBAudio.cpp@345,0: #1035-D: single-precision operand
implicitly converted to double-precision
-[Warning] USBHID.cpp@29,0: #1300-D: ~AsyncSend inherits implicit
virtual
-[Warning] USBHID.cpp@61,0: #1300-D: ~AsyncRead inherits implicit
virtual
-[Warning] USBHID.cpp@93,0: #1300-D: ~AsyncWait inherits implicit
virtual
-[Warning] EndpointResolver.cpp@125,26: '<<' in boolean context, did
you mean '<' ? [-Wint-in-bool-context]
Update the USBAudio class to use the new USB API. This patch also adds
buffering and blocking functionality so it can be used in practice
from thread context.
Add the ByteBuffer class which is similar to the CircularBuffer class
but uses dynamic memory rather than template parameters and is
optimized for byte transfers. This is required for USBAudio which
needs a high performance circular buffer which can be resized at
runtime.
If an IN endpoint is stalled during a transfer by writing to the
USB ENDPOINT register then the data being sent will repeat and flood
the USB bus. This patch prevents the register write from occurring by
instead writing to the buffer descriptor in RAM and letting the USB
hardware handle setting the stall bit.
Note - Control requests on endpoint 0 do still set the STALL bit
directly. This is not a problem since control endpoints cannot be
stalled externally while a transfer is ongoing.
Perform isochronous endpoint processing from the frame interrupt
rather than the endpoint interrupt. Isochronous endpoints to not
generate interrupts normally and are intended to be handled from
the start of frame interrupt.
Set correct SYSMPU register for proper USB operation. This bug was
introduced when the SYSMPU register names and defines were updated
in the commit:
"K64F: Updated the SYSMPU SDK driver"
93f8cfed05