Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ Supported CPUs
| | CH32V305, CH32V307 | 🟡 | | ✅ | ch32_usbfs/hs | ISO data loss [2]_ |
| +-----------------------------+--------+------+-----------+------------------------+--------------------+
| | CH583/2, CH32V103 | 🟡 | | ❌ | ch32_usbfs | ISO data loss [2]_ |
| +-----------------------------+--------+------+-----------+------------------------+--------------------+
| | CH32X033, CH32X035 | ✅ | | ❌ | ch32_usbfs | EP4 quirk |
+--------------+-----------------------------+--------+------+-----------+------------------------+--------------------+

Table Legend
Expand Down
29 changes: 15 additions & 14 deletions docs/reference/boards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,18 @@ fomu fomu fomu https://tomu.im/fomu.html
WCH
---

================== ============================= ======== ===================================================================== ======
Board Name Family URL Note
================== ============================= ======== ===================================================================== ======
ch32f205r-r0 CH32F205r-r0 ch32f20x https://github.com/openwch/ch32f20x
ch32v103c_bluepill CH32V103C8T6-Bluepill ch32v10x https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill
ch32v103r_r1_1v0 CH32V103R-R1-1v1 ch32v10x https://github.com/openwch/ch32v103/tree/main/SCHPCB/CH32V103R-R1-1v1
ch32v203c_r0_1v0 CH32V203C-R0-1v0 ch32v20x https://github.com/openwch/ch32v20x/tree/main/SCHPCB/CH32V203C-R0
ch32v203g_r0_1v0 CH32V203G-R0-1v0 ch32v20x https://github.com/openwch/ch32v20x/tree/main/SCHPCB/CH32V203C-R0
nanoch32v203 nanoCH32V203 ch32v20x https://github.com/wuxx/nanoCH32V203
ch32v307v_r1_1v0 CH32V307V-R1-1v0 ch32v30x https://github.com/openwch/ch32v307/tree/main/SCHPCB/CH32V307V-R1-1v0
nanoch32v305 nanoCH32V305 ch32v30x https://github.com/wuxx/nanoCH32V305
ch582m_evt CH582M-EVT evaluation board ch583 https://www.wch-ic.com/products/CH582.html
yd-ch582m yd-ch582m from vcc-gnd studio ch583 http://vcc-gnd.com/
================== ============================= ======== ===================================================================== ======
=========================== ============================= ======== ===================================================================== ======
Board Name Family URL Note
=========================== ============================= ======== ===================================================================== ======
ch32f205r-r0 CH32F205r-r0 ch32f20x https://github.com/openwch/ch32f20x
ch32v103c_bluepill CH32V103C8T6-Bluepill ch32v10x https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill
ch32v103r_r1_1v0 CH32V103R-R1-1v1 ch32v10x https://github.com/openwch/ch32v103/tree/main/SCHPCB/CH32V103R-R1-1v1
ch32v203c_r0_1v0 CH32V203C-R0-1v0 ch32v20x https://github.com/openwch/ch32v20x/tree/main/SCHPCB/CH32V203C-R0
ch32v203g_r0_1v0 CH32V203G-R0-1v0 ch32v20x https://github.com/openwch/ch32v20x/tree/main/SCHPCB/CH32V203C-R0
nanoch32v203 nanoCH32V203 ch32v20x https://github.com/wuxx/nanoCH32V203
ch32v307v_r1_1v0 CH32V307V-R1-1v0 ch32v30x https://github.com/openwch/ch32v307/tree/main/SCHPCB/CH32V307V-R1-1v0
nanoch32v305 nanoCH32V305 ch32v30x https://github.com/wuxx/nanoCH32V305
ch582m_evt CH582M-EVT evaluation board ch583 https://www.wch-ic.com/products/CH582.html
yd-ch582m yd-ch582m from vcc-gnd studio ch583 http://vcc-gnd.com/
weact_ch32x035_core_board WeAct CH32X035 Core Board ch32x035 https://github.com/WeActStudio/WeActStudio.CH32X035CoreBoard
=========================== ============================= ======== ===================================================================== ======
1 change: 1 addition & 0 deletions docs/reference/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ hw/mcu/wch/ch32v103 https://github.com/openwch/ch32v103.gi
hw/mcu/wch/ch32v20x https://github.com/openwch/ch32v20x.git c4c38f507e258a4e69b059ccc2dc27dde33cea1b ch32v20x
hw/mcu/wch/ch32v307 https://github.com/openwch/ch32v307.git 184f21b852cb95eed58e86e901837bc9fff68775 ch32v30x
hw/mcu/wch/ch583 https://github.com/openwch/ch583.git bd508ad7ceed48377619837051412a651952857f ch583
hw/mcu/wch/ch32x035 https://github.com/openwch/ch32x035.git c6253942b29ff2a3f5e2829182a874afffa45881 ch32x035
lib/CMSIS_5 https://github.com/ARM-software/CMSIS_5.git 2b7495b8535bdcb306dac29b9ded4cfb679d7e5c kinetis_k kinetis_kl lpc54 rw61x mm32 msp432e4 nrf samd2x_l2x lpc11 lpc13 lpc15 lpc17 lpc18 lpc40 lpc43 stm32c0 stm32f0 stm32f1 stm32f2 stm32f3 stm32f4 stm32f7 stm32g0 stm32g4 stm32h5 stm32h7 stm32h7rs stm32l0 stm32l1 stm32l4 stm32l5 stm32u0 stm32u5 stm32wb stm32wba sam3x samd11 samd21 samd2x_l2x samd51 samd5x_e5x same5x same7x samg tm4c
lib/CMSIS_6 https://github.com/ARM-software/CMSIS_6.git 6f0a58d01aa9bd2feba212097f9afe7acd991d52 imxrt kinetis_k32l ra stm32n6 lpc51 lpc55 mcx stm32c5
lib/FreeRTOS-Kernel https://github.com/FreeRTOS/FreeRTOS-Kernel.git 9b777ae5c5b8e9e456065a00294d1e5f5f9facf5 all
Expand Down
1 change: 1 addition & 0 deletions examples/device/audio_4_channel_mic_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH583
mcu:CH32X035
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/audio_test_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH583
mcu:CH32X035
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/cdc_msc_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH583
mcu:CH32X035
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/hid_composite_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH583
mcu:CH32X035
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/midi_test_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH583
mcu:CH32X035
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/net_lwip_webserver/skip.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mcu:CH32V103
mcu:CH32V20X
mcu:CH32X035
mcu:LPC11UXX
mcu:LPC13XX
mcu:LPC15XX
Expand Down
8 changes: 8 additions & 0 deletions hw/bsp/ch32x035/boards/weact_ch32x035_core_board/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(LD_FLASH_SIZE 62K)
set(LD_RAM_SIZE 20K)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
SYSCLK_FREQ_48MHz_HSI=48000000
)
endfunction()
23 changes: 23 additions & 0 deletions hw/bsp/ch32x035/boards/weact_ch32x035_core_board/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* metadata:
name: WeAct CH32X035 Core Board
url: https://github.com/WeActStudio/WeActStudio.CH32X035CoreBoard
*/

