Skip to content

Commit 64067e5

Browse files
nzmichaelhkartben
authored andcommitted
soc: wch: add the CH32V00x series
Compared to the CH32V003, the CH32V00x series is an evolution that uses a different microarchitecture (V2C instead of V2A) and different pinctrl mappings. Fork the current qingke_v2a and use the new proposed naming convention. Signed-off-by: Michael Hope <[email protected]>
1 parent d68c184 commit 64067e5

File tree

10 files changed

+159
-0
lines changed

10 files changed

+159
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2024 Michael Hope
2+
# Copyright (c) 2024 Jianxiong Gu
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
zephyr_sources(
6+
soc_irq.S
7+
vector.S
8+
)
9+
10+
zephyr_include_directories(.)

soc/wch/ch32v/ch32v00x/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Michael Hope <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_SERIES_CH32V00X
5+
select RISCV_ISA_RV32E
6+
select RISCV_ISA_EXT_ZICSR
7+
select RISCV_ISA_EXT_ZIFENCEI
8+
select RISCV_ISA_EXT_C
9+
select RISCV_ISA_EXT_ZMMUL
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2025 Michael Hope <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SOC_SERIES_CH32V00X
5+
6+
config SYS_CLOCK_HW_CYCLES_PER_SEC
7+
default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency)
8+
9+
config CLOCK_CONTROL
10+
default y
11+
12+
rsource "Kconfig.defconfig.*"
13+
14+
endif # SOC_SERIES_CH32V00X
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2025 Michael Hope <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SOC_SERIES_CH32V00X
5+
6+
config VECTOR_TABLE_SIZE
7+
default 41
8+
9+
config NUM_IRQS
10+
default 41
11+
12+
endif # SOC_SERIES_CH32V00X

soc/wch/ch32v/ch32v00x/Kconfig.soc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2025 Michael Hope <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_SERIES_CH32V00X
5+
bool
6+
select SOC_FAMILY_CH32V
7+
8+
config SOC_SERIES
9+
default "ch32v00x" if SOC_SERIES_CH32V00X
10+
11+
rsource "Kconfig.soc.*"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Michael Hope <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_CH32V006
5+
bool
6+
select SOC_SERIES_CH32V00X
7+
8+
config SOC
9+
default "ch32v006" if SOC_CH32V006
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2024 Michael Hope
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef __PINCTRL_SOC_H__
8+
#define __PINCTRL_SOC_H__
9+
10+
/**
11+
* @brief Type to hold a pin's pinctrl configuration.
12+
*/
13+
struct ch32v00x_pinctrl_soc_pin {
14+
uint32_t config: 22;
15+
bool bias_pull_up: 1;
16+
bool bias_pull_down: 1;
17+
bool drive_open_drain: 1;
18+
bool drive_push_pull: 1;
19+
bool output_high: 1;
20+
bool output_low: 1;
21+
uint8_t slew_rate: 2;
22+
};
23+
24+
typedef struct ch32v00x_pinctrl_soc_pin pinctrl_soc_pin_t;
25+
26+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
27+
{ \
28+
.config = DT_PROP_BY_IDX(node_id, prop, idx), \
29+
.bias_pull_up = DT_PROP(node_id, bias_pull_up), \
30+
.bias_pull_down = DT_PROP(node_id, bias_pull_down), \
31+
.drive_open_drain = DT_PROP(node_id, drive_open_drain), \
32+
.drive_push_pull = DT_PROP(node_id, drive_push_pull), \
33+
.output_high = DT_PROP(node_id, output_high), \
34+
.output_low = DT_PROP(node_id, output_low), \
35+
.slew_rate = DT_ENUM_IDX(node_id, slew_rate), \
36+
},
37+
38+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
39+
{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \
40+
Z_PINCTRL_STATE_PIN_INIT)}
41+
42+
#endif

soc/wch/ch32v/ch32v00x/soc_irq.S

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2024 Michael Hope
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <offsets.h>
8+
#include <zephyr/toolchain.h>
9+
10+
/* Exports */
11+
GTEXT(__soc_is_irq)
12+
GTEXT(__soc_handle_irq)
13+
14+
SECTION_FUNC(exception.other, __soc_is_irq)
15+
csrr a0, mcause
16+
srli a0, a0, 31
17+
ret
18+
19+
SECTION_FUNC(exception.other, __soc_handle_irq)
20+
ret

soc/wch/ch32v/ch32v00x/vector.S

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2024 Michael Hope
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/toolchain.h>
8+
9+
#ifndef CONFIG_VECTOR_TABLE_SIZE
10+
#error "VECTOR_TABLE_SIZE must be defined"
11+
#endif
12+
13+
/* Exports */
14+
GTEXT(__start)
15+
16+
/* Imports */
17+
GTEXT(__initialize)
18+
19+
SECTION_FUNC(vectors, ivt)
20+
.option norvc
21+
j __start
22+
.rept CONFIG_VECTOR_TABLE_SIZE
23+
.word _isr_wrapper
24+
.endr
25+
26+
SECTION_FUNC(vectors, __start)
27+
li a0, 3
28+
csrw mtvec, a0
29+
j __initialize

soc/wch/ch32v/soc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ family:
77
- name: qingke-v2a
88
socs:
99
- name: ch32v003
10+
- name: ch32v00x
11+
socs:
12+
- name: ch32v006
1013
- name: qingke-v4c
1114
socs:
1215
- name: ch32v208

0 commit comments

Comments
 (0)