Skip to content

Commit

Permalink
refactor(USBDevice): move USB device support as a built-in library
Browse files Browse the repository at this point in the history
It could propbaly be splitted in 3 libraries:
	- USBDevice: base support
	- USBDCDC
	- USBDHID

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
  • Loading branch information
fpistm committed Jun 19, 2024
1 parent 8136da7 commit 66b29ba
Show file tree
Hide file tree
Showing 38 changed files with 130 additions and 27 deletions.
4 changes: 2 additions & 2 deletions License.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Note: most license information is available on top of each source file

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

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

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

[Apache License](#apache-license) is used for:
* system/Drivers/CMSIS folder includes the STMicroelectronics CMSIS device
Expand Down
4 changes: 1 addition & 3 deletions cmake/set_base_arduino_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ target_include_directories(base_config INTERFACE
"${BUILD_CORE_PATH}"
"${BUILD_CORE_PATH}/avr"
"${BUILD_CORE_PATH}/stm32"
"${BUILD_CORE_PATH}/stm32/usb"
"${BUILD_CORE_PATH}/stm32/usb/hid"
"${BUILD_CORE_PATH}/stm32/usb/cdc"
"${BUILD_LIB_PATH}/SrcWrapper/inc"
"${BUILD_LIB_PATH}/SrcWrapper/inc/LL"
"${BUILD_LIB_PATH}/USBDevice/inc"
"${BUILD_LIB_PATH}/VirtIO/inc"
"${BUILD_SYSTEM_PATH}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc"
"${BUILD_SYSTEM_PATH}/Middlewares/ST/STM32_USB_Device_Library/Core/Src"
Expand Down
1 change: 1 addition & 0 deletions cmake/templates/easy_cmake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ build_sketch(TARGET "{{tgtname or "@binary_name_here@"}}"
# SD
# Wire
# SPI
# USBDevice
# VirtIO
)

Expand Down
13 changes: 0 additions & 13 deletions cores/arduino/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,8 @@ add_library(core_bin STATIC EXCLUDE_FROM_ALL
Print.cpp
RingBuffer.cpp
stm32/startup_stm32yyxx.S
stm32/usb/cdc/cdc_queue.c
stm32/usb/cdc/usbd_cdc.c
stm32/usb/cdc/usbd_cdc_if.c
stm32/usb/hid/usbd_hid_composite.c
stm32/usb/hid/usbd_hid_composite_if.c
stm32/usb/usb_device_core.c
stm32/usb/usb_device_ctlreq.c
stm32/usb/usb_device_ioreq.c
stm32/usb/usbd_conf.c
stm32/usb/usbd_desc.c
stm32/usb/usbd_ep_conf.c
stm32/usb/usbd_if.c
Stream.cpp
Tone.cpp
USBSerial.cpp
WInterrupts.cpp
wiring_analog.c
wiring_digital.c
Expand Down
4 changes: 3 additions & 1 deletion cores/arduino/WSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include "variant.h"
#include "HardwareSerial.h"
#include "USBSerial.h"
#if defined (USBCON) && defined(USBD_USE_CDC)
#include "USBSerial.h"
#endif /* USBCON && USBD_USE_CDC */
#if defined(VIRTIOCON)
#include "VirtIOSerial.h"
#endif /* VIRTIOCON */
Expand Down
1 change: 1 addition & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ add_subdirectory(SPI)
add_subdirectory(Servo)
add_subdirectory(SoftwareSerial)
add_subdirectory(SrcWrapper)
add_subdirectory(USBDevice)
add_subdirectory(VirtIO)
add_subdirectory(Wire)
4 changes: 3 additions & 1 deletion libraries/SrcWrapper/src/stm32/hw_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include "dwt.h"
#include "hw_config.h"
#include "clock.h"
#include "usbd_if.h"
#if defined (USBCON) && defined(USBD_USE_CDC)
#include "usbd_if.h"
#endif

#ifdef __cplusplus
extern "C" {
Expand Down
42 changes: 42 additions & 0 deletions libraries/USBDevice/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# v3.21 implemented semantic changes regarding $<TARGET_OBJECTS:...>
# See https://cmake.org/cmake/help/v3.21/command/target_link_libraries.html#linking-object-libraries-via-target-objects
cmake_minimum_required(VERSION 3.21)

add_library(USBDevice INTERFACE)
add_library(USBDevice_usage INTERFACE)

target_include_directories(USBDevice_usage INTERFACE
src
)


target_link_libraries(USBDevice_usage INTERFACE
base_config
)

target_link_libraries(USBDevice INTERFACE USBDevice_usage)



add_library(USBDevice_bin OBJECT EXCLUDE_FROM_ALL
src/cdc/cdc_queue.c
src/cdc/usbd_cdc.c
src/cdc/usbd_cdc_if.c
src/hid/usbd_hid_composite.c
src/hid/usbd_hid_composite_if.c
src/usb_device_core.c
src/usb_device_ctlreq.c
src/usb_device_ioreq.c
src/usbd_conf.c
src/usbd_desc.c
src/usbd_ep_conf.c
src/usbd_if.c
src/USBSerial.cpp
)
target_link_libraries(USBDevice_bin PUBLIC USBDevice_usage)

target_link_libraries(USBDevice INTERFACE
USBDevice_bin
$<TARGET_OBJECTS:USBDevice_bin>
)

9 changes: 9 additions & 0 deletions libraries/USBDevice/examples/BareMinimum/BareMinimum.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions libraries/USBDevice/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#######################################
# Syntax Coloring Map For USBDevice
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################
USBSerial KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################
SerialUSB KEYWORD2
begin KEYWORD2
available KEYWORD2
availableForWrite KEYWORD2
peek KEYWORD2
read KEYWORD2
readBytes KEYWORD2
readBytesUntil
write KEYWORD2
flush KEYWORD2
baud KEYWORD2
stopbits KEYWORD2
paritytype KEYWORD2
numbits KEYWORD2
dtr KEYWORD2
dtr KEYWORD2
rts KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
USBD_VID LITERAL1
USBD_PID LITERAL1
USBD_MANUFACTURER_STRING LITERAL1
ONE_STOP_BIT LITERAL1
ONE_AND_HALF_STOP_BIT LITERAL1
TWO_STOP_BITS LITERAL1
NO_PARITY LITERAL1
ODD_PARITY LITERAL1
EVEN_PARITY LITERAL1
MARK_PARITY LITERAL1
SPACE_PARITY LITERAL1
9 changes: 9 additions & 0 deletions libraries/USBDevice/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=USBDevice
version=1.0.0
author=Frederic Pillon
maintainer=stm32duino
sentence=Enables USB device support (CDC or HID).
paragraph=
category=Communication
url=https://github.com/stm32duino/Arduino_Core_STM32
architectures=stm32
4 changes: 4 additions & 0 deletions libraries/USBDevice/src/USBDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef __USBD_H__
#define __USBD_H__

#endif /* __USBD_H__ */
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ tools_bin_path.macosx={runtime.tools.STM32Tools.path}/macosx
tools_bin_path.linux={runtime.tools.STM32Tools.path}/linux

core_stm32_dir={build.core.path}/stm32
core_usb_dir={core_stm32_dir}/usb
hal_dir={build.system.path}/Drivers/{build.series}_HAL_Driver
cmsis_dir={runtime.tools.CMSIS-5.9.0.path}/CMSIS
cmsis_dev_dir={build.system.path}/Drivers/CMSIS/Device/ST/{build.series}
usbd_core_dir={build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core
SrcWrapper_include_dir={runtime.platform.path}/libraries/SrcWrapper/inc
VirtIO_include_dir={runtime.platform.path}/libraries/VirtIO/inc
USBDevice_include_dir={runtime.platform.path}/libraries/USBDevice/inc


# STM compile variables
# ----------------------
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}
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}
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"

compiler.warning_flags=-w
Expand Down Expand Up @@ -146,7 +147,7 @@ build.opt.path={build.path}/sketch/{build.opt.name}
extras.path={build.system.path}/extras

# Create {build.opt} if not exists in the output sketch dir and force include of SrcWrapper library
recipe.hooks.prebuild.1.pattern="{busybox}" sh "{extras.path}/prebuild.sh" "{build.path}" "{build.source.path}" "{runtime.platform.path}" "{build.enable_virtio}"
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}"
recipe.hooks.postbuild.1.pattern="{busybox}" sh "{extras.path}/postbuild.sh" "{build.path}" "{build.series}" "{runtime.platform.path}"

# compile patterns
Expand Down
7 changes: 6 additions & 1 deletion system/extras/prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
BUILD_PATH="$1"
BUILD_SOURCE_PATH="$2"
BOARD_PLATFORM_PATH="$3"
BUILD_VIRTIO="$4"
BUILD_USB="$4"
BUILD_VIRTIO="$5"

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

# Force include of SrcWrapper library
echo "#include <SrcWrapper.h>" >"$BUILD_PATH/sketch/requiredLibraries.cpp"
# Force include of USBDevice library if required
if [ -n "${BUILD_USB#*=}" ]; then
echo "#include <USBDevice.h>" >>"$BUILD_PATH/sketch/requiredLibraries.cpp"
fi
# Force include of VirtIO library if required
if [ -n "${BUILD_VIRTIO#*=}" ]; then
echo "#include <VirtIO.h>" >>"$BUILD_PATH/sketch/requiredLibraries.cpp"
Expand Down
4 changes: 1 addition & 3 deletions tools/platformio/platformio-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,9 @@ def get_arduino_board_id(board_config, mcu):
CPPPATH=[
join(FRAMEWORK_DIR, "cores", "arduino", "avr"),
join(FRAMEWORK_DIR, "cores", "arduino", "stm32"),
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb"),
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb", "hid"),
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb", "cdc"),
join(FRAMEWORK_DIR, "libraries", "SrcWrapper", "inc"),
join(FRAMEWORK_DIR, "libraries", "SrcWrapper", "inc", "LL"),
join(FRAMEWORK_DIR, "libraries", "USBDevice", "inc"),
join(FRAMEWORK_DIR, "libraries", "VirtIO", "inc"),
join(FRAMEWORK_DIR, "system", "Drivers", series + "_HAL_Driver", "Inc"),
join(FRAMEWORK_DIR, "system", "Drivers", series + "_HAL_Driver", "Src"),
Expand Down

0 comments on commit 66b29ba

Please sign in to comment.