#ifndef BOARD_H_
#define BOARD_H_

#ifdef __cplusplus
extern "C" {
#endif

#define LED_PORT GPIOB
#define LED_PIN GPIO_Pin_12
#define LED_STATE_ON 1
#define LED_CLOCK_EN() RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE)
#define LED_MODE GPIO_Mode_Out_PP

#ifdef __cplusplus
}
#endif

#endif
5 changes: 5 additions & 0 deletions hw/bsp/ch32x035/boards/weact_ch32x035_core_board/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CFLAGS += -DSYSCLK_FREQ_48MHz_HSI=48000000

LDFLAGS += \
-Wl,--defsym=__FLASH_SIZE=62K \
-Wl,--defsym=__RAM_SIZE=20K \
23 changes: 23 additions & 0 deletions hw/bsp/ch32x035/ch32x035_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32x035_conf.h
* Author : WCH
* Version : V1.0.0
* Date : 2023/04/06
* Description : Library configuration file.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32X035_CONF_H
#define __CH32X035_CONF_H

#include "ch32x035_dbgmcu.h"
#include "ch32x035_flash.h"
#include "ch32x035_gpio.h"
#include "ch32x035_misc.h"
#include "ch32x035_rcc.h"
#include "ch32x035_usb.h"
#include "ch32x035_usart.h"

#endif
29 changes: 29 additions & 0 deletions hw/bsp/ch32x035/ch32x035_it.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32x035_it.h
* Author : WCH
* Version : V1.0.0
* Date : 2023/04/06
* Description : This file contains the headers of the interrupt handlers.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32X035_IT_H
#define __CH32X035_IT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "ch32x035.h"

void USBFS_IRQHandler(void);
void USBFSWakeUp_IRQHandler(void);
void SysTick_Handler(void);

#ifdef __cplusplus
}
#endif

#endif
176 changes: 176 additions & 0 deletions hw/bsp/ch32x035/family.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* metadata:
manufacturer: WCH
*/

#include <stdio.h>

// https://github.com/openwch/ch32v307/pull/90
// https://github.com/openwch/ch32v20x/pull/12
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
#endif

#include "ch32x035.h"
#include "ch32x035_it.h"

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "bsp/board_api.h"
#include "board.h"

__attribute__((interrupt)) __attribute__((used)) void USBFS_IRQHandler(void) {
#if CFG_TUD_ENABLED && CFG_TUD_WCH_USBIP_USBFS
tud_int_handler(0);
#endif
}

__attribute__((interrupt)) __attribute__((used)) void USBFSWakeUp_IRQHandler(void) {
#if CFG_TUD_ENABLED && CFG_TUD_WCH_USBIP_USBFS
tud_int_handler(0);
#endif
}

//--------------------------------------------------------------------+
// Board API
//--------------------------------------------------------------------+
#if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0;

__attribute__((interrupt)) void SysTick_Handler(void) {
SysTick->SR = 0;
system_ticks++;
}

static uint32_t SysTick_Config(uint32_t ticks) {
NVIC_EnableIRQ(SysTicK_IRQn);
SysTick->CTLR = 0;
SysTick->SR = 0;
SysTick->CNT = 0;
SysTick->CMP = ticks - 1;
SysTick->CTLR = 0xF;
return 0;
}

uint32_t tusb_time_millis_api(void) {
return system_ticks;
}
#endif

void board_init(void) {
__disable_irq();

SystemCoreClockUpdate();

#if CFG_TUSB_OS == OPT_OS_NONE
SysTick_Config(SystemCoreClock / 1000);
#endif

LED_CLOCK_EN();

GPIO_InitTypeDef GPIO_InitStructure = {
.GPIO_Pin = LED_PIN,
.GPIO_Mode = LED_MODE,
.GPIO_Speed = GPIO_Speed_50MHz,
};
GPIO_Init(LED_PORT, &GPIO_InitStructure);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_USBFS, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_16;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_17;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);

AFIO->CTLR = (AFIO->CTLR & ~(AFIO_CTLR_UDP_PUE | AFIO_CTLR_UDM_PUE)) | AFIO_CTLR_USB_PHY_V33 | AFIO_CTLR_UDP_PUE |
AFIO_CTLR_USB_IOEN;

#ifdef UART_DEV
UART_CLOCK_EN();
GPIO_InitTypeDef usart_init = {
.GPIO_Pin = UART_TX_PIN | UART_RX_PIN,
.GPIO_Speed = GPIO_Speed_50MHz,
.GPIO_Mode = GPIO_Mode_AF_PP,
};
GPIO_Init(GPIOA, &usart_init);

USART_InitTypeDef usart = {
.USART_BaudRate = 115200,
.USART_WordLength = USART_WordLength_8b,
.USART_StopBits = USART_StopBits_1,
.USART_Parity = USART_Parity_No,
.USART_Mode = USART_Mode_Tx | USART_Mode_Rx,
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
};
USART_Init(UART_DEV, &usart);
USART_Cmd(UART_DEV, ENABLE);
#endif

__enable_irq();
}

void board_reset_to_bootloader(void) {
}

void board_led_write(bool state) {
GPIO_WriteBit(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
}

uint32_t board_button_read(void) {
return false;
}

size_t board_get_unique_id(uint8_t id[], size_t max_len) {
(void)max_len;
volatile uint32_t *ch32_uuid = ((volatile uint32_t *)0x1FFFF7E8UL);
uint32_t *serial_32 = (uint32_t *)(uintptr_t)id;
serial_32[0] = ch32_uuid[0];
serial_32[1] = ch32_uuid[1];
serial_32[2] = ch32_uuid[2];

return 12;
}

int board_uart_read(uint8_t *buf, int len) {
#ifdef UART_DEV
int count;
for (count = 0; count < len; count++) {
if (USART_GetFlagStatus(UART_DEV, USART_FLAG_RXNE) == RESET) {
break;
}
buf[count] = USART_ReceiveData(UART_DEV);
}
return count;
#else
(void)buf;
(void)len;
return 0;
#endif
}

int board_uart_write(const void *buf, int len) {
#ifdef UART_DEV
const uint8_t *p = (const uint8_t *)buf;
int count = 0;
while (count < len) {
if (USART_GetFlagStatus(UART_DEV, USART_FLAG_TXE) != RESET) {
USART_SendData(UART_DEV, p[count]);
count++;
} else {
break;
}
}
return count;
#else
(void)buf;
(void)len;
return 0;
#endif
}
Loading
Loading