-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add Zephyr RTOS support for WCH CH32V003 #73761
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
Changes from all commits
861b4aa
802220b
1b392ba
1f114da
a833b7e
e39b5b1
3627c26
563928d
553bb44
d82900a
771c85c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Copyright (c) 2024 Dhiru Kholia | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| board_set_flasher_ifnset(minichlink) | ||
| board_finalize_runner_args(minichlink) | ||
| 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_CH32V003EVT | ||
| select SOC_CH32V003 |
| 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 | ||
|
|
||
| board_runner_args(openocd "--use-elf" "--cmd-reset-halt" "halt") | ||
| include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) | ||
|
|
||
| board_runner_args(minichlink) | ||
| include(${ZEPHYR_BASE}/boards/common/minichlink.board.cmake) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| board: | ||
| name: ch32v003evt | ||
| full_name: WCH CH32V003EVT | ||
| vendor: wch | ||
| socs: | ||
| - name: ch32v003 |
| 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; | ||
| }; | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Copyright (c) 2024 Michael Hope <[email protected]> | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /dts-v1/; | ||
|
|
||
| #include <wch/ch32v00x.dtsi> | ||
| #include "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"; | ||
|
|
||
| /* | ||
| * Please connect the unconnected LED on the WCH CH32V003EVT | ||
| * board to a suitable GPIO pin (like PD4) and then change | ||
| * this status to "okay". | ||
| */ | ||
| status = "disabled"; | ||
|
|
||
| red_led: led0 { | ||
|
||
| gpios = <&gpiod 4 GPIO_ACTIVE_HIGH>; | ||
| }; | ||
| }; | ||
|
|
||
| aliases { | ||
| led0 = &red_led; | ||
| }; | ||
| }; | ||
|
|
||
| &clk_hse { | ||
| clock-frequency = <DT_FREQ_M(24)>; | ||
| status = "okay"; | ||
| }; | ||
|
|
||
| &pll { | ||
| clocks = <&clk_hse>; | ||
| status = "okay"; | ||
| }; | ||
gmarull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| &rcc { | ||
| clocks = <&pll>; | ||
| }; | ||
|
|
||
| &gpiod { | ||
| status = "okay"; | ||
| }; | ||
|
|
||
| &usart1 { | ||
| status = "okay"; | ||
| current-speed = <115200>; | ||
| pinctrl-0 = <&usart1_default>; | ||
| pinctrl-names = "default"; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| identifier: ch32v003evt | ||
| name: WCH CH32V003 Evaluation Board | ||
| type: mcu | ||
| arch: riscv | ||
| toolchain: | ||
| - cross-compile | ||
| - zephyr | ||
| ram: 2 | ||
| flash: 16 | ||
| supported: | ||
| - gpio |
kholia marked this conversation as resolved.
Show resolved
Hide resolved
|
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| .. zephyr:board:: 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)` | ||
|
|
||
| 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 ``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 | | ||
kholia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| +-----------+------------+----------------------+ | ||
| | 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 ``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 built-in debug support. | ||
|
|
||
| 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: 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/ch32v003evt.dts`. | ||
|
|
||
| References | ||
| ********** | ||
|
|
||
| .. target-notes:: | ||
|
|
||
| .. _WCH: http://www.wch-ic.com | ||
| .. _WCH webpage on CH32V003: https://www.wch-ic.com/products/CH32V003.html | ||
| 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" |
| 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: | ||
|
|
||
| **/* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Copyright (c) 2024 Michael Hope | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config CLOCK_CONTROL_WCH_RCC | ||
| bool "WCH CH32V00x Reset and Clock Control (RCC) driver" | ||
| default y | ||
| depends on DT_HAS_WCH_RCC_ENABLED |
Uh oh!
There was an error while loading. Please reload this page.