Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

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
Matthias

You must be logged in to vote

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 tinyusb_sources_get function too add all source files:

include(../../../tinyusb/src/CMakeLists.txt)

t…

Replies: 3 comments · 3 replies

Comment options

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 tinyusb_sources_get function too add all source files:

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
    .
)
You must be logged in to vote
0 replies
Answer selected by Matthias32
Comment options

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
)
You must be logged in to vote
0 replies
Comment options

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?

You must be logged in to vote
3 replies
@HiFiPhile
Comment options

board_usb_get_serial is not a a part of core source code (/src) but board specific (/hw), you can leave it behind.

static inline size_t board_usb_get_serial(uint16_t desc_str1[], size_t max_chars) {

@Matthias32
Comment options

OK so I need to implement this function by my own if needed?

@HiFiPhile
Comment options

OK so I need to implement this function by my own if needed?

Yep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.