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
Take the code from
mbed-os\features\unsupported\USBDevice\targets\TARGET_STM
as a starting point and use it to fill in the USBPhy template for STM32
devices.
Implement the USB abort function so interrupts wont fire for a
transfer that has been aborted. The transfer may still take place
but the buffer passed into endpoint_write or endpoint_read will not
be used.
Make the function configuration_desc pure virtual inside USBDevice.
This should be a compile time error since no subclass will work
without a configuration descriptor.
Add the OperationList class to simplify managing async operations.
Add a callback to the AsyncOp class so completion can be signaled with
another mechanism. Finally rework the lock handling so AsyncOp::wait
is passed the lock to use rather than taking it in a constructor.
Make the following changes
-Make blocking the first parameter in the constructor
-Add destructor and proper cleanup
-Add ready and wait_ready functions
Add a destructor to USBDevice to ensure that resources have been
properly released. Additionally add an assert in the destructor that
deinit has already been called. If it has not been called then
interrupts can still occur which may cause a crash.
Remove the option to block in USBDevice::connect since this
should be handled at a higher level. Also call init to ensure that
the USBDevice has been initalized.
When disconnecting in the middle of a setup packet USB stops working
even after being re-connected. This is because the setup packet
suspended endpoint events but nothing resumed endpoint events.
This patch adds code to resume endpoint events in the reset handler.
Add the helper function endpoint_remove_all which removes all added
endpoints. This is useful for class drivers switching between
different USB configurations.
Move the USBPhy header files into usb/device/USBPhy. Also move hal
and target USB files since mbed 2 does not compile when these files
are present without the USBPhy headers.
Directory restructure summary:
platform/USBPhy*
to usb/device/USBPhy/USBPhy*
hal/*
to usb/device/hal/*
targets/TARGET_Freescale/usb/*
to usb/device/targets/TARGET_Freescale/*
targets/TARGET_NXP/TARGET_LPC176X/usb/*
to usb/device/targets/TARGET_NXP/*
Update the USBCDC and USBSerial classes to the new API. This patch also
updates the blocking behavior to unblock at the appropriate times and
to let the processor sleep when blocking rather than busy waiting.
Add an allocation free linked list implementation. Additionally add
the class AsyncOp which provides blocking and wakeup funcionality
to simplify making asynchronous operations block.
Stalling endpoint 0 indicates the end of a control transfer.
Return immediately when this occurs rather than continuing processing.
In particular, this patch prevents status from erroneously being
sent when _request_setup returns false inside _complete_request.
Perform processing triggered by user callbacks when USB is being
unlocked rather than synchronously. This prevents recursive callbacks
which reduces stack usage. This also prevents state change inside
the user callback which makes the code easier to reason about.
Initialize the _transfer structure so the behavior is the same
regardless of prior memory contents. This fixes a hang during
USB testing when CI flags are used.
Remove the USBDevice function read_start and automatically start all
reads internally in USBDevice. This patch also renames the function
read_finish to read.