mirror of https://github.com/ARMmbed/mbed-os.git
Convert mbed-usb target, enable mbed-usb tests (#49)
* Convert mbed-usb target, enable mbed-usb tests * Fix ByteBuffer compile error * Add missing requirements, fix some pyserial issues * Move CDC_ECM to its own target since it needs RTOSpull/15339/head
parent
f317dbc335
commit
7cd7e60df8
|
|
@ -257,7 +257,6 @@ add_subdirectory(connectivity)
|
|||
|
||||
# The directories below contain optional target libraries
|
||||
add_subdirectory(drivers/device_key EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(drivers/usb EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(features EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
|
||||
|
|
|
|||
|
|
@ -53,3 +53,4 @@ target_sources(mbed-core-sources
|
|||
source/Watchdog.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(usb)
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
# Copyright (c) 2020 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
add_library(mbed-usb INTERFACE)
|
||||
if(MBED_ENABLE_OS_INTERNAL_TESTS)
|
||||
if(MBED_BUILD_GREENTEA_TESTS)
|
||||
add_subdirectory(tests/TESTS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_include_directories(mbed-usb
|
||||
INTERFACE
|
||||
include
|
||||
include/usb
|
||||
include/usb/internal
|
||||
)
|
||||
|
||||
target_sources(mbed-usb
|
||||
INTERFACE
|
||||
if("DEVICE_USBDEVICE=1" IN_LIST MBED_TARGET_DEFINITIONS)
|
||||
add_library(mbed-usb STATIC EXCLUDE_FROM_ALL
|
||||
source/AsyncOp.cpp
|
||||
source/ByteBuffer.cpp
|
||||
source/EndpointResolver.cpp
|
||||
|
|
@ -21,15 +18,43 @@ target_sources(mbed-usb
|
|||
source/TaskBase.cpp
|
||||
source/USBAudio.cpp
|
||||
source/USBCDC.cpp
|
||||
source/USBCDC_ECM.cpp
|
||||
source/USBDevice.cpp
|
||||
source/USBHID.cpp
|
||||
source/USBKeyboard.cpp
|
||||
source/USBMIDI.cpp
|
||||
source/USBMSD.cpp
|
||||
source/USBMouse.cpp
|
||||
source/USBMouseKeyboard.cpp
|
||||
source/USBSerial.cpp
|
||||
)
|
||||
source/USBSerial.cpp)
|
||||
|
||||
target_link_libraries(mbed-usb INTERFACE mbed-storage)
|
||||
target_include_directories(mbed-usb
|
||||
PUBLIC
|
||||
include
|
||||
include/usb
|
||||
include/usb/internal
|
||||
)
|
||||
|
||||
target_link_libraries(mbed-usb PUBLIC mbed-core-flags)
|
||||
|
||||
# USB Mass Storage Device library is separate because it pulls in a dependency on mbed-storage-blockdevice
|
||||
add_library(mbed-usb-msd STATIC EXCLUDE_FROM_ALL
|
||||
source/msd/USBMSD.cpp)
|
||||
|
||||
target_include_directories(mbed-usb-msd
|
||||
PUBLIC
|
||||
include/usb/msd
|
||||
)
|
||||
|
||||
target_link_libraries(mbed-usb-msd PUBLIC mbed-usb mbed-storage-blockdevice)
|
||||
|
||||
# USB CDC ECM library is separate because it pulls in a dependency on mbed-rtos-flags
|
||||
add_library(mbed-usb-cdc-ecm STATIC EXCLUDE_FROM_ALL
|
||||
source/cdc_ecm/USBCDC_ECM.cpp)
|
||||
|
||||
|
||||
target_include_directories(mbed-usb-cdc-ecm
|
||||
PUBLIC
|
||||
include/usb/cdc_ecm
|
||||
)
|
||||
|
||||
target_link_libraries(mbed-usb-cdc-ecm PUBLIC mbed-usb mbed-rtos-flags)
|
||||
endif()
|
||||
|
|
@ -0,0 +1 @@
|
|||
add_subdirectory(usb_device)
|
||||
|
|
@ -27,6 +27,12 @@ import serial.tools.list_ports as stlp
|
|||
import six
|
||||
import mbed_host_tests
|
||||
|
||||
# Pyserial 3.5 has a compatibility breaking capitalization change :((
|
||||
try:
|
||||
from serial import portNotOpenError as PortNotOpenError
|
||||
except ImportError:
|
||||
from serial import PortNotOpenError as PortNotOpenError
|
||||
|
||||
|
||||
MSG_KEY_DEVICE_READY = 'ready'
|
||||
MSG_KEY_SERIAL_NUMBER = 'usb_dev_sn'
|
||||
|
|
@ -130,7 +136,11 @@ class USBSerialTest(mbed_host_tests.BaseHostTest):
|
|||
|
||||
def port_open_wait(self):
|
||||
"""Open the serial and wait until it's closed by the device."""
|
||||
mbed_serial = serial.Serial(dsrdtr=False)
|
||||
|
||||
# Note: Need to set dsrdtr on open to true to avoid exception on Linux
|
||||
# https://github.com/pyserial/pyserial/issues/67
|
||||
mbed_serial = serial.Serial(dsrdtr=True)
|
||||
|
||||
mbed_serial.dtr = False
|
||||
try:
|
||||
mbed_serial.port = retry_fun_call(
|
||||
|
|
@ -148,12 +158,12 @@ class USBSerialTest(mbed_host_tests.BaseHostTest):
|
|||
mbed_serial.dtr = True
|
||||
try:
|
||||
mbed_serial.read() # wait until closed
|
||||
except (serial.portNotOpenError, serial.SerialException):
|
||||
except (PortNotOpenError, serial.SerialException):
|
||||
pass
|
||||
|
||||
def port_open_close(self):
|
||||
"""Open the serial and close it with a delay."""
|
||||
mbed_serial = serial.Serial(timeout=0.5, write_timeout=0.1, dsrdtr=False)
|
||||
mbed_serial = serial.Serial(timeout=0.5, write_timeout=0.1, dsrdtr=True)
|
||||
mbed_serial.dtr = False
|
||||
try:
|
||||
mbed_serial.port = retry_fun_call(
|
||||
|
|
@ -179,7 +189,7 @@ class USBSerialTest(mbed_host_tests.BaseHostTest):
|
|||
chunk_size defines the size of data sent in each write operation.
|
||||
The input buffer content is discarded.
|
||||
"""
|
||||
mbed_serial = serial.Serial(write_timeout=0.1, dsrdtr=False)
|
||||
mbed_serial = serial.Serial(write_timeout=0.1, dsrdtr=True)
|
||||
try:
|
||||
mbed_serial.port = retry_fun_call(
|
||||
fun=functools.partial(self.get_usb_serial_name, self.dut_usb_dev_sn), # pylint: disable=not-callable
|
||||
|
|
@ -214,7 +224,7 @@ class USBSerialTest(mbed_host_tests.BaseHostTest):
|
|||
|
||||
def loopback(self):
|
||||
"""Open the serial and send back every byte received."""
|
||||
mbed_serial = serial.Serial(timeout=0.5, write_timeout=0.1, dsrdtr=False)
|
||||
mbed_serial = serial.Serial(timeout=0.5, write_timeout=0.1, dsrdtr=True)
|
||||
mbed_serial.dtr = False
|
||||
try:
|
||||
mbed_serial.port = retry_fun_call(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
add_subdirectory(basic)
|
||||
add_subdirectory(hid)
|
||||
add_subdirectory(msd)
|
||||
add_subdirectory(serial)
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Copyright (c) 2022 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if(NOT "DEVICE_USBDEVICE=1" IN_LIST MBED_TARGET_DEFINITIONS)
|
||||
set(TEST_SKIPPED "USB Device is not supported for this target")
|
||||
endif()
|
||||
|
||||
mbed_greentea_add_test(
|
||||
TEST_NAME
|
||||
mbed-usb-device-basic
|
||||
TEST_SOURCES
|
||||
main.cpp
|
||||
USBEndpointTester.cpp
|
||||
USBTester.cpp
|
||||
HOST_TESTS_DIR
|
||||
"${CMAKE_CURRENT_LIST_DIR}/../../host_tests"
|
||||
TEST_SKIPPED
|
||||
${TEST_SKIPPED}
|
||||
TEST_REQUIRED_LIBS
|
||||
mbed-usb
|
||||
)
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if USB_DEVICE_TESTS
|
||||
#if DEVICE_USBDEVICE
|
||||
|
||||
#include "stdint.h"
|
||||
#include "stdlib.h"
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if USB_DEVICE_TESTS
|
||||
#if DEVICE_USBDEVICE
|
||||
|
||||
#include "stdint.h"
|
||||
#include "USBTester.h"
|
||||
|
|
|
|||
|
|
@ -15,10 +15,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if !USB_DEVICE_TESTS
|
||||
#error [NOT_SUPPORTED] usb device tests not enabled
|
||||
#else
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "mbed.h"
|
||||
|
|
@ -664,5 +660,4 @@ int main()
|
|||
Harness::run(specification);
|
||||
}
|
||||
|
||||
#endif // !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
|
||||
#endif // !defined(USB_DEVICE_TESTS)
|
||||
#endif // !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# Copyright (c) 2022 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if(NOT "DEVICE_USBDEVICE=1" IN_LIST MBED_TARGET_DEFINITIONS)
|
||||
set(TEST_SKIPPED "USB Device is not supported for this target")
|
||||
endif()
|
||||
|
||||
mbed_greentea_add_test(
|
||||
TEST_NAME
|
||||
mbed-usb-device-hid
|
||||
TEST_SOURCES
|
||||
main.cpp
|
||||
HOST_TESTS_DIR
|
||||
"${CMAKE_CURRENT_LIST_DIR}/../../host_tests"
|
||||
TEST_SKIPPED
|
||||
${TEST_SKIPPED}
|
||||
TEST_REQUIRED_LIBS
|
||||
mbed-usb
|
||||
)
|
||||
|
|
@ -15,11 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if !USB_DEVICE_TESTS
|
||||
#error [NOT_SUPPORTED] usb device tests not enabled
|
||||
#else
|
||||
|
||||
#if !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
|
||||
#if !DEVICE_USBDEVICE
|
||||
#error [NOT_SUPPORTED] USB Device not supported for this target
|
||||
#else
|
||||
|
||||
|
|
@ -388,5 +384,4 @@ int main()
|
|||
return !Harness::run(specification);
|
||||
}
|
||||
|
||||
#endif // !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
|
||||
#endif // !defined(USB_DEVICE_TESTS)
|
||||
#endif // !DEVICE_USBDEVICE
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
# Copyright (c) 2022 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if(NOT "DEVICE_USBDEVICE=1" IN_LIST MBED_TARGET_DEFINITIONS)
|
||||
set(TEST_SKIPPED "USB Device is not supported for this target")
|
||||
endif()
|
||||
|
||||
if(MBED_GREENTEA_TEST_BAREMETAL)
|
||||
set(TEST_SKIPPED "USB MSD test is not compatible with mbed-baremetal")
|
||||
endif()
|
||||
|
||||
mbed_greentea_add_test(
|
||||
TEST_NAME
|
||||
mbed-usb-device-msd
|
||||
TEST_SOURCES
|
||||
main.cpp
|
||||
HOST_TESTS_DIR
|
||||
"${CMAKE_CURRENT_LIST_DIR}/../../host_tests"
|
||||
TEST_SKIPPED
|
||||
${TEST_SKIPPED}
|
||||
TEST_REQUIRED_LIBS
|
||||
mbed-usb-msd
|
||||
mbed-storage-fat
|
||||
)
|
||||
|
|
@ -15,10 +15,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if !USB_DEVICE_TESTS
|
||||
#error [NOT_SUPPORTED] usb device tests not enabled
|
||||
#else
|
||||
|
||||
#if !defined(MBED_CONF_RTOS_PRESENT)
|
||||
#error [NOT_SUPPORTED] USB stack and test cases require RTOS to run.
|
||||
#else
|
||||
|
|
@ -492,5 +488,4 @@ int main()
|
|||
}
|
||||
|
||||
#endif // !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
|
||||
#endif // !defined(MBED_CONF_RTOS_PRESENT)
|
||||
#endif // !defined(USB_DEVICE_TESTS)
|
||||
#endif // !defined(MBED_CONF_RTOS_PRESENT)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# Copyright (c) 2022 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if(NOT "DEVICE_USBDEVICE=1" IN_LIST MBED_TARGET_DEFINITIONS)
|
||||
set(TEST_SKIPPED "USB Device is not supported for this target")
|
||||
endif()
|
||||
|
||||
mbed_greentea_add_test(
|
||||
TEST_NAME
|
||||
mbed-usb-device-serial
|
||||
TEST_SOURCES
|
||||
main.cpp
|
||||
HOST_TESTS_DIR
|
||||
"${CMAKE_CURRENT_LIST_DIR}/../../host_tests"
|
||||
TEST_SKIPPED
|
||||
${TEST_SKIPPED}
|
||||
TEST_REQUIRED_LIBS
|
||||
mbed-usb
|
||||
)
|
||||
|
|
@ -15,11 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if !USB_DEVICE_TESTS
|
||||
#error [NOT_SUPPORTED] usb device tests not enabled
|
||||
#else
|
||||
|
||||
#if !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
|
||||
#if !DEVICE_USBDEVICE
|
||||
#error [NOT_SUPPORTED] USB Device not supported for this target
|
||||
#else
|
||||
|
||||
|
|
@ -879,5 +875,4 @@ int main()
|
|||
return !Harness::run(specification);
|
||||
}
|
||||
|
||||
#endif // !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
|
||||
#endif // !defined(USB_DEVICE_TESTS)
|
||||
#endif // !DEVICE_USBDEVICE
|
||||
|
|
@ -2,4 +2,8 @@
|
|||
# It installs flashing support through the mbed tools packages and also the mbedhtrun test runner.
|
||||
mbed-host-tests
|
||||
mbed-greentea
|
||||
mbed-ls
|
||||
mbed-ls
|
||||
|
||||
# For USB Device host tests
|
||||
hidapi>=0.7.99
|
||||
pyusb>=1.2.0
|
||||
Loading…
Reference in New Issue