Skip to content

Commit

Permalink
ch32x035
Browse files Browse the repository at this point in the history
  • Loading branch information
21km43 committed Sep 25, 2024
1 parent 143eb3b commit ddf059a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/arduino/ports/ch32/Adafruit_TinyUSB_ch32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/arduino/ports/ch32/tusb_config_ch32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/common/tusb_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/portable/wch/ch32_usbfs_reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
#elif CFG_TUSB_MCU == OPT_MCU_CH32V307
#include <ch32v30x.h>
#define USBHD_IRQn OTG_FS_IRQn
#elif CFG_TUSB_MCU == OPT_MCU_CH32X035
#include <ch32x035.h>
#define USBOTG_FS USBFSD
#define USBHD_IRQn USBFS_IRQn
#endif
#elif CFG_TUSB_MCU == OPT_MCU_CH32L10X
#include <ch32l103.h>
#define USBOTG_FS USBFSD
Expand Down
3 changes: 2 additions & 1 deletion src/tusb_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ddf059a

Please sign in to comment.