Skip to content

Commit 349e313

Browse files
committed
refactor(USBDevice): move USB device support as a built-in library
It could propbaly be splitted in 3 libraries: - USBDevice: base support - USBDCDC - USBDHID Signed-off-by: Frederic Pillon <[email protected]>
1 parent 17bcdd1 commit 349e313

38 files changed

+129
-26
lines changed

License.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Note: most license information is available on top of each source file
99

1010
[BSD 3-Clause License](#bsd-3-clause-license) is used for:
1111

12-
* cores/arduino/stm32/ mainly contains source from STMicroelectronics.
1312
* system/Drivers/STM32*xx_HAL_Driver folders include the STMicroelectronics HAL Drivers.
1413
* system/Middlewares/OpenAMP folders.
1514
* libraries/VirtIO/ OpenAMP part except virtio* implementation see [MIT License](#mit-license)
1615
* libraries/SrcWrapper/inc/PinName*.h
1716

1817
[Ultimate Liberty License](#Ultimate-Liberty-License) is used for:
1918
* system/Middlewares/STM32_USB_*_Library/ folders
19+
* libraries/USBDevice/ (see header)
2020

2121
[Apache License](#apache-license) is used for:
2222
* system/Drivers/CMSIS folder includes the STMicroelectronics CMSIS device

cmake/set_base_arduino_config.cmake

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ target_include_directories(base_config INTERFACE
5555
"${BUILD_CORE_PATH}"
5656
"${BUILD_CORE_PATH}/avr"
5757
"${BUILD_CORE_PATH}/stm32"
58-
"${BUILD_CORE_PATH}/stm32/usb"
59-
"${BUILD_CORE_PATH}/stm32/usb/hid"
60-
"${BUILD_CORE_PATH}/stm32/usb/cdc"
6158
"${BUILD_LIB_PATH}/SrcWrapper/inc"
6259
"${BUILD_LIB_PATH}/SrcWrapper/inc/LL"
60+
"${BUILD_LIB_PATH}/USBDevice/inc"
6361
"${BUILD_LIB_PATH}/VirtIO/inc"
6462
"${BUILD_SYSTEM_PATH}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc"
6563
"${BUILD_SYSTEM_PATH}/Middlewares/ST/STM32_USB_Device_Library/Core/Src"

cmake/templates/easy_cmake.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ build_sketch(TARGET "{{tgtname or "@binary_name_here@"}}"
9191
# SD
9292
# Wire
9393
# SPI
94+
# USBDevice
9495
# VirtIO
9596
)
9697

cores/arduino/CMakeLists.txt

-13
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,8 @@ add_library(core_bin STATIC EXCLUDE_FROM_ALL
3232
Print.cpp
3333
RingBuffer.cpp
3434
stm32/startup_stm32yyxx.S
35-
stm32/usb/cdc/cdc_queue.c
36-
stm32/usb/cdc/usbd_cdc.c
37-
stm32/usb/cdc/usbd_cdc_if.c
38-
stm32/usb/hid/usbd_hid_composite.c
39-
stm32/usb/hid/usbd_hid_composite_if.c
40-
stm32/usb/usb_device_core.c
41-
stm32/usb/usb_device_ctlreq.c
42-
stm32/usb/usb_device_ioreq.c
43-
stm32/usb/usbd_conf.c
44-
stm32/usb/usbd_desc.c
45-
stm32/usb/usbd_ep_conf.c
46-
stm32/usb/usbd_if.c
4735
Stream.cpp
4836
Tone.cpp
49-
USBSerial.cpp
5037
WInterrupts.cpp
5138
wiring_analog.c
5239
wiring_digital.c

cores/arduino/WSerial.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include "variant.h"
55
#include "HardwareSerial.h"
6-
#include "USBSerial.h"
6+
#if defined (USBCON) && defined(USBD_USE_CDC)
7+
#include "USBSerial.h"
8+
#endif /* USBCON && USBD_USE_CDC */
79
#if defined(VIRTIOCON)
810
#include "VirtIOSerial.h"
911
#endif /* VIRTIOCON */

libraries/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ add_subdirectory(SPI)
1010
add_subdirectory(Servo)
1111
add_subdirectory(SoftwareSerial)
1212
add_subdirectory(SrcWrapper)
13+
add_subdirectory(USBDevice)
1314
add_subdirectory(VirtIO)
1415
add_subdirectory(Wire)

libraries/SrcWrapper/src/stm32/hw_config.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include "dwt.h"
1414
#include "hw_config.h"
1515
#include "clock.h"
16-
#include "usbd_if.h"
16+
#if defined (USBCON) && defined(USBD_USE_CDC)
17+
#include "usbd_if.h"
18+
#endif
1719

1820
#ifdef __cplusplus
1921
extern "C" {

libraries/USBDevice/CMakeLists.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# v3.21 implemented semantic changes regarding $<TARGET_OBJECTS:...>
2+
# See https://cmake.org/cmake/help/v3.21/command/target_link_libraries.html#linking-object-libraries-via-target-objects
3+
cmake_minimum_required(VERSION 3.21)
4+
5+
add_library(USBDevice INTERFACE)
6+
add_library(USBDevice_usage INTERFACE)
7+
8+
target_include_directories(USBDevice_usage INTERFACE
9+
src
10+
)
11+
12+
13+
target_link_libraries(USBDevice_usage INTERFACE
14+
base_config
15+
)
16+
17+
target_link_libraries(USBDevice INTERFACE USBDevice_usage)
18+
19+
20+
21+
add_library(USBDevice_bin OBJECT EXCLUDE_FROM_ALL
22+
src/cdc/cdc_queue.c
23+
src/cdc/usbd_cdc.c
24+
src/cdc/usbd_cdc_if.c
25+
src/hid/usbd_hid_composite.c
26+
src/hid/usbd_hid_composite_if.c
27+
src/usb_device_core.c
28+
src/usb_device_ctlreq.c
29+
src/usb_device_ioreq.c
30+
src/usbd_conf.c
31+
src/usbd_desc.c
32+
src/usbd_ep_conf.c
33+
src/usbd_if.c
34+
src/USBSerial.cpp
35+
)
36+
target_link_libraries(USBDevice_bin PUBLIC USBDevice_usage)
37+
38+
target_link_libraries(USBDevice INTERFACE
39+
USBDevice_bin
40+
$<TARGET_OBJECTS:USBDevice_bin>
41+
)
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
void setup() {
2+
// put your setup code here, to run once:
3+
4+
}
5+
6+
void loop() {
7+
// put your main code here, to run repeatedly:
8+
9+
}
File renamed without changes.
File renamed without changes.

libraries/USBDevice/keywords.txt

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#######################################
2+
# Syntax Coloring Map For USBDevice
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
USBSerial KEYWORD1
9+
10+
#######################################
11+
# Methods and Functions (KEYWORD2)
12+
#######################################
13+
SerialUSB KEYWORD2
14+
begin KEYWORD2
15+
available KEYWORD2
16+
availableForWrite KEYWORD2
17+
peek KEYWORD2
18+
read KEYWORD2
19+
readBytes KEYWORD2
20+
readBytesUntil
21+
write KEYWORD2
22+
flush KEYWORD2
23+
baud KEYWORD2
24+
stopbits KEYWORD2
25+
paritytype KEYWORD2
26+
numbits KEYWORD2
27+
dtr KEYWORD2
28+
dtr KEYWORD2
29+
rts KEYWORD2
30+
31+
#######################################
32+
# Constants (LITERAL1)
33+
#######################################
34+
USBD_VID LITERAL1
35+
USBD_PID LITERAL1
36+
USBD_MANUFACTURER_STRING LITERAL1
37+
ONE_STOP_BIT LITERAL1
38+
ONE_AND_HALF_STOP_BIT LITERAL1
39+
TWO_STOP_BITS LITERAL1
40+
NO_PARITY LITERAL1
41+
ODD_PARITY LITERAL1
42+
EVEN_PARITY LITERAL1
43+
MARK_PARITY LITERAL1
44+
SPACE_PARITY LITERAL1
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=USBDevice
2+
version=1.0.0
3+
author=Frederic Pillon
4+
maintainer=stm32duino
5+
sentence=Enables the USB device support CDC or HID.
6+
paragraph=
7+
category=Communication
8+
url=https://github.com/stm32duino/Arduino_Core_STM32
9+
architectures=stm32

libraries/USBDevice/src/USBDevice.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef __USBD_H__
2+
#define __USBD_H__
3+
4+
#endif /* __USBD_H__ */
File renamed without changes.
File renamed without changes.

platform.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ tools_bin_path.macosx={runtime.tools.STM32Tools.path}/macosx
2424
tools_bin_path.linux={runtime.tools.STM32Tools.path}/linux
2525

2626
core_stm32_dir={build.core.path}/stm32
27-
core_usb_dir={core_stm32_dir}/usb
2827
hal_dir={build.system.path}/Drivers/{build.series}_HAL_Driver
2928
cmsis_dir={runtime.tools.CMSIS-5.9.0.path}/CMSIS
3029
cmsis_dev_dir={build.system.path}/Drivers/CMSIS/Device/ST/{build.series}
3130
usbd_core_dir={build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core
3231
SrcWrapper_include_dir={runtime.platform.path}/libraries/SrcWrapper/inc
3332
VirtIO_include_dir={runtime.platform.path}/libraries/VirtIO/inc
33+
USBDevice_include_dir={runtime.platform.path}/libraries/USBDevice/inc
34+
3435

3536
# STM compile variables
3637
# ----------------------
37-
compiler.stm.extra_include="-I{build.source.path}" "-I{build.core.path}/avr" "-I{core_stm32_dir}" "-I{SrcWrapper_include_dir}" "-I{SrcWrapper_include_dir}/LL" "-I{core_usb_dir}" "-I{core_usb_dir}/hid" "-I{core_usb_dir}/cdc" "-I{hal_dir}/Inc" "-I{hal_dir}/Src" "-I{build.system.path}/{build.series}" "-I{usbd_core_dir}/Inc" "-I{usbd_core_dir}/Src" "-I{VirtIO_include_dir}" {build.virtio_extra_include}
38+
compiler.stm.extra_include="-I{build.source.path}" "-I{build.core.path}/avr" "-I{core_stm32_dir}" "-I{SrcWrapper_include_dir}" "-I{SrcWrapper_include_dir}/LL" "-I{hal_dir}/Inc" "-I{hal_dir}/Src" "-I{build.system.path}/{build.series}" "-I{USBDevice_include_dir}" "-I{usbd_core_dir}/Inc" "-I{usbd_core_dir}/Src" "-I{VirtIO_include_dir}" {build.virtio_extra_include}
3839
compiler.arm.cmsis.c.flags="-I{cmsis_dir}/Core/Include/" "-I{cmsis_dev_dir}/Include/" "-I{cmsis_dev_dir}/Source/Templates/gcc/" "-I{cmsis_dir}/DSP/Include" "-I{cmsis_dir}/DSP/PrivateInclude"
3940

4041
compiler.warning_flags=-w
@@ -146,7 +147,7 @@ build.opt.path={build.path}/sketch/{build.opt.name}
146147
extras.path={build.system.path}/extras
147148

148149
# Create {build.opt} if not exists in the output sketch dir and force include of SrcWrapper library
149-
recipe.hooks.prebuild.1.pattern="{busybox}" sh "{extras.path}/prebuild.sh" "{build.path}" "{build.source.path}" "{runtime.platform.path}" "{build.enable_virtio}"
150+
recipe.hooks.prebuild.1.pattern="{busybox}" sh "{extras.path}/prebuild.sh" "{build.path}" "{build.source.path}" "{runtime.platform.path}" "usb={build.enable_usb}" "virtio={build.enable_virtio}"
150151
recipe.hooks.postbuild.1.pattern="{busybox}" sh "{extras.path}/postbuild.sh" "{build.path}" "{build.series}" "{runtime.platform.path}"
151152

152153
# compile patterns

system/extras/prebuild.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
BUILD_PATH="$1"
44
BUILD_SOURCE_PATH="$2"
55
BOARD_PLATFORM_PATH="$3"
6-
BUILD_VIRTIO="$4"
6+
BUILD_USB="$4"
7+
BUILD_VIRTIO="$5"
78

89
# Create sketch dir if not exists
910
if [ ! -f "$BUILD_PATH/sketch" ]; then
@@ -45,6 +46,10 @@ printf '\n-fmacro-prefix-map="%s"=.' "${prefix}" >>"$BUILD_PATH/sketch/build.opt
4546

4647
# Force include of SrcWrapper library
4748
echo "#include <SrcWrapper.h>" >"$BUILD_PATH/sketch/requiredLibraries.cpp"
49+
# Force include of USBDevice library if required
50+
if [ -n "${BUILD_USB#*=}" ]; then
51+
echo "#include <USBDevice.h>" >>"$BUILD_PATH/sketch/requiredLibraries.cpp"
52+
fi
4853
# Force include of VirtIO library if required
4954
if [ -n "${BUILD_VIRTIO#*=}" ]; then
5055
echo "#include <VirtIO.h>" >>"$BUILD_PATH/sketch/requiredLibraries.cpp"

tools/platformio/platformio-build.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,9 @@ def get_arduino_board_id(board_config, mcu):
258258
CPPPATH=[
259259
join(FRAMEWORK_DIR, "cores", "arduino", "avr"),
260260
join(FRAMEWORK_DIR, "cores", "arduino", "stm32"),
261-
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb"),
262-
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb", "hid"),
263-
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb", "cdc"),
264261
join(FRAMEWORK_DIR, "libraries", "SrcWrapper", "inc"),
265262
join(FRAMEWORK_DIR, "libraries", "SrcWrapper", "inc", "LL"),
263+
join(FRAMEWORK_DIR, "libraries", "USBDevice", "inc"),
266264
join(FRAMEWORK_DIR, "libraries", "VirtIO", "inc"),
267265
join(FRAMEWORK_DIR, "system", "Drivers", series + "_HAL_Driver", "Inc"),
268266
join(FRAMEWORK_DIR, "system", "Drivers", series + "_HAL_Driver", "Src"),

0 commit comments

Comments
 (0)