Commit Graph

30 Commits (279f4cd5841f747c57d5de7c310c77fbba346ad4)

Author SHA1 Message Date
Russ Butler 3a891f9bfe Fix USB control transfers using small size
Fix support for wMaxPacketSize values other than 64 for endpoint 0.
2019-04-24 11:12:40 -05:00
Russ Butler 6527cf2bad Update files to include SPDX-License-Identifier
Update the header of all files to use a newer license template which
includes SPDX-License-Identifier.
2019-02-22 10:53:24 -06:00
Russ Butler 005df3559c Applied suggested astyle fixes 2019-02-22 10:53:23 -06:00
Russ Butler 8d731561cf Remove inclusion of mbed.h from USB
Remove mbed.h from USB files and fix the build errors this causes.
This is required to pass CI.
2019-02-22 10:53:23 -06:00
Russ Butler dbe41c3659 Abort the current USB transfer when stalling
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.
2019-02-22 10:53:18 -06:00
Russ Butler 799cde0fc3 Remove endpoint parameter from USB callbacks
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.
2019-02-22 10:53:18 -06:00
Russ Butler 322b4b72af Update USBDevice endpoint checks to fix asserts
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
2019-02-22 10:53:17 -06:00
Russ Butler d5fc72d5b4 Fix unbalanced USBDevice unlock
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.
2019-02-22 10:53:17 -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
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 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 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