Commit Graph

98 Commits (4625221f1e00df13412e5a0217d8dc9a4018ac28)

Author SHA1 Message Date
Russ Butler 4b609b6240 Add circular byte buffer using dynamic memory
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.
2019-02-22 10:53:17 -06:00
Russ Butler 9a35bc7184 Fix Kinetis bug causing USB to get stuck sending
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.
2019-02-22 10:53:17 -06:00
Russ Butler da77f3885b Fix isochronous endpoints on LPC1768
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.
2019-02-22 10:53:17 -06:00
Russ Butler 2fedc706e6 Fix USB on Kinetis devices
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
2019-02-22 10:53:17 -06:00
Russ Butler 7ba6314157 Only build in USBPhy_STM32 for supported devices
Define USBSTM_HAL_UNSUPPORTED if DEVICE_USBDEVICE is undefined or
defined to 0.
2019-02-22 10:53:16 -06:00
Russ Butler 3f45a81a81 Fix return code check in endpoint abort
Assert that HAL_PCD_EP_Abort returns HAL_OK rather that something else.
2019-02-22 10:53:16 -06:00
Michel Jaouen ced1cbd0ed Create HAL_PCD_EP_Abort 2019-02-22 10:53:16 -06:00
Russ Butler 17b61daf21 Remove unnecessary USB receive buffer
Remove receive buffer from USBPhy_STM32 and instead passed buffers in
directly.
2019-02-22 10:53:16 -06:00
Russ Butler 57fa607432 Remove ep0_write from set_address
The USBDevice stack automatically sends control endpoint status
so this does not and should not be done from the call to set_address.
2019-02-22 10:53:16 -06:00
Russ Butler a47c383233 Update the STM32 USB driver to the new API
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.
2019-02-22 10:53:16 -06:00
Russ Butler 67498e384a Implement LPC1768 USB abort function
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.
2019-02-22 10:53:16 -06:00
Russ Butler 044804200b Fix LPC1768 test failures
Reset endpoints when they are removed. This ensures buffers and the
data toggle bit get reset back to zero.
2019-02-22 10:53:16 -06:00
Russ Butler 9efccb20eb Add default values to USBCDC constructor
Add reasonable defaults to the USBCDC constructor so it is easier to
use.
2019-02-22 10:53:16 -06:00
Russ Butler 3dcd345efe Update the USBMIDI class
Update the USB class USBMIDI from the unsupported folder.
2019-02-22 10:53:16 -06:00
Russ Butler 9f94e4651a Require USB classes to implement descriptor
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.
2019-02-22 10:53:16 -06:00
Russ Butler 5ffe123973 Update USBHID and USBCDC for new AsyncOp
Update USB classes to use the new AsyncOp API.
2019-02-22 10:53:15 -06:00
Russ Butler c709f68434 Refactor AsyncOp class
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.
2019-02-22 10:53:15 -06:00
Russ Butler 3d429cf43f Update the USBHID classes
Update the USB classes USBHID, USBKeyboard, USBMouse and
USBMouseKeyboard from the unsupported folder.
2019-02-22 10:53:15 -06:00
Russ Butler 7e5e64bfdf Cleanup USBSerial
Make the following changes
-Make blocking the first parameter in the constructor
-Add destructor and proper cleanup
-Add ready and wait_ready functions
2019-02-22 10:53:15 -06:00
Russ Butler 11e2ba1f92 Add USBDevice destructor
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.
2019-02-22 10:53:14 -06:00
Russ Butler ced82dd16b Remove extra USBDevice constructor
Remove the second USBDevice constructor since it does not provide
any new functionality.
2019-02-22 10:53:14 -06:00
Russ Butler e3219cd016 Remove blocking option from USB connect
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.
2019-02-22 10:53:14 -06:00
Russ Butler 7245a33164 Fix Kinetis USB disconnect
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.
2019-02-22 10:53:14 -06:00
Russ Butler 630e6292c9 Prevent Kinetis USB setup packets at wrong time
When disconnecting USB clear all pending interrupts. This ensures that
pending setup packets are dropped rather than being triggered after
disconnect.
2019-02-22 10:53:14 -06:00
Maciej Bocianski 561a2407f4 USBDevice: endpoint_add/read_start functions return value fix 2019-02-22 10:53:13 -06:00
Russ Butler ca4a68649d Add endpoint_remove_all helper function
Add the helper function endpoint_remove_all which removes all added
endpoints. This is useful for class drivers switching between
different USB configurations.
2019-02-22 10:53:13 -06:00
Maciej Bocianski ff3b0c1623 code formatting fixes 2019-02-22 10:53:13 -06:00
Maciej Bocianski 69a095cf3e USBDevice - add multiconfiguration support 2019-02-22 10:53:13 -06:00
Russ Butler dc29fdefcc Add USBPhy template
Add a template for implementing a USBPhy.
2019-02-22 10:52:35 -06:00
Russ Butler 76aa7e0b6d Move USBPhy and related files to USB directory
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/*
2019-02-22 10:52:35 -06:00
Russ Butler 0653799b5a Limit USB control transfer size
Limit the size of control reads to the max packet size of endpoint
zero. This fixes the handling of large transfers.
2019-02-22 10:52:35 -06:00
Russ Butler 0eac26038d Update USBCDC and USBSerial
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.
2019-02-22 10:52:34 -06:00
Russ Butler 0d8c8f0a28 Add USB utility classes
Add an allocation free linked list implementation. Additionally add
the class AsyncOp which provides blocking and wakeup funcionality
to simplify making asynchronous operations block.
2019-02-22 10:52:34 -06:00
Russ Butler 09c1d2cf1e Add abort API to USBDevice
Add the function endpoint_abort and ensure ongoing transfer are
aborted when an endpoint is removed.
2019-02-22 10:52:34 -06:00
Russ Butler 544282d934 Update USBDevice to reflect the updated USBPhy
Update USBDevice so the USB buffers are user supplied.
2019-02-22 10:52:34 -06:00
Russ Butler 4c398a308f Call disconnect when uninitializing USB
Disconnect USB when uninitializing USB so it is in a well defined
state.
2019-02-22 10:52:33 -06:00
Russ Butler 12231917ef Explicitly return when endpoint 0 is stalled
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.
2019-02-22 10:52:33 -06:00
Russ Butler 8e2361a6b5 Allow transfer to start when configuring USB
Allow reads and writes to be started when entering the configured
state.
2019-02-22 10:52:33 -06:00
Russ Butler 7c96e22fa7 Move USBDevice processing out of user callbacks
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.
2019-02-22 10:52:33 -06:00
Russ Butler ff157a237a Update stall state on set and clear feature
Call USBDevice::endpoint_stall/unstall in the request to set/clear
halt so the endpoint state is properly updated in the array
_endpoint_info.
2019-02-22 10:52:33 -06:00
Russ Butler 23f3c01633 Fix USB init problems
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.
2019-02-22 10:52:33 -06:00
Russ Butler de12bb57fa Update USBTester for simplified read handling
Remove read_start and replace read_finish with read to match the new
USBDevice API.
2019-02-22 10:52:33 -06:00
Russ Butler 3168a92231 Change USBDevice read handling
Remove the USBDevice function read_start and automatically start all
reads internally in USBDevice. This patch also renames the function
read_finish to read.
2019-02-22 10:52:33 -06:00
Russ Butler 57ca5bc335 Add and assert USB callback completion
Assert that when a callback is completed it is the active callback.
2019-02-22 10:52:33 -06:00
Russ Butler caace4ac61 Update USBDevice and configure to use a USBPhy
Update the USBDevice class API so it matches mbed-os's naming
conventions, has a more robust API and uses USBPhy as its backend.
2019-02-22 10:52:32 -06:00
Russ Butler f7cb2cd280 Update USB licenses and format code
Update USB licenses from MIT to Apache 2 and run astyle on the code.
2019-02-22 10:52:32 -06:00
Russ Butler a4b6cfe90a Copy USBDevice from unsupported
Copy the USBDevice code out of unsupported and into a top level USB
folder in preparation for development.

squash
2019-02-22 10:52:32 -06:00
Russ Butler 8ae123f2d4 Add USBPhy, USB HAL and Utility class
Add the USBPhy and USBPhyEvents abstract classes, the HAL header using
this class and the EndpointResolver utility class.
2019-02-22 10:52:32 -06:00