Skip to content

Add support for WCH CH32L103 #89451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions boards/wch/ch32l103evt/Kconfig.ch32l103evt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2025 Paul Wedeck
# SPDX-License-Identifier: Apache-2.0

config BOARD_CH32L103EVT
select SOC_CH32L103
5 changes: 5 additions & 0 deletions boards/wch/ch32l103evt/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2024 Michael Hope
# SPDX-License-Identifier: Apache-2.0

board_runner_args(minichlink)
include(${ZEPHYR_BASE}/boards/common/minichlink.board.cmake)
6 changes: 6 additions & 0 deletions boards/wch/ch32l103evt/board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
board:
name: ch32l103evt
full_name: WCH CH32L103C8T6-R0-1v2
vendor: wch
socs:
- name: ch32l103
21 changes: 21 additions & 0 deletions boards/wch/ch32l103evt/ch32l103evt-pinctrl.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Michael Hope <michaelh@juju.nz>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I"m fine if you want to rewrite the copyright here.

* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/pinctrl/ch32v20x_30x-pinctrl.h>

&pinctrl {
usart1_default: usart1_default {
group1 {
pinmux = <USART1_TX_PA9_0>;
output-high;
drive-push-pull;
slew-rate = "max-speed-10mhz";
};
group2 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline gap between child nodes

pinmux = <USART1_RX_PA10_0>;
bias-pull-up;
};
};
};
81 changes: 81 additions & 0 deletions boards/wch/ch32l103evt/ch32l103evt.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2024 Michael Hope <michaelh@juju.nz>
* Copyright (c) 2025 Paul Wedeck
* SPDX-License-Identifier: Apache-2.0
*/

/dts-v1/;

#include <wch/ch32l103/ch32l103c8t.dtsi>
#include "ch32l103evt-pinctrl.dtsi"

#include <zephyr/dt-bindings/gpio/gpio.h>

/ {
model = "ch32l103evt";
compatible = "wch,ch32l103";

chosen {
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
};

leds {
compatible = "gpio-leds";

/*
* Please connect the unconnected LED on the WCH CH32L103EVT
* board to a suitable GPIO pin (like PA1) and then change
* this status to "okay".
*/
status = "disabled";

red_led: led0 {
gpios = <&gpioa 1 GPIO_ACTIVE_HIGH>;
};
};

aliases {
led0 = &red_led;
};
};

&clk_hse {
clock-frequency = <DT_FREQ_M(8)>;
status = "okay";
};

&pll {
clocks = <&clk_hse>;
mul = <12>;
status = "okay";
};

&rcc {
clocks = <&pll>;
};

&gpioa {
status = "okay";
};

&gpiob {
status = "okay";
};

&gpioc {
status = "okay";
};

&gpiod {
status = "okay";
};

&usart1 {
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&usart1_default>;
pinctrl-names = "default";
};
12 changes: 12 additions & 0 deletions boards/wch/ch32l103evt/ch32l103evt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
identifier: ch32l103evt
name: WCH CH32L103C8T6-R0-1v2
type: mcu
arch: riscv
toolchain:
- cross-compile
- zephyr
ram: 64
flash: 20
supported:
- gpio
- dma
8 changes: 8 additions & 0 deletions boards/wch/ch32l103evt/ch32l103evt_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2024 Michael Hope
# SPDX-License-Identifier: Apache-2.0

CONFIG_GPIO=y

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
Binary file added boards/wch/ch32l103evt/doc/img/ch32l103evt.webp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put through https://tinypng.com/

Binary file not shown.
88 changes: 88 additions & 0 deletions boards/wch/ch32l103evt/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.. zephyr:board:: ch32l103evt

Overview
********

The `WCH`_ CH32L103EVT hardware provides support for QingKe 32-bit RISC-V4C
processor and the following devices:

* CLOCK
* :abbr:`GPIO (General Purpose Input Output)`
* :abbr:`NVIC (Nested Vectored Interrupt Controller)`
* :abbr:`DMA (Direct Memory Access)`

The board is equipped with two LEDs.
The `WCH webpage on CH32L103`_ contains the processor's manuals.
The `WCH webpage on CH32L103EVT`_ contains the CH32L103EVT's schematic.

Hardware
********

The QingKe 32-bit RISC-V4C processor of the WCH CH32L103EVT is clocked by an external
8 MHz crystal or the internal 8 MHz oscillator and runs up to 96 MHz.
The CH32V208 SoC Features 4 USART, 4 GPIO ports, 2 SPI, 2 I2C, ADC, RTC,
CAN FD, USB 2.0 Host, USB Type-C PD, OPA, and several timers.

Supported Features
==================

.. zephyr:board-supported-hw::

Connections and IOs
===================

LED
---

* LED3/LED4 = Unconnected. Connect to an I/O pin (PA1).

Button
------

* S1 = Reset Button

Programming and Debugging
*************************

.. zephyr:board-supported-runners::

Applications for the ``CH32L103EVT`` board target can be built and flashed
in the usual way (see :ref:`build_an_application` and :ref:`application_run`
for more details); however, an external programmer is required since the board
does not have any built-in debug support.

The following pins of the external programmer must be connected to the
following pins on the PCB:

* VCC = VCC
* GND = GND
* SWIO = PA13
* SWCLK = PA14

Flashing
========

You can use ``minichlink`` to flash the board. Once ``minichlink`` has been set
up, build and flash applications as usual (see :ref:`build_an_application` and
:ref:`application_run` for more details).

Here is an example for the :zephyr:code-sample:`blinky` application.

.. zephyr-app-commands::
:zephyr-app: samples/basic/blinky
:board: ch32l103evt
:goals: build flash

Debugging
=========

This board can be debugged via ``minichlink``.

References
**********

.. target-notes::

.. _WCH: http://www.wch-ic.com
.. _WCH webpage on CH32L103: https://www.wch-ic.com/products/CH32L103.html
.. _WCH webpage on CH32L103EVT: https://www.wch.cn/downloads/CH32L103EVT_ZIP.html
15 changes: 15 additions & 0 deletions boards/wch/ch32l103evt/support/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#interface wlink
adapter driver wlink
wlink_set
set _CHIPNAME riscv
jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x00001

set _TARGETNAME $_CHIPNAME.cpu

target create $_TARGETNAME.0 riscv -chain-position $_TARGETNAME
$_TARGETNAME.0 configure -work-area-phys 0x80000000 -work-area-size 10000 -work-area-backup 1
set _FLASHNAME $_CHIPNAME.flash

flash bank $_FLASHNAME wch_riscv 0x00000000 0 0 0 $_TARGETNAME.0

echo "Ready for Remote Connections"
Loading