Commit Graph

75 Commits (feature-hal-spec-usb-device)

Author SHA1 Message Date
Russ Butler f8864ae307 Applied suggested astyle fixes 2019-01-29 15:45:18 -06:00
Russ Butler 5867e99bc9 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-01-29 15:31:24 -06:00
bcostm 28150d1d90 STM32F7 USB: add NUCLEO_F756ZG in pins definition 2019-01-29 12:27:33 -06:00
bcostm 9c83fe9ff0 STM32F7 USB: change VBUS pin for DISCO_F746NG FS 2019-01-29 12:27:33 -06:00
bcostm b91a196b22 STM32L4 USB: add pins definition for STM32L496/L4R5 MCUs 2019-01-29 12:27:33 -06:00
TomoYamanaka 2495386eda Renesas : Implement USB Device feature
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)
2019-01-29 12:27:33 -06:00
bcostm dd58a048f6 STM32F4 USB: remove useless macro 2019-01-29 12:27:33 -06:00
Russ Butler 83ffab6763 Ignore disabled Kinetis USB endpoint interrupts
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.
2019-01-29 12:27:31 -06:00
Russ Butler 805e5631a9 Remove HAL_GetTick from ST USBPhy
Remove the function HAL_GetTick from the ST USBPhy driver. This is no
longer needed as that change has been made on master.
2019-01-29 12:27:31 -06:00
Filip Jagodzinski 4c752ff057 USB: EndpointResolver: Add a generic method to get a free endpoint 2019-01-29 12:27:30 -06:00
Russ Butler 4dfc6debe5 Fix ST test failures due to endpoint reconfiguration
Also always use the max endpoint size for SetTxFifo
since re-configuring fifos when endpoints are added or removed
causes tests to fail.
2019-01-29 12:27:30 -06:00
Russ Butler b955d55553 Implement endpoint_abort for STM32
Make use of the added function HAL_PCD_EP_Abort to implement
endpoint_abort.
2019-01-29 12:27:29 -06:00
Russ Butler 6be6386d93 Revert "Create HAL_PCD_EP_Abort"
Revert the patch "Create HAL_PCD_EP_Abort" in preparation for an
alternate fix.
2019-01-29 12:27:29 -06:00
Russ Butler 882df808fa Reset data toggle on Kinetis when unstalling
Data toggle must be reset to DATA0 when an endpoint is unstalled.
This patch makes that change.
2019-01-29 12:27:29 -06:00
Russ Butler be5e7d3613 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-01-29 12:27:29 -06:00
Russ Butler 9745662f04 Alternate Kinetis USB stuck sending bug fix
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.
2019-01-29 12:27:29 -06:00
Russ Butler 067a1b0c7e Revert "Fix Kinetis bug causing USB to get stuck"
Revert the commit "Fix Kinetis bug causing USB to get stuck sending"
since this change causes stalls to be missed sometimes.
2019-01-29 12:27:29 -06:00
Russ Butler 09931588db Update USBMSD to be more consistent with others
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.
2019-01-29 12:27:29 -06:00
Russ Butler ddc27cb821 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-01-29 12:27:29 -06:00
Russ Butler af527b490c USBMSD fixes
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
2019-01-29 12:27:29 -06:00
Russ Butler 3b7201cc13 Update USBMSD
Update the USBMSD class for the new API. Add support for passing in
a BlockDevice directly without the need to extend USBMSD.
2019-01-29 12:27:28 -06:00
Russ Butler 96d9c244a3 Add the PolledQueue implementation of TaskQueue
Add the PolledQueue class which provides a TaskQueue which is run
by calling PolledQueue::process.
2019-01-29 12:27:28 -06:00
Russ Butler 572f9cb2e1 Add the TaskQueue abstract interface and friends
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.
2019-01-29 12:27:28 -06:00
Russ Butler 2c4686f468 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-01-29 12:27:28 -06:00
Russ Butler 6e8fe50ad2 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-01-29 12:27:28 -06:00
Russ Butler 6688857247 Fix various USB warnings
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]
2019-01-29 12:27:28 -06:00
Russ Butler ef18c07d1b Update USBAudio
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.
2019-01-29 12:27:28 -06:00
Russ Butler 376c213c88 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-01-29 12:27:28 -06:00
Russ Butler 073068aa36 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-01-29 12:27:28 -06:00
Russ Butler cbda2fb575 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-01-29 12:27:28 -06:00
Russ Butler 589b7f626d 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-01-29 12:27:28 -06:00
Russ Butler c31dfbc174 Only build in USBPhy_STM32 for supported devices
Define USBSTM_HAL_UNSUPPORTED if DEVICE_USBDEVICE is undefined or
defined to 0.
2019-01-29 12:27:28 -06:00
Russ Butler 4ce82d714a Fix return code check in endpoint abort
Assert that HAL_PCD_EP_Abort returns HAL_OK rather that something else.
2019-01-29 12:27:28 -06:00
Michel Jaouen 6ca7d2e828 Create HAL_PCD_EP_Abort 2019-01-29 12:27:27 -06:00
Russ Butler 21002c63dd Remove unnecessary USB receive buffer
Remove receive buffer from USBPhy_STM32 and instead passed buffers in
directly.
2019-01-29 12:27:27 -06:00
Russ Butler 0fa612e49d 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-01-29 12:27:27 -06:00
Russ Butler e7017270ef 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-01-29 12:27:27 -06:00
Russ Butler 513af70afe 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-01-29 12:27:27 -06:00
Russ Butler 4ba6741617 Fix LPC1768 test failures
Reset endpoints when they are removed. This ensures buffers and the
data toggle bit get reset back to zero.
2019-01-29 12:27:27 -06:00
Russ Butler c90c8b9dba Add default values to USBCDC constructor
Add reasonable defaults to the USBCDC constructor so it is easier to
use.
2019-01-29 12:27:27 -06:00
Russ Butler 30bb929982 Update the USBMIDI class
Update the USB class USBMIDI from the unsupported folder.
2019-01-29 12:27:27 -06:00
Russ Butler 3d605b672a 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-01-29 12:27:27 -06:00
Russ Butler 6984060b9f Update USBHID and USBCDC for new AsyncOp
Update USB classes to use the new AsyncOp API.
2019-01-29 12:27:27 -06:00
Russ Butler bfa9992c7d 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-01-29 12:27:27 -06:00
Russ Butler f1c00e48fe Update the USBHID classes
Update the USB classes USBHID, USBKeyboard, USBMouse and
USBMouseKeyboard from the unsupported folder.
2019-01-29 12:27:26 -06:00
Russ Butler 67b3993974 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-01-29 12:27:26 -06:00
Russ Butler beddff36e9 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-01-29 12:27:26 -06:00
Russ Butler 0c52350540 Remove extra USBDevice constructor
Remove the second USBDevice constructor since it does not provide
any new functionality.
2019-01-29 12:27:26 -06:00
Russ Butler 7df887fe69 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-01-29 12:27:26 -06:00
Russ Butler bdb8b5f342 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-01-29 12:27:25 -06:00