diff --git a/soc/wch/ch32v/qingke_v4b/CMakeLists.txt b/soc/wch/ch32v/qingke_v4b/CMakeLists.txt new file mode 100644 index 00000000000..a7e9de643d6 --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2024 Michael Hope +# Copyright (c) 2024 Jianxiong Gu +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources( + soc_irq.S + vector.S +) + +zephyr_include_directories(.) diff --git a/soc/wch/ch32v/qingke_v4b/Kconfig b/soc/wch/ch32v/qingke_v4b/Kconfig new file mode 100644 index 00000000000..1706900e7cd --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/Kconfig @@ -0,0 +1,10 @@ +# Copyright (c) 2025 MASSDRIVER EI (massdriver.space) +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_QINGKE_V4B + select RISCV_ISA_RV32I + select RISCV_ISA_EXT_M + select RISCV_ISA_EXT_A + select RISCV_ISA_EXT_C + select RISCV_ISA_EXT_ZICSR + select RISCV_ISA_EXT_ZIFENCEI diff --git a/soc/wch/ch32v/qingke_v4b/Kconfig.defconfig b/soc/wch/ch32v/qingke_v4b/Kconfig.defconfig new file mode 100644 index 00000000000..817d778852a --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/Kconfig.defconfig @@ -0,0 +1,14 @@ +# Copyright (c) 2025 MASSDRIVER EI (massdriver.space) +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_QINGKE_V4B + +config SYS_CLOCK_HW_CYCLES_PER_SEC + default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency) + +config CLOCK_CONTROL + default y + +rsource "Kconfig.defconfig.*" + +endif # SOC_SERIES_QINGKE_V4B diff --git a/soc/wch/ch32v/qingke_v4b/Kconfig.defconfig.ch32v203 b/soc/wch/ch32v/qingke_v4b/Kconfig.defconfig.ch32v203 new file mode 100644 index 00000000000..dd4ca4aa679 --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/Kconfig.defconfig.ch32v203 @@ -0,0 +1,12 @@ +# Copyright (c) 2025 MASSDRIVER EI (massdriver.space) +# SPDX-License-Identifier: Apache-2.0 + +if SOC_CH32V203 + +config VECTOR_TABLE_SIZE + default 103 + +config NUM_IRQS + default 128 + +endif # SOC_CH32V203 diff --git a/soc/wch/ch32v/qingke_v4b/Kconfig.soc b/soc/wch/ch32v/qingke_v4b/Kconfig.soc new file mode 100644 index 00000000000..c4bf31f80b7 --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/Kconfig.soc @@ -0,0 +1,11 @@ +# Copyright (c) 2025 MASSDRIVER EI (massdriver.space) +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_QINGKE_V4B + bool + select SOC_FAMILY_CH32V + +config SOC_SERIES + default "qingke_v4b" if SOC_SERIES_QINGKE_V4B + +rsource "Kconfig.soc.*" diff --git a/soc/wch/ch32v/qingke_v4b/Kconfig.soc.ch32v203 b/soc/wch/ch32v/qingke_v4b/Kconfig.soc.ch32v203 new file mode 100644 index 00000000000..82538cde99f --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/Kconfig.soc.ch32v203 @@ -0,0 +1,9 @@ +# Copyright (c) 2025 MASSDRIVER EI (massdriver.space) +# SPDX-License-Identifier: Apache-2.0 + +config SOC_CH32V203 + bool + select SOC_SERIES_QINGKE_V4B + +config SOC + default "ch32v203" if SOC_CH32V203 diff --git a/soc/wch/ch32v/qingke_v4b/pinctrl_soc.h b/soc/wch/ch32v/qingke_v4b/pinctrl_soc.h new file mode 100644 index 00000000000..d11568a6124 --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/pinctrl_soc.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Michael Hope + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __PINCTRL_SOC_H__ +#define __PINCTRL_SOC_H__ + +/** + * @brief Type to hold a pin's pinctrl configuration. + */ +struct ch32v203_pinctrl_soc_pin { + uint32_t config: 22; + bool bias_pull_up: 1; + bool bias_pull_down: 1; + bool drive_open_drain: 1; + bool drive_push_pull: 1; + bool output_high: 1; + bool output_low: 1; + uint8_t slew_rate: 2; +}; + +typedef struct ch32v203_pinctrl_soc_pin pinctrl_soc_pin_t; + +#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ + { \ + .config = DT_PROP_BY_IDX(node_id, prop, idx), \ + .bias_pull_up = DT_PROP(node_id, bias_pull_up), \ + .bias_pull_down = DT_PROP(node_id, bias_pull_down), \ + .drive_open_drain = DT_PROP(node_id, drive_open_drain), \ + .drive_push_pull = DT_PROP(node_id, drive_push_pull), \ + .output_high = DT_PROP(node_id, output_high), \ + .output_low = DT_PROP(node_id, output_low), \ + .slew_rate = DT_ENUM_IDX(node_id, slew_rate), \ + }, + +#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ + {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \ + Z_PINCTRL_STATE_PIN_INIT)} + +#endif diff --git a/soc/wch/ch32v/qingke_v4b/soc_irq.S b/soc/wch/ch32v/qingke_v4b/soc_irq.S new file mode 100644 index 00000000000..fcb0daea51d --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/soc_irq.S @@ -0,0 +1,19 @@ +/* Copyright (c) 2024 Michael Hope + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* Exports */ +GTEXT(__soc_is_irq) +GTEXT(__soc_handle_irq) + +SECTION_FUNC(exception.other, __soc_is_irq) + csrr a0, mcause + srli a0, a0, 31 + ret + +SECTION_FUNC(exception.other, __soc_handle_irq) + ret diff --git a/soc/wch/ch32v/qingke_v4b/vector.S b/soc/wch/ch32v/qingke_v4b/vector.S new file mode 100644 index 00000000000..97766e820fd --- /dev/null +++ b/soc/wch/ch32v/qingke_v4b/vector.S @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 Michael Hope + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#ifndef CONFIG_VECTOR_TABLE_SIZE +#error "VECTOR_TABLE_SIZE must be defined" +#endif + +/* Exports */ +GTEXT(__start) + +/* Imports */ +GTEXT(__initialize) + +SECTION_FUNC(vectors, ivt) + .option norvc + /* Jump to 0x08000008, into the main flash zone where j __start is */ + lui x5, 0x8000 + jr 0x8(x5) + j __start + .rept CONFIG_VECTOR_TABLE_SIZE + .word _isr_wrapper + .endr + +SECTION_FUNC(vectors, __start) + li a0, 0xf + csrw mtvec, a0 + j __initialize diff --git a/soc/wch/ch32v/soc.yml b/soc/wch/ch32v/soc.yml index 0d68990413f..312de11090c 100644 --- a/soc/wch/ch32v/soc.yml +++ b/soc/wch/ch32v/soc.yml @@ -13,3 +13,6 @@ family: - name: qingke-v4c socs: - name: ch32v208 + - name: qingke-v4b + socs: + - name: ch32v203