Please help with tinyusb cmake minimum sample #3356
-
|
HI, Im trying now for days to make a very simple tinyusb USB CDC sample with a STM32Nucelo C071 board. I have searched the whole internet but found no explanation to my problem. Im failing to integrate the tinyusb lib into my project. Can someone explain a minimal cmake example how to implement the tinyusb lib? For the editor Im using CLion. BR |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
|
It's pretty straightforward, you can simply add the source files of the class you needed (eg. CDC & HID) and includes to your project: # C/C++ source files
set(SRC_C_CXX
../../../tinyusb/src/class/cdc/cdc_device.c
../../../tinyusb/src/class/hid/hid_device.c
../../../tinyusb/src/tusb.c
../../../tinyusb/src/common/tusb_fifo.c
../../../tinyusb/src/device/usbd.c
../../../tinyusb/src/device/usbd_control.c
main.c
usb_descriptors.c
system_stm32g0xx.c
)
# Includes
set(INCLUDES
CMSIS/Include
CMSIS/Device/Include
../../../tinyusb/src
.
)Or use include(../../../tinyusb/src/CMakeLists.txt)
tinyusb_sources_get(TUSB_SRC)
# C/C++ source files
set(SRC_C_CXX
${TUSB_SRC}
main.c
usb_descriptors.c
system_stm32g0xx.c
)
# Includes
set(INCLUDES
CMSIS/Include
CMSIS/Device/Include
../../../tinyusb/src
.
) |
Beta Was this translation helpful? Give feedback.
-
|
Sorry I still cant make it work. My cmake looks different. Below is my clean cmake so far. I have added the modified (set MCU type) tusb_config.h to Core/Inc and usb_descriptors.c (from the CDC sample) to Core/Scr. I modified the main.c. How I need to modify my cmake then? cmake_minimum_required(VERSION 3.22)
#
# This file is generated only once,
# and is not re-generated if converter is called multiple times.
#
# User is free to modify the file as much as necessary
#
# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
# Define the build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Set the project name
set(CMAKE_PROJECT_NAME USBTest)
# Enable compile command to ease indexing with e.g. clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# Core project settings
project(${CMAKE_PROJECT_NAME})
message("Build type: " ${CMAKE_BUILD_TYPE})
# Enable CMake support for ASM and C languages
enable_language(C ASM)
# Create an executable object type
add_executable(${CMAKE_PROJECT_NAME})
# Add STM32CubeMX generated sources
add_subdirectory(cmake/stm32cubemx)
# Link directories setup
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined library search paths
)
# Add sources to executable
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
# Add user sources here
)
# Add include paths
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined include paths
)
# Add project symbols (macros)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined symbols
)
# Remove wrong libob.a library dependency when using cpp files
list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_LIBRARIES ob)
# Add linked libraries
target_link_libraries(${CMAKE_PROJECT_NAME}
stm32cubemx
# Add user defined libraries
)
|
Beta Was this translation helpful? Give feedback.
-
|
Meanwhile I made it work with the following cmake :-) I didn't add the dcd driver before. cmake_minimum_required(VERSION 3.22)
#
# This file is generated only once,
# and is not re-generated if converter is called multiple times.
#
# User is free to modify the file as much as necessary
#
# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
# Define the build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Set the project name
set(CMAKE_PROJECT_NAME USBTest)
# Enable compile command to ease indexing with e.g. clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# Core project settings
project(${CMAKE_PROJECT_NAME})
message("Build type: " ${CMAKE_BUILD_TYPE})
# Enable CMake support for ASM and C languages
enable_language(C ASM)
# Create an executable object type
add_executable(${CMAKE_PROJECT_NAME})
# Add STM32CubeMX generated sources
add_subdirectory(cmake/stm32cubemx)
# Tinyusb
include(tinyusb/src/CMakeLists.txt)
tinyusb_sources_get(TUSB_SRC)
# Link directories setup
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined library search paths
)
# Add sources to executable
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
# Add user sources here
${TUSB_SRC}
Core/Src/usb_descriptors.c
tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
)
# Add include paths
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined include paths
tinyusb/src
tinyusb/hw
)
# Add project symbols (macros)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined symbols
)
# Remove wrong libob.a library dependency when using cpp files
list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_LIBRARIES ob)
# Add linked libraries
target_link_libraries(${CMAKE_PROJECT_NAME}
stm32cubemx
# Add user defined libraries
)
To make it compile and show the cdc port I needed to uncomment the "chr_count = board_usb_get_serial(_desc_str + 1, 32);" from the samples usb_descriptor.c. Without uncomment I got a error from the board_api.h which didn't find "board_get_unique_id". Is this a bug or is my configuration still wrong? |
Beta Was this translation helpful? Give feedback.
It's pretty straightforward, you can simply add the source files of the class you needed (eg. CDC & HID) and includes to your project:
Or use
tinyusb_sources_getfunction too add all source files:include(../../../tinyusb/src/CMakeLists.txt) t…