Files
tinyUSB/src/common/tusb_mcu.h

428 lines
14 KiB
C
Raw Normal View History

/*
* The MIT License (MIT)
*
* Copyright (c) 2021, Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
2022-02-26 15:18:51 +07:00
#ifndef TUSB_MCU_H_
#define TUSB_MCU_H_
//--------------------------------------------------------------------+
// Port/Platform Specific
// TUP stand for TinyUSB Port/Platform (can be renamed)
2022-02-26 15:18:51 +07:00
//--------------------------------------------------------------------+
//------------- Unaligned Memory Access -------------//
2023-07-07 12:27:18 +07:00
#ifdef __ARM_ARCH
// ARM Architecture set __ARM_FEATURE_UNALIGNED to 1 for mcu supports unaligned access
#if defined(__ARM_FEATURE_UNALIGNED) && __ARM_FEATURE_UNALIGNED == 1
#define TUP_ARCH_STRICT_ALIGN 0
#else
#define TUP_ARCH_STRICT_ALIGN 1
#endif
2022-02-26 15:18:51 +07:00
#else
2023-07-07 12:27:18 +07:00
// TODO default to strict align for others
// Should investigate other architecture such as risv, xtensa, mips for optimal setting
2022-02-26 15:18:51 +07:00
#define TUP_ARCH_STRICT_ALIGN 1
#endif
2022-02-25 23:04:39 +07:00
/* USB Controller Attributes for Device, Host or MCU (both)
2022-02-25 22:45:05 +07:00
* - ENDPOINT_MAX: max (logical) number of endpoint
* - ENDPOINT_EXCLUSIVE_NUMBER: endpoint number with different direction IN and OUT aren't allowed,
* e.g EP1 OUT & EP1 IN cannot exist together
* - RHPORT_HIGHSPEED: support highspeed with on-chip PHY
2022-02-25 22:45:05 +07:00
*/
//--------------------------------------------------------------------+
// NXP
//--------------------------------------------------------------------+
#if TU_CHECK_MCU(OPT_MCU_LPC11UXX, OPT_MCU_LPC13XX, OPT_MCU_LPC15XX)
#define TUP_USBIP_IP3511
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 5
#elif TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC40XX)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 16
2022-02-26 17:03:54 +07:00
#define TUP_USBIP_OHCI
2023-02-22 22:17:45 +07:00
#define TUP_OHCI_RHPORTS 2
#elif TU_CHECK_MCU(OPT_MCU_LPC51UXX)
#define TUP_USBIP_IP3511
2022-02-26 17:03:54 +07:00
#define TUP_DCD_ENDPOINT_MAX 5
#elif TU_CHECK_MCU(OPT_MCU_LPC54)
2021-07-21 17:00:02 +07:00
// TODO USB0 has 5, USB1 has 6
#define TUP_USBIP_IP3511
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 6
2021-07-21 17:00:02 +07:00
#elif TU_CHECK_MCU(OPT_MCU_LPC55)
// TODO USB0 has 5, USB1 has 6
#define TUP_USBIP_IP3511
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 6
#elif TU_CHECK_MCU(OPT_MCU_LPC18XX, OPT_MCU_LPC43XX)
// USB0 has 6 with HS PHY, USB1 has 4 only FS
#define TUP_USBIP_CHIPIDEA_HS
#define TUP_USBIP_EHCI
#define TUP_DCD_ENDPOINT_MAX 6
#define TUP_RHPORT_HIGHSPEED 1
#elif TU_CHECK_MCU(OPT_MCU_MCXN9)
// USB0 is chipidea FS
#define TUP_USBIP_CHIPIDEA_FS
#define TUP_USBIP_CHIPIDEA_FS_MCX
// USB1 is chipidea HS
#define TUP_USBIP_CHIPIDEA_HS
#define TUP_USBIP_EHCI
#define TUP_DCD_ENDPOINT_MAX 8
#define TUP_RHPORT_HIGHSPEED 1
#elif TU_CHECK_MCU(OPT_MCU_MIMXRT1XXX)
2022-02-26 15:18:51 +07:00
#define TUP_USBIP_CHIPIDEA_HS
2022-02-26 17:03:54 +07:00
#define TUP_USBIP_EHCI
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
#define TUP_RHPORT_HIGHSPEED 1
2022-02-25 22:45:05 +07:00
#elif TU_CHECK_MCU(OPT_MCU_KINETIS_KL, OPT_MCU_KINETIS_K32L)
#define TUP_USBIP_CHIPIDEA_FS
#define TUP_USBIP_CHIPIDEA_FS_KINETIS
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 16
#elif TU_CHECK_MCU(OPT_MCU_MM32F327X)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 16
2021-09-18 16:53:16 +07:00
//--------------------------------------------------------------------+
// Nordic
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_NRF5X)
// 8 CBI + 1 ISO
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 9
//--------------------------------------------------------------------+
// Microchip
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_SAMD21, OPT_MCU_SAMD51, OPT_MCU_SAME5X) || \
TU_CHECK_MCU(OPT_MCU_SAMD11, OPT_MCU_SAML21, OPT_MCU_SAML22)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
#elif TU_CHECK_MCU(OPT_MCU_SAMG)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 6
2022-02-26 17:03:54 +07:00
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
#elif TU_CHECK_MCU(OPT_MCU_SAMX7X)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 10
#define TUP_RHPORT_HIGHSPEED 1
2022-02-26 17:03:54 +07:00
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
2021-07-22 00:28:37 +07:00
#elif TU_CHECK_MCU(OPT_MCU_PIC32MZ)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
2022-02-26 17:03:54 +07:00
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
#elif TU_CHECK_MCU(OPT_MCU_PIC32MX, OPT_MCU_PIC32MM, OPT_MCU_PIC32MK) || \
TU_CHECK_MCU(OPT_MCU_PIC24, OPT_MCU_DSPIC33)
#define TUP_DCD_ENDPOINT_MAX 16
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
//--------------------------------------------------------------------+
// ST
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_STM32F0)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
#elif TU_CHECK_MCU(OPT_MCU_STM32F1)
// - F102, F103 use fsdev
// - F105, F107 use dwc2
2021-10-24 23:24:46 +07:00
#if defined (STM32F105x8) || defined (STM32F105xB) || defined (STM32F105xC) || \
defined (STM32F107xB) || defined (STM32F107xC)
2022-02-26 15:18:51 +07:00
#define TUP_USBIP_DWC2
2022-02-26 17:03:54 +07:00
#define TUP_USBIP_DWC2_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 4
#elif defined(STM32F102x6) || defined(STM32F102xB) || \
defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
#else
#error "Unsupported STM32F1 mcu"
2021-10-24 23:24:46 +07:00
#endif
#elif TU_CHECK_MCU(OPT_MCU_STM32F2)
2022-02-26 15:18:51 +07:00
#define TUP_USBIP_DWC2
2022-02-26 17:03:54 +07:00
#define TUP_USBIP_DWC2_STM32
// FS has 4 ep, HS has 5 ep
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 6
2021-10-24 23:24:46 +07:00
#elif TU_CHECK_MCU(OPT_MCU_STM32F3)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
2021-10-24 23:24:46 +07:00
#elif TU_CHECK_MCU(OPT_MCU_STM32F4)
2022-02-26 17:03:54 +07:00
#define TUP_USBIP_DWC2
#define TUP_USBIP_DWC2_STM32
2021-10-24 23:24:46 +07:00
// For most mcu, FS has 4, HS has 6. TODO 446/469/479 HS has 9
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 6
2022-02-26 15:18:51 +07:00
2022-02-26 17:03:54 +07:00
#elif TU_CHECK_MCU(OPT_MCU_STM32F7)
2022-02-26 15:18:51 +07:00
#define TUP_USBIP_DWC2
2022-02-26 17:03:54 +07:00
#define TUP_USBIP_DWC2_STM32
// FS has 6, HS has 9
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 9
2022-02-26 17:34:29 +07:00
// MCU with on-chip HS Phy
#if defined(STM32F723xx) || defined(STM32F730xx) || defined(STM32F733xx)
#define TUP_RHPORT_HIGHSPEED 1 // Port0: FS, Port1: HS
2022-02-26 17:34:29 +07:00
#endif
#elif TU_CHECK_MCU(OPT_MCU_STM32H7)
2022-02-26 15:18:51 +07:00
#define TUP_USBIP_DWC2
2022-02-26 17:03:54 +07:00
#define TUP_USBIP_DWC2_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 9
2021-10-24 23:24:46 +07:00
#elif TU_CHECK_MCU(OPT_MCU_STM32G4)
2023-06-07 18:57:48 +07:00
// Device controller
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
2023-06-07 18:57:48 +07:00
// TypeC controller
#define TUP_USBIP_TYPEC_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
2023-06-07 18:57:48 +07:00
#define TUP_TYPEC_RHPORTS_NUM 1
2023-03-08 12:05:58 +01:00
#elif TU_CHECK_MCU(OPT_MCU_STM32G0)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
#define TUP_DCD_ENDPOINT_MAX 8
#elif TU_CHECK_MCU(OPT_MCU_STM32L0, OPT_MCU_STM32L1)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
2021-10-24 23:24:46 +07:00
#elif TU_CHECK_MCU(OPT_MCU_STM32L4)
// - L4x2, L4x3 use fsdev
// - L4x4, L4x6, L4x7, L4x9 use dwc2
2021-10-24 23:24:46 +07:00
#if defined (STM32L475xx) || defined (STM32L476xx) || \
defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || \
defined (STM32L4A6xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
2021-10-24 23:24:46 +07:00
defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || \
defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
2022-02-26 15:18:51 +07:00
#define TUP_USBIP_DWC2
2022-02-26 17:03:54 +07:00
#define TUP_USBIP_DWC2_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 6
#elif defined(STM32L412xx) || defined(STM32L422xx) || defined(STM32L432xx) || defined(STM32L433xx) || \
defined(STM32L442xx) || defined(STM32L443xx) || defined(STM32L452xx) || defined(STM32L462xx)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
#else
#error "Unsupported STM32L4 mcu"
2021-10-24 23:24:46 +07:00
#endif
2022-03-05 17:09:04 +01:00
#elif TU_CHECK_MCU(OPT_MCU_STM32WB)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
#define TUP_DCD_ENDPOINT_MAX 8
2022-03-05 17:09:04 +01:00
2022-10-13 17:37:28 +08:00
#elif TU_CHECK_MCU(OPT_MCU_STM32U5)
#define TUP_USBIP_DWC2
#define TUP_USBIP_DWC2_STM32
#define TUP_DCD_ENDPOINT_MAX 6
2022-03-05 17:09:04 +01:00
#elif TU_CHECK_MCU(OPT_MCU_STM32L5)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_STM32
#define TUP_DCD_ENDPOINT_MAX 8
//--------------------------------------------------------------------+
// Sony
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_CXD56)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 7
#define TUP_RHPORT_HIGHSPEED 1
2022-02-26 17:03:54 +07:00
#define TUP_DCD_ENDPOINT_EXCLUSIVE_NUMBER
//--------------------------------------------------------------------+
// TI
//--------------------------------------------------------------------+
2021-11-08 16:41:08 +07:00
#elif TU_CHECK_MCU(OPT_MCU_MSP430x5xx)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
2021-11-08 16:41:08 +07:00
#elif TU_CHECK_MCU(OPT_MCU_MSP432E4, OPT_MCU_TM4C123, OPT_MCU_TM4C129)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
//--------------------------------------------------------------------+
// ValentyUSB (Litex)
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_VALENTYUSB_EPTRI)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 16
//--------------------------------------------------------------------+
// Nuvoton
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_NUC121, OPT_MCU_NUC126)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
#elif TU_CHECK_MCU(OPT_MCU_NUC120)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 6
#elif TU_CHECK_MCU(OPT_MCU_NUC505)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 12
#define TUP_RHPORT_HIGHSPEED 1
//--------------------------------------------------------------------+
// Espressif
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
2022-02-26 17:13:06 +07:00
#define TUP_USBIP_DWC2
#define TUP_DCD_ENDPOINT_MAX 6
//--------------------------------------------------------------------+
// Dialog
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_DA1469X)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 4
//--------------------------------------------------------------------+
// Raspberry Pi
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_RP2040)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 16
#define TU_ATTR_FAST_FUNC __attribute__((section(".time_critical.tinyusb")))
//--------------------------------------------------------------------+
// Silabs
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_EFM32GG)
2022-02-26 17:13:06 +07:00
#define TUP_USBIP_DWC2
#define TUP_DCD_ENDPOINT_MAX 7
//--------------------------------------------------------------------+
// Renesas
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_RX63X, OPT_MCU_RX65X, OPT_MCU_RX72N, OPT_MCU_RAXXX)
2023-07-05 17:13:01 +07:00
#define TUP_USBIP_RUSB2
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 10
//--------------------------------------------------------------------+
// GigaDevice
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_GD32VF103)
2022-02-26 17:13:06 +07:00
#define TUP_USBIP_DWC2
#define TUP_DCD_ENDPOINT_MAX 4
//--------------------------------------------------------------------+
// Broadcom
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_BCM2711, OPT_MCU_BCM2835, OPT_MCU_BCM2837)
2022-02-26 17:13:06 +07:00
#define TUP_USBIP_DWC2
#define TUP_DCD_ENDPOINT_MAX 8
#define TUP_RHPORT_HIGHSPEED 1
2021-09-17 16:51:34 -07:00
//--------------------------------------------------------------------+
// Infineon
//--------------------------------------------------------------------+
2021-11-05 11:40:53 +07:00
#elif TU_CHECK_MCU(OPT_MCU_XMC4000)
2022-02-26 17:13:06 +07:00
#define TUP_USBIP_DWC2
#define TUP_DCD_ENDPOINT_MAX 8
2021-11-05 11:40:53 +07:00
//--------------------------------------------------------------------+
// BridgeTek
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_FT90X)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
#define TUP_RHPORT_HIGHSPEED 1
#elif TU_CHECK_MCU(OPT_MCU_FT93X)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 16
#define TUP_RHPORT_HIGHSPEED 1
//--------------------------------------------------------------------+
// Allwinner
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_F1C100S)
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 4
//------------- WCH -------------//
2022-03-22 23:31:20 +10:30
#elif TU_CHECK_MCU(OPT_MCU_CH32V307)
2022-03-23 00:00:06 +10:30
#define TUP_DCD_ENDPOINT_MAX 16
#define TUP_RHPORT_HIGHSPEED 1
#elif TU_CHECK_MCU(OPT_MCU_CH32F20X)
#define TUP_DCD_ENDPOINT_MAX 16
2023-01-12 15:38:18 +07:00
#define TUP_RHPORT_HIGHSPEED 1
2022-02-25 22:45:05 +07:00
#endif
2023-08-27 23:45:34 +07:00
//--------------------------------------------------------------------+
// External USB controller
//--------------------------------------------------------------------+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
2023-08-27 23:45:34 +07:00
#ifndef CFG_TUH_MAX3421_ENDPOINT_TOTAL
#define CFG_TUH_MAX3421_ENDPOINT_TOTAL (8 + 4*(CFG_TUH_DEVICE_MAX-1))
#endif
#endif
2022-02-25 22:45:05 +07:00
//--------------------------------------------------------------------+
// Default Values
//--------------------------------------------------------------------+
#ifndef TUP_MCU_MULTIPLE_CORE
#define TUP_MCU_MULTIPLE_CORE 0
#endif
2022-02-26 17:03:54 +07:00
#ifndef TUP_DCD_ENDPOINT_MAX
#warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
2022-02-26 17:13:06 +07:00
#define TUP_DCD_ENDPOINT_MAX 8
#endif
2021-07-21 17:00:02 +07:00
// Default to fullspeed if not defined
2022-02-26 17:03:54 +07:00
#ifndef TUP_RHPORT_HIGHSPEED
#define TUP_RHPORT_HIGHSPEED 0
#endif
2021-07-21 17:00:02 +07:00
// fast function, normally mean placing function in SRAM
#ifndef TU_ATTR_FAST_FUNC
#define TU_ATTR_FAST_FUNC
#endif
#endif