diff --git a/src/arduino/ports/ch32/Adafruit_TinyUSB_ch32.cpp b/src/arduino/ports/ch32/Adafruit_TinyUSB_ch32.cpp index 80a87b90..bd31f942 100644 --- a/src/arduino/ports/ch32/Adafruit_TinyUSB_ch32.cpp +++ b/src/arduino/ports/ch32/Adafruit_TinyUSB_ch32.cpp @@ -25,7 +25,8 @@ #include "tusb_option.h" #if CFG_TUD_ENABLED && (defined(ARDUINO_ARCH_CH32) || defined(CH32V20x) || \ - defined(CH32V30x) || defined(CH32L10x)) + defined(CH32V30x) || defined(CH32X035) || \ + defined(CH32L10x)) #include "Arduino.h" #include "arduino/Adafruit_USBD_Device.h" @@ -64,7 +65,7 @@ USBWakeUp_IRQHandler(void) { #if defined(CH32V10x) #define USBHDWakeUp_IRQHandler USBWakeUp_IRQHandler -#elif defined(CH32L10x) +#elif defined(CH32X035) || defined(CH32L10x) #define USBHD_IRQHandler USBFS_IRQHandler #define USBHDWakeUp_IRQHandler USBFSWakeUp_IRQHandler #endif @@ -115,6 +116,8 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) { EXTEN->EXTEN_CTR &= ~EXTEN_USB_5V_SEL; #define RCC_AHBPeriph_OTG_FS RCC_AHBPeriph_USBHD +#elif defined(CH32X035) +#define RCC_AHBPeriph_OTG_FS RCC_AHBPeriph_USBFS #elif defined(CH32L10x) #define RCC_AHBPeriph_OTG_FS RCC_HBPeriph_USBFS #define RCC_AHBPeriphClockCmd RCC_HBPeriphClockCmd @@ -139,6 +142,9 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) { case 72000000: usb_div = RCC_USBCLKSource_PLLCLK_1Div5; break; +#elif defined(CH32X035) + case 48000000: + break; #elif defined(CH32L10x) case 48000000: usb_div = RCC_USBCLKSource_PLLCLK_Div1; @@ -156,7 +162,7 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) { #if defined(CH32V30x) RCC_OTGFSCLKConfig(usb_div); -#else +#else !defined(CH32X035) RCC_USBCLKConfig(usb_div); #endif diff --git a/src/arduino/ports/ch32/tusb_config_ch32.h b/src/arduino/ports/ch32/tusb_config_ch32.h index 9b41ebd8..d56d0367 100644 --- a/src/arduino/ports/ch32/tusb_config_ch32.h +++ b/src/arduino/ports/ch32/tusb_config_ch32.h @@ -39,6 +39,8 @@ extern "C" { #define CFG_TUSB_MCU OPT_MCU_CH32V20X #elif defined(CH32V30x) #define CFG_TUSB_MCU OPT_MCU_CH32V307 +#elif defined(CH32X035) +#define CFG_TUSB_MCU OPT_MCU_CH32X035 #elif defined(CH32L10x) #define CFG_TUSB_MCU OPT_MCU_CH32L10X #warning "CH32L103 is not working yet" diff --git a/src/common/tusb_mcu.h b/src/common/tusb_mcu.h index afabae61..f8957f20 100644 --- a/src/common/tusb_mcu.h +++ b/src/common/tusb_mcu.h @@ -473,8 +473,8 @@ #define TUP_RHPORT_HIGHSPEED CFG_TUD_WCH_USBIP_USBHS #define TUP_DCD_ENDPOINT_MAX (CFG_TUD_WCH_USBIP_USBHS ? 16 : 8) -#elif TU_CHECK_MCU(OPT_MCU_CH32L10X) - // l103 support USBFS only +#elif TU_CHECK_MCU(OPT_MCU_CH32X035) || TU_CHECK_MCU(OPT_MCU_CH32L10X) + // x035 and l103 support USBFS only #define TUP_USBIP_WCH_USBFS #if !defined(CFG_TUD_WCH_USBIP_USBFS) diff --git a/src/portable/wch/ch32_usbfs_reg.h b/src/portable/wch/ch32_usbfs_reg.h index cf7357e7..7f9aac9f 100644 --- a/src/portable/wch/ch32_usbfs_reg.h +++ b/src/portable/wch/ch32_usbfs_reg.h @@ -97,6 +97,11 @@ #elif CFG_TUSB_MCU == OPT_MCU_CH32V307 #include #define USBHD_IRQn OTG_FS_IRQn +#elif CFG_TUSB_MCU == OPT_MCU_CH32X035 + #include + #define USBOTG_FS USBFSD + #define USBHD_IRQn USBFS_IRQn +#endif #elif CFG_TUSB_MCU == OPT_MCU_CH32L10X #include #define USBOTG_FS USBFSD diff --git a/src/tusb_option.h b/src/tusb_option.h index da842a00..4f0b0f5d 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -183,7 +183,8 @@ #define OPT_MCU_CH32F20X 2210 ///< WCH CH32F20x #define OPT_MCU_CH32V20X 2220 ///< WCH CH32V20x #define OPT_MCU_CH32V103 2230 ///< WCH CH32V103 -#define OPT_MCU_CH32L10X 2240 ///< WCH CH32L10x +#define OPT_MCU_CH32X035 2240 ///< WCH CH32X035 +#define OPT_MCU_CH32L10X 2250 ///< WCH CH32L10x // NXP LPC MCX #define OPT_MCU_MCXN9 2300 ///< NXP MCX N9 Series