Skip to content

Commit 72dadd3

Browse files
VynDragonfabiobaltieri
authored andcommitted
soc: wch: Introduce Qingke V4B
Introduces the Soc for ch32v203 Signed-off-by: Camille BAUD <[email protected]>
1 parent 88b108d commit 72dadd3

File tree

10 files changed

+162
-0
lines changed

10 files changed

+162
-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/qingke_v4b/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2025 MASSDRIVER EI (massdriver.space)
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_SERIES_QINGKE_V4B
5+
select RISCV_ISA_RV32I
6+
select RISCV_ISA_EXT_M
7+
select RISCV_ISA_EXT_A
8+
select RISCV_ISA_EXT_C
9+
select RISCV_ISA_EXT_ZICSR
10+
select RISCV_ISA_EXT_ZIFENCEI
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2025 MASSDRIVER EI (massdriver.space)
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SOC_SERIES_QINGKE_V4B
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_QINGKE_V4B
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2025 MASSDRIVER EI (massdriver.space)
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SOC_CH32V203
5+
6+
config VECTOR_TABLE_SIZE
7+
default 103
8+
9+
config NUM_IRQS
10+
default 128
11+
12+
endif # SOC_CH32V203

soc/wch/ch32v/qingke_v4b/Kconfig.soc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2025 MASSDRIVER EI (massdriver.space)
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_SERIES_QINGKE_V4B
5+
bool
6+
select SOC_FAMILY_CH32V
7+
8+
config SOC_SERIES
9+
default "qingke_v4b" if SOC_SERIES_QINGKE_V4B
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 MASSDRIVER EI (massdriver.space)
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_CH32V203
5+
bool
6+
select SOC_SERIES_QINGKE_V4B
7+
8+
config SOC
9+
default "ch32v203" if SOC_CH32V203
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 ch32v203_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 ch32v203_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/qingke_v4b/soc_irq.S

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

soc/wch/ch32v/qingke_v4b/vector.S

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
/* Jump to 0x08000008, into the main flash zone where j __start is */
22+
lui x5, 0x8000
23+
jr 0x8(x5)
24+
j __start
25+
.rept CONFIG_VECTOR_TABLE_SIZE
26+
.word _isr_wrapper
27+
.endr
28+
29+
SECTION_FUNC(vectors, __start)
30+
li a0, 0xf
31+
csrw mtvec, a0
32+
j __initialize

soc/wch/ch32v/soc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ family:
1313
- name: qingke-v4c
1414
socs:
1515
- name: ch32v208
16+
- name: qingke-v4b
17+
socs:
18+
- name: ch32v203

0 commit comments

Comments
 (0)