Skip to content

Commit 7cd7e60

Browse files
author
Jamie Smith
authored
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 RTOS
1 parent f317dbc commit 7cd7e60

File tree

21 files changed

+157
-50
lines changed

21 files changed

+157
-50
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ add_subdirectory(connectivity)
257257

258258
# The directories below contain optional target libraries
259259
add_subdirectory(drivers/device_key EXCLUDE_FROM_ALL)
260-
add_subdirectory(drivers/usb EXCLUDE_FROM_ALL)
261260
add_subdirectory(features EXCLUDE_FROM_ALL)
262261
add_subdirectory(cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL)
263262
add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)

drivers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ target_sources(mbed-core-sources
5353
source/Watchdog.cpp
5454
)
5555

56+
add_subdirectory(usb)

drivers/usb/CMakeLists.txt

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
add_library(mbed-usb INTERFACE)
4+
if(MBED_ENABLE_OS_INTERNAL_TESTS)
5+
if(MBED_BUILD_GREENTEA_TESTS)
6+
add_subdirectory(tests/TESTS)
7+
endif()
8+
endif()
59

6-
target_include_directories(mbed-usb
7-
INTERFACE
8-
include
9-
include/usb
10-
include/usb/internal
11-
)
12-
13-
target_sources(mbed-usb
14-
INTERFACE
10+
if("DEVICE_USBDEVICE=1" IN_LIST MBED_TARGET_DEFINITIONS)
11+
add_library(mbed-usb STATIC EXCLUDE_FROM_ALL
1512
source/AsyncOp.cpp
1613
source/ByteBuffer.cpp
1714
source/EndpointResolver.cpp
@@ -21,15 +18,43 @@ target_sources(mbed-usb
2118
source/TaskBase.cpp
2219
source/USBAudio.cpp
2320
source/USBCDC.cpp
24-
source/USBCDC_ECM.cpp
2521
source/USBDevice.cpp
2622
source/USBHID.cpp
2723
source/USBKeyboard.cpp
2824
source/USBMIDI.cpp
29-
source/USBMSD.cpp
3025
source/USBMouse.cpp
3126
source/USBMouseKeyboard.cpp
32-
source/USBSerial.cpp
33-
)
27+
source/USBSerial.cpp)
28+
29+
target_include_directories(mbed-usb
30+
PUBLIC
31+
include
32+
include/usb
33+
include/usb/internal
34+
)
35+
36+
target_link_libraries(mbed-usb PUBLIC mbed-core-flags)
37+
38+
# USB Mass Storage Device library is separate because it pulls in a dependency on mbed-storage-blockdevice
39+
add_library(mbed-usb-msd STATIC EXCLUDE_FROM_ALL
40+
source/msd/USBMSD.cpp)
41+
42+
target_include_directories(mbed-usb-msd
43+
PUBLIC
44+
include/usb/msd
45+
)
46+
47+
target_link_libraries(mbed-usb-msd PUBLIC mbed-usb mbed-storage-blockdevice)
48+
49+
# USB CDC ECM library is separate because it pulls in a dependency on mbed-rtos-flags
50+
add_library(mbed-usb-cdc-ecm STATIC EXCLUDE_FROM_ALL
51+
source/cdc_ecm/USBCDC_ECM.cpp)
52+
53+
54+
target_include_directories(mbed-usb-cdc-ecm
55+
PUBLIC
56+
include/usb/cdc_ecm
57+
)
3458

35-
target_link_libraries(mbed-usb INTERFACE mbed-storage)
59+
target_link_libraries(mbed-usb-cdc-ecm PUBLIC mbed-usb mbed-rtos-flags)
60+
endif()
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(usb_device)

drivers/usb/tests/TESTS/host_tests/usb_device_serial.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
import six
2828
import mbed_host_tests
2929

30+
# Pyserial 3.5 has a compatibility breaking capitalization change :((
31+
try:
32+
from serial import portNotOpenError as PortNotOpenError
33+
except ImportError:
34+
from serial import PortNotOpenError as PortNotOpenError
35+
3036

3137
MSG_KEY_DEVICE_READY = 'ready'
3238
MSG_KEY_SERIAL_NUMBER = 'usb_dev_sn'
@@ -130,7 +136,11 @@ def __init__(self):
130136

131137
def port_open_wait(self):
132138
"""Open the serial and wait until it's closed by the device."""
133-
mbed_serial = serial.Serial(dsrdtr=False)
139+
140+
# Note: Need to set dsrdtr on open to true to avoid exception on Linux
141+
# https://github.com/pyserial/pyserial/issues/67
142+
mbed_serial = serial.Serial(dsrdtr=True)
143+
134144
mbed_serial.dtr = False
135145
try:
136146
mbed_serial.port = retry_fun_call(
@@ -148,12 +158,12 @@ def port_open_wait(self):
148158
mbed_serial.dtr = True
149159
try:
150160
mbed_serial.read() # wait until closed
151-
except (serial.portNotOpenError, serial.SerialException):
161+
except (PortNotOpenError, serial.SerialException):
152162
pass
153163

154164
def port_open_close(self):
155165
"""Open the serial and close it with a delay."""
156-
mbed_serial = serial.Serial(timeout=0.5, write_timeout=0.1, dsrdtr=False)
166+
mbed_serial = serial.Serial(timeout=0.5, write_timeout=0.1, dsrdtr=True)
157167
mbed_serial.dtr = False
158168
try:
159169
mbed_serial.port = retry_fun_call(
@@ -179,7 +189,7 @@ def send_data_sequence(self, chunk_size=1):
179189
chunk_size defines the size of data sent in each write operation.
180190
The input buffer content is discarded.
181191
"""
182-
mbed_serial = serial.Serial(write_timeout=0.1, dsrdtr=False)
192+
mbed_serial = serial.Serial(write_timeout=0.1, dsrdtr=True)
183193
try:
184194
mbed_serial.port = retry_fun_call(
185195
fun=functools.partial(self.get_usb_serial_name, self.dut_usb_dev_sn), # pylint: disable=not-callable
@@ -214,7 +224,7 @@ def send_data_sequence(self, chunk_size=1):
214224

215225
def loopback(self):
216226
"""Open the serial and send back every byte received."""
217-
mbed_serial = serial.Serial(timeout=0.5, write_timeout=0.1, dsrdtr=False)
227+
mbed_serial = serial.Serial(timeout=0.5, write_timeout=0.1, dsrdtr=True)
218228
mbed_serial.dtr = False
219229
try:
220230
mbed_serial.port = retry_fun_call(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_subdirectory(basic)
2+
add_subdirectory(hid)
3+
add_subdirectory(msd)
4+
add_subdirectory(serial)

0 commit comments

Comments
 (0)