Skip to content

Commit 5360d17

Browse files
committed
add ch32x035 and ch32l103 support
typo fix Adafruit_TinyUSB_ch32.cpp typo fix in Adafruit_TinyUSB_ch32.cpp add macro for ch32l103 remove ch32x035 remove unused macro clang format define fix usb_div size fix add pragma warning Typo tusb_config_ch32.h
1 parent 05686e7 commit 5360d17

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

src/arduino/ports/ch32/Adafruit_TinyUSB_ch32.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
#include "tusb_option.h"
2626

27-
#if CFG_TUD_ENABLED && \
28-
(defined(ARDUINO_ARCH_CH32) || defined(CH32V20x) || defined(CH32V30x))
27+
#if CFG_TUD_ENABLED && (defined(ARDUINO_ARCH_CH32) || defined(CH32V20x) || \
28+
defined(CH32V30x) || defined(CH32L10x))
2929

3030
#include "Arduino.h"
3131
#include "arduino/Adafruit_USBD_Device.h"
@@ -60,10 +60,13 @@ USBWakeUp_IRQHandler(void) {
6060
// USBFS
6161
#if CFG_TUD_WCH_USBIP_USBFS
6262

63-
#if defined(CH32V10x) || defined(CH32V20x)
63+
#if defined(CH32V10x) || defined(CH32V20x) || defined(CH32L10x)
6464

6565
#if defined(CH32V10x)
6666
#define USBHDWakeUp_IRQHandler USBWakeUp_IRQHandler
67+
#elif defined(CH32L10x)
68+
#define USBHD_IRQHandler USBFS_IRQHandler
69+
#define USBHDWakeUp_IRQHandler USBFSWakeUp_IRQHandler
6770
#endif
6871

6972
__attribute__((interrupt("WCH-Interrupt-fast"))) void USBHD_IRQHandler(void) {
@@ -112,9 +115,12 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
112115
EXTEN->EXTEN_CTR &= ~EXTEN_USB_5V_SEL;
113116

114117
#define RCC_AHBPeriph_OTG_FS RCC_AHBPeriph_USBHD
118+
#elif defined(CH32L10x)
119+
#define RCC_AHBPeriph_OTG_FS RCC_HBPeriph_USBFS
120+
#define RCC_AHBPeriphClockCmd RCC_HBPeriphClockCmd
115121
#endif
116122

117-
uint8_t usb_div;
123+
uint32_t usb_div;
118124
switch (SystemCoreClock) {
119125
#if defined(CH32V20x) || defined(CH32V30x)
120126
case 48000000:
@@ -133,6 +139,16 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
133139
case 72000000:
134140
usb_div = RCC_USBCLKSource_PLLCLK_1Div5;
135141
break;
142+
#elif defined(CH32L10x)
143+
case 48000000:
144+
usb_div = RCC_USBCLKSource_PLLCLK_Div1;
145+
break;
146+
case 72000000:
147+
usb_div = RCC_USBCLKSource_PLLCLK_Div1_5;
148+
break;
149+
case 96000000:
150+
usb_div = RCC_USBCLKSource_PLLCLK_Div2;
151+
break;
136152
#endif
137153
default:
138154
return; // unsupported

src/arduino/ports/ch32/tusb_config_ch32.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ extern "C" {
3434
//--------------------------------------------------------------------
3535
#if defined(CH32V10x)
3636
#define CFG_TUSB_MCU OPT_MCU_CH32V103
37-
#warnning "CH32v103 is not working yet"
37+
#warning "CH32V103 is not working yet"
3838
#elif defined(CH32V20x)
3939
#define CFG_TUSB_MCU OPT_MCU_CH32V20X
4040
#elif defined(CH32V30x)
4141
#define CFG_TUSB_MCU OPT_MCU_CH32V307
42+
#elif defined(CH32L10x)
43+
#define CFG_TUSB_MCU OPT_MCU_CH32L10X
44+
#warning "CH32L103 is not working yet"
4245
#endif
4346

4447
#define CFG_TUSB_OS OPT_OS_NONE

src/common/tusb_mcu.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,16 @@
473473
#define TUP_RHPORT_HIGHSPEED CFG_TUD_WCH_USBIP_USBHS
474474
#define TUP_DCD_ENDPOINT_MAX (CFG_TUD_WCH_USBIP_USBHS ? 16 : 8)
475475

476+
#elif TU_CHECK_MCU(OPT_MCU_CH32L10X)
477+
// l103 support USBFS only
478+
#define TUP_USBIP_WCH_USBFS
479+
480+
#if !defined(CFG_TUD_WCH_USBIP_USBFS)
481+
#define CFG_TUD_WCH_USBIP_USBFS 1
482+
#endif
483+
484+
#define TUP_DCD_ENDPOINT_MAX 8
485+
476486
//--------------------------------------------------------------------+
477487
// Analog Devices
478488
//--------------------------------------------------------------------+

src/portable/wch/ch32_usbfs_reg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
#elif CFG_TUSB_MCU == OPT_MCU_CH32V307
9898
#include <ch32v30x.h>
9999
#define USBHD_IRQn OTG_FS_IRQn
100+
#elif CFG_TUSB_MCU == OPT_MCU_CH32L10X
101+
#include <ch32l103.h>
102+
#define USBOTG_FS USBFSD
103+
#define USBHD_IRQn USBFS_IRQn
100104
#endif
101105

102106
#ifdef __GNUC__

src/tusb_option.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@
181181
// WCH
182182
#define OPT_MCU_CH32V307 2200 ///< WCH CH32V307
183183
#define OPT_MCU_CH32F20X 2210 ///< WCH CH32F20x
184-
#define OPT_MCU_CH32V20X 2220 ///< WCH CH32V20X
184+
#define OPT_MCU_CH32V20X 2220 ///< WCH CH32V20x
185185
#define OPT_MCU_CH32V103 2230 ///< WCH CH32V103
186+
#define OPT_MCU_CH32L10X 2240 ///< WCH CH32L10x
186187

187188
// NXP LPC MCX
188189
#define OPT_MCU_MCXN9 2300 ///< NXP MCX N9 Series

0 commit comments

Comments
 (0)