TinyUSB Documentation

repository·master·Indexed 27 days ago

https://github.com/hathach/tinyusb

A lightweight USB stack providing Host and Device implementations. Includes board support packages (BSP) for ESP32 (with RMT/SPI LED strip drivers), F1Cx00s, Analog Devices MAXIM, and Microchip PIC microcontrollers. Features integration with SEGGER RTT for high-speed data transfer and support for ETM-trace debugging via SEGGER J-Trace.

Tokens
31.2K
Snippets
47
Records
243
Agent score
92%

What's inside TinyUSB

  1. Overview of Microchip PIC Chipidea FS Driver

    master

    This driver provides support for Microchip PIC microcontrollers equipped with the full-speed Chipidea USB peripheral within the TinyUSB stack.

    Supported Families:

    • PIC32MM
    • PIC24FJ
    • PIC32MX (untested)
    • PIC32MK (untested)
    • PIC24EP (untested)
    • dsPIC33EP (untested)

    Note: Currently, only device mode is supported.

  2. Overview of SEGGER RTT implementation

    master

    This repository includes the source files for SEGGER Real Time Transfer (RTT), a technology that allows high-speed data transfer between a target device and a host via a debug probe (like J-Link) without using a UART interface.

    Key components included:

    • Core RTT: SEGGER_RTT.c and SEGGER_RTT.h provide the main module functionality.
    • Optimized Assembly: SEGGER_RTT_ASM_ARMv7M.S provides assembly-optimized implementations for ARMv7M processors.
    • Formatted Output: SEGGER_RTT_Printf.c provides a simple SEGGER_RTT_Printf() function for writing formatted strings.
    • Syscall Retargeting: Files in Syscalls/ allow retargeting standard printf() to RTT for various toolchains.
    • Configuration: Config/SEGGER_RTT_Conf.h is used to configure RTT settings.
  3. Understand TinyUSB Controller Abstraction (DCD and HCD)

    master

    TinyUSB uses abstraction layers to provide portability across different MCU hardware.

    Device Mode (DCD)

    TinyUSB uses a Device Controller Driver (DCD) layer to abstract hardware differences for device-mode applications. The DCD provides a portable interface (src/device/usbd.h) with standardized signatures for endpoint and transfer management.

    Host Mode (HCD)

    For host-mode applications, TinyUSB uses a Host Controller Driver (HCD) layer. This abstracts host controllers through a standardized interface (src/host/usbh.h) for device enumeration, pipe management, and transfer scheduling.

    Key Differences:

    • DCD (Device): Reactive; responds to host requests.
    • HCD (Host): Active; initiates communication and manages connected devices.
  4. Understand TinyUSB's Core Architecture

    master

    TinyUSB uses a layered architecture to separate hardware-specific code from application logic. The layers consist of:

    1. Application Layer: Your main application code using TinyUSB APIs.
    2. Class Drivers: Implement specific USB device classes (e.g., CDC, HID, MSC) and handle class-specific requests.
    3. Device/Host Core: Implements USB protocol state machines, endpoint management, and core USB functionality.
    4. OS Abstraction (OSAL): Provides threading primitives and synchronization for different RTOS environments.
    5. Device/Host Controller Driver (DCD/HCD): Drivers that interface directly with the MCU's USB hardware peripherals.
  5. Understand the purpose of TinyUSB Board Support Code

    master

    TinyUSB's board support code is intended exclusively for self-contained examples and testing. It is not used when TinyUSB is integrated into a larger, custom project.

    The board support code handles:

    • Initializing the MCU.
    • Clocking the USB peripheral with minimal on-board devices.
    • Providing basic hardware abstractions for examples, typically including:
      • One LED (for status).
      • One Button (for user input).
      • One UART (required for logging when using LOGGER=uart, or potentially required for host/dual examples).
  6. Use the Analog Devices MAXIM Board Support Package (BSP)

    master

    This BSP provides support for Analog Devices MAXIM microcontrollers, including the MAX32650, MAX32651, MAX32652, MAX32665, MAX32666, MAX32690, and the MAX78002 AI microcontroller.

    Supported boards include:

    • MAX32650EVKIT
    • MAX32650FTHR
    • MAX32651EVKIT (Secure Bootloader)
    • MAX32666EVKIT
    • MAX32666FTHR
    • MAX32690EVKIT
    • AD-APARD32690-SL
    • MAX78002EVKIT

    This BSP leverages the Maxim Microcontrollers SDK (MSDK) for device interfaces and hardware abstraction layers. The MSDK source code is fetched automatically via the get-deps script.

  7. Understand TinyUSB API Naming Conventions

    master

    TinyUSB uses specific function prefixes to distinguish between different parts of the stack. This prevents naming conflicts when using both host and device stacks simultaneously.

    • tusb_: Core stack functions (e.g., initialization, interrupt handling).
    • tud_: Device stack functions (e.g., tud_task(), tud_cdc_write()).
    • tuh_: Host stack functions (e.g., tuh_task(), tuh_cdc_receive()).
    • tu_: Internal utility functions (not intended for application use).
  8. Handle concurrency and interrupts in TinyUSB

    master
    TinyUSB is designed for single-core MCUs running multi-threaded applications and is compatible with RTOS environments. When developing, account for the fact that an RTOS may swap out your code at any time, and your code can be preempted by interrupts at any time.