Commit Graph

22803 Commits (4284afd29701aeefac7ccfdf313bf5af95f502f3)

Author SHA1 Message Date
Russ Butler 4284afd297 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-02-22 10:53:17 -06:00
Russ Butler c08da25aa7 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-02-22 10:53:17 -06:00
Russ Butler 33756e2316 Add the PolledQueue implementation of TaskQueue
Add the PolledQueue class which provides a TaskQueue which is run
by calling PolledQueue::process.
2019-02-22 10:53:17 -06:00
Russ Butler 29e59d6b83 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-02-22 10:53:17 -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 793044eb26 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-02-22 10:53:17 -06:00
Russ Butler 6d88bd118f 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-02-22 10:53:17 -06:00
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
Maciej Bocianski d66e576227 USB basic test documentation update 2019-02-22 10:53:15 -06:00
Maciej Bocianski fee14771e9 USB basic test update
disable suspend/resume test
disable sync frame test
improve reset test
2019-02-22 10:53:15 -06:00
jeromecoutant 21606569da STM32F4: replace CLOCK_SOURCE_USB by DEVICE_USBDEVICE 2019-02-22 10:53:15 -06:00
jeromecoutant 9b16d4fb5b NUCLEO_F103RB: replace CLOCK_SOURCE_USB by DEVICE_USBDEVICE 2019-02-22 10:53:15 -06:00
Maciej Bocianski bcfe96b83c Update usb test to connect and block itself
Update the basic usb test so it does blocking itself since blocking
connect was removed from USBDevice.
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 9f94a5fc56 Fix typo in USBTester.h
Fix the spelling of product_release.
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
Maciej Bocianski 12c91c3b7e pyusb_basic test update
test code refactoring
align test to use device multiconfiguration
2019-02-22 10:53:14 -06:00
Maciej Bocianski e85d5a33cd pyusb_basic test add helper functions 2019-02-22 10:53:14 -06:00
Maciej Bocianski 972fee6143 pyusb_basic test formatting fixes 2019-02-22 10:53:14 -06:00
Maciej Bocianski 9b4970342b Extend USB test class configuration 2019-02-22 10:53:14 -06:00
Russ Butler 6bb6d6fb42 Explicitly specify USBPhy used for testing
Add a parameter to the USBPhy class so mock or wrapper USBPhy classes
can be used.
2019-02-22 10:53:14 -06:00
Russ Butler a341a7c258 Make USB disconnect + connect time explicit
Create the define MIN_DISCONNECT_TIME_US to be used as the amount of
time that must pass between connect and disconnect for the host to
reliably detect reconnection. Replace the wait calls delaying for this
value to wait_us to indicate the precision required. Finally, remove
the unnecessary calls to wait_ms in
repeated_construction_destruction_test.
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
Maciej Bocianski c2c3e01c36 USBDevice - add support for deconfiguration 2019-02-22 10:53:13 -06:00
Maciej Bocianski e4ffc6dea0 USB reset test fix 2019-02-22 10:53:13 -06:00