Skip to content

Commit

Permalink
boards: add ch32v003evt
Browse files Browse the repository at this point in the history
This commit adds support for the CH32V003EVT board which features a
32-bit general-purpose RISC-V MCU.

Signed-off-by: Michael Hope <[email protected]>
Signed-off-by: Dhiru Kholia <[email protected]>
  • Loading branch information
nzmichaelh authored and kholia committed Oct 2, 2024
1 parent d101dfd commit 26f8d4e
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 0 deletions.
5 changes: 5 additions & 0 deletions boards/wch/ch32v003evt/Kconfig.wch_ch32v003evt
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

config BOARD_WCH_CH32V003EVT
select SOC_CH32V003
5 changes: 5 additions & 0 deletions boards/wch/ch32v003evt/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(openocd "--use-elf" "--cmd-reset-halt" "halt")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
5 changes: 5 additions & 0 deletions boards/wch/ch32v003evt/board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
board:
name: wch_ch32v003evt
vendor: wch
socs:
- name: ch32v003
Binary file not shown.
116 changes: 116 additions & 0 deletions boards/wch/ch32v003evt/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.. _wch_ch32v003evt:

WCH CH32V003EVT
###############

Overview
********

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

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

.. figure:: img/wch_ch32v003evt_front.webp
:align: center
:alt: WCH CH32V003EVT

WCH CH32V003EVT (Credit: WCH)

The board is equipped with two LEDs. The `WCH webpage on CH32V003`_ contains
the processor's information and the datasheet.

Hardware
********

The QingKe 32-bit RISC-V2A processor of the WCH CH32V003EVT is clocked by an
external crystal and runs at 48 MHz.

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

The ``wch_ch32v003evt`` board target supports the following hardware features:

+-----------+------------+----------------------+
| Interface | Controller | Driver/Component |
+===========+============+======================+
| CLOCK | on-chip | clock_control |
+-----------+------------+----------------------+
| GPIO | on-chip | gpio |
+-----------+------------+----------------------+
| PWM | on-chip | pwm |
+-----------+------------+----------------------+
| PINCTRL | on-chip | pinctrl |
+-----------+------------+----------------------+
| TIMER | on-chip | timer |
+-----------+------------+----------------------+
| UART | on-chip | uart |
+-----------+------------+----------------------+

Other hardware features have not been enabled yet for this board.

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

LED
---

* LED1 = Unconnected. Connect to an I/O pin (PD4).

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

Applications for the ``wch_ch32v003evt`` 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 on-board debug IC.

The following pins of the external programmer must be connected to the
following pins on the PCB (see image):

* VCC = VCC (do not power the board from the USB port at the same time)
* GND = GND
* SWIO = PD1

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: wch_ch32v003evt
:goals: build flash

Debugging
=========

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

Testing the LED on the WCH CH32V003EVT
**************************************

There is 1 sample program that allow you to test that the LED on the board is
working properly with Zephyr:

.. code-block:: console
samples/basic/blinky
You can build and flash the examples to make sure Zephyr is running
correctly on your board. The button and LED definitions can be found
in :zephyr_file:`boards/wch/ch32v003evt/wch_ch32v003evt.dts`.

References
**********

.. target-notes::

.. _WCH: http://www.wch-ic.com
.. _WCH webpage on CH32V003: https://www.wch-ic.com/products/CH32V003.html
15 changes: 15 additions & 0 deletions boards/wch/ch32v003evt/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"
21 changes: 21 additions & 0 deletions boards/wch/ch32v003evt/wch_ch32v003evt-pinctrl.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Michael Hope <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

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

&pinctrl {
usart1_default: usart1_default {
group1 {
pinmux = <USART1_TX_PD5_0>;
output-high;
drive-push-pull;
slew-rate = "max-speed-10mhz";
};
group2 {
pinmux = <USART1_RX_PD6_0>;
bias-pull-up;
};
};
};
44 changes: 44 additions & 0 deletions boards/wch/ch32v003evt/wch_ch32v003evt.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 Michael Hope <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

/dts-v1/;

#include <wch/ch32v00x.dtsi>
#include "wch_ch32v003evt-pinctrl.dtsi"

/ {
model = "ch32v003evt";
compatible = "wch,ch32v003";

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

leds {
compatible = "gpio-leds";

red_led: led0 {
gpios = <&gpiod 4 GPIO_ACTIVE_HIGH>;
};
};

aliases {
led0 = &red_led;
};
};

&gpiod {
status = "okay";
};

&usart1 {
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&usart1_default>;
pinctrl-names = "default";
};
11 changes: 11 additions & 0 deletions boards/wch/ch32v003evt/wch_ch32v003evt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
identifier: wch_ch32v003evt
name: WCH CH32V003 Evaluation Board
type: mcu
arch: riscv
toolchain:
- cross-compile
- zephyr
ram: 2
flash: 16
supported:
- gpio
10 changes: 10 additions & 0 deletions boards/wch/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _boards-wch:

WCH - Nanjing Qinheng Microelectronics Co.
##########################################

.. toctree::
:maxdepth: 1
:glob:

**/*

0 comments on commit 26f8d4e

Please sign in to comment.