From e19837594a19325108612805af2cea8fdfa9345b Mon Sep 17 00:00:00 2001 From: Miguel Gazquez Date: Thu, 15 May 2025 12:13:59 +0200 Subject: [PATCH 1/2] soc: wch: Deduplicate common files across ch32v socs Moves shared files from multiple ch32v SoCs into a new `common/` directory to eliminate duplication. Signed-off-by: Miguel Gazquez --- soc/wch/ch32v/ch32v00x/CMakeLists.txt | 4 +-- soc/wch/ch32v/ch32v00x/soc_irq.S | 20 ------------ .../{ch32v00x => common/qingke_v2x}/vector.S | 0 .../{qingke_v4c => common/qingke_v4}/vector.S | 0 .../ch32v/{qingke_v2a => common}/soc_irq.S | 0 soc/wch/ch32v/qingke_v2a/CMakeLists.txt | 4 +-- soc/wch/ch32v/qingke_v2a/vector.S | 29 ----------------- soc/wch/ch32v/qingke_v4b/CMakeLists.txt | 4 +-- soc/wch/ch32v/qingke_v4b/soc_irq.S | 19 ----------- soc/wch/ch32v/qingke_v4b/vector.S | 32 ------------------- soc/wch/ch32v/qingke_v4c/CMakeLists.txt | 4 +-- soc/wch/ch32v/qingke_v4c/soc_irq.S | 19 ----------- soc/wch/ch32v/qingke_v4f/CMakeLists.txt | 4 +-- soc/wch/ch32v/qingke_v4f/soc_irq.S | 19 ----------- soc/wch/ch32v/qingke_v4f/vector.S | 32 ------------------- 15 files changed, 10 insertions(+), 180 deletions(-) delete mode 100644 soc/wch/ch32v/ch32v00x/soc_irq.S rename soc/wch/ch32v/{ch32v00x => common/qingke_v2x}/vector.S (100%) rename soc/wch/ch32v/{qingke_v4c => common/qingke_v4}/vector.S (100%) rename soc/wch/ch32v/{qingke_v2a => common}/soc_irq.S (100%) delete mode 100644 soc/wch/ch32v/qingke_v2a/vector.S delete mode 100644 soc/wch/ch32v/qingke_v4b/soc_irq.S delete mode 100644 soc/wch/ch32v/qingke_v4b/vector.S delete mode 100644 soc/wch/ch32v/qingke_v4c/soc_irq.S delete mode 100644 soc/wch/ch32v/qingke_v4f/soc_irq.S delete mode 100644 soc/wch/ch32v/qingke_v4f/vector.S diff --git a/soc/wch/ch32v/ch32v00x/CMakeLists.txt b/soc/wch/ch32v/ch32v00x/CMakeLists.txt index a7e9de643d690..b75306e920faf 100644 --- a/soc/wch/ch32v/ch32v00x/CMakeLists.txt +++ b/soc/wch/ch32v/ch32v00x/CMakeLists.txt @@ -3,8 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_sources( - soc_irq.S - vector.S + ../common/soc_irq.S + ../common/qingke_v2x/vector.S ) zephyr_include_directories(.) diff --git a/soc/wch/ch32v/ch32v00x/soc_irq.S b/soc/wch/ch32v/ch32v00x/soc_irq.S deleted file mode 100644 index 04f1407e2ad38..0000000000000 --- a/soc/wch/ch32v/ch32v00x/soc_irq.S +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/ch32v00x/vector.S b/soc/wch/ch32v/common/qingke_v2x/vector.S similarity index 100% rename from soc/wch/ch32v/ch32v00x/vector.S rename to soc/wch/ch32v/common/qingke_v2x/vector.S diff --git a/soc/wch/ch32v/qingke_v4c/vector.S b/soc/wch/ch32v/common/qingke_v4/vector.S similarity index 100% rename from soc/wch/ch32v/qingke_v4c/vector.S rename to soc/wch/ch32v/common/qingke_v4/vector.S diff --git a/soc/wch/ch32v/qingke_v2a/soc_irq.S b/soc/wch/ch32v/common/soc_irq.S similarity index 100% rename from soc/wch/ch32v/qingke_v2a/soc_irq.S rename to soc/wch/ch32v/common/soc_irq.S diff --git a/soc/wch/ch32v/qingke_v2a/CMakeLists.txt b/soc/wch/ch32v/qingke_v2a/CMakeLists.txt index a7e9de643d690..b75306e920faf 100644 --- a/soc/wch/ch32v/qingke_v2a/CMakeLists.txt +++ b/soc/wch/ch32v/qingke_v2a/CMakeLists.txt @@ -3,8 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_sources( - soc_irq.S - vector.S + ../common/soc_irq.S + ../common/qingke_v2x/vector.S ) zephyr_include_directories(.) diff --git a/soc/wch/ch32v/qingke_v2a/vector.S b/soc/wch/ch32v/qingke_v2a/vector.S deleted file mode 100644 index d078444d85e15..0000000000000 --- a/soc/wch/ch32v/qingke_v2a/vector.S +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 - j __start - .rept CONFIG_VECTOR_TABLE_SIZE - .word _isr_wrapper - .endr - -SECTION_FUNC(vectors, __start) - li a0, 3 - csrw mtvec, a0 - j __initialize diff --git a/soc/wch/ch32v/qingke_v4b/CMakeLists.txt b/soc/wch/ch32v/qingke_v4b/CMakeLists.txt index a7e9de643d690..ff02c32fd5e26 100644 --- a/soc/wch/ch32v/qingke_v4b/CMakeLists.txt +++ b/soc/wch/ch32v/qingke_v4b/CMakeLists.txt @@ -3,8 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_sources( - soc_irq.S - vector.S + ../common/soc_irq.S + ../common/qingke_v4/vector.S ) zephyr_include_directories(.) diff --git a/soc/wch/ch32v/qingke_v4b/soc_irq.S b/soc/wch/ch32v/qingke_v4b/soc_irq.S deleted file mode 100644 index fcb0daea51d01..0000000000000 --- a/soc/wch/ch32v/qingke_v4b/soc_irq.S +++ /dev/null @@ -1,19 +0,0 @@ -/* 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 deleted file mode 100644 index 97766e820fddf..0000000000000 --- a/soc/wch/ch32v/qingke_v4b/vector.S +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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/qingke_v4c/CMakeLists.txt b/soc/wch/ch32v/qingke_v4c/CMakeLists.txt index a7e9de643d690..ff02c32fd5e26 100644 --- a/soc/wch/ch32v/qingke_v4c/CMakeLists.txt +++ b/soc/wch/ch32v/qingke_v4c/CMakeLists.txt @@ -3,8 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_sources( - soc_irq.S - vector.S + ../common/soc_irq.S + ../common/qingke_v4/vector.S ) zephyr_include_directories(.) diff --git a/soc/wch/ch32v/qingke_v4c/soc_irq.S b/soc/wch/ch32v/qingke_v4c/soc_irq.S deleted file mode 100644 index fcb0daea51d01..0000000000000 --- a/soc/wch/ch32v/qingke_v4c/soc_irq.S +++ /dev/null @@ -1,19 +0,0 @@ -/* 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_v4f/CMakeLists.txt b/soc/wch/ch32v/qingke_v4f/CMakeLists.txt index a7e9de643d690..ff02c32fd5e26 100644 --- a/soc/wch/ch32v/qingke_v4f/CMakeLists.txt +++ b/soc/wch/ch32v/qingke_v4f/CMakeLists.txt @@ -3,8 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_sources( - soc_irq.S - vector.S + ../common/soc_irq.S + ../common/qingke_v4/vector.S ) zephyr_include_directories(.) diff --git a/soc/wch/ch32v/qingke_v4f/soc_irq.S b/soc/wch/ch32v/qingke_v4f/soc_irq.S deleted file mode 100644 index fcb0daea51d01..0000000000000 --- a/soc/wch/ch32v/qingke_v4f/soc_irq.S +++ /dev/null @@ -1,19 +0,0 @@ -/* 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_v4f/vector.S b/soc/wch/ch32v/qingke_v4f/vector.S deleted file mode 100644 index 97766e820fddf..0000000000000 --- a/soc/wch/ch32v/qingke_v4f/vector.S +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 From a4fe886ead27fe10037d29739b811500f5d13724 Mon Sep 17 00:00:00 2001 From: Miguel Gazquez Date: Tue, 27 May 2025 12:10:13 +0200 Subject: [PATCH 2/2] soc: wch: rename pinctrl struct for the ch32v303 Rename the struct ch32v303_pinctrl_soc_pin to ch32v30x_pinctrl_soc_pin to allow the same struct to be used for other SoC of the series. Signed-off-by: Miguel Gazquez --- soc/wch/ch32v/qingke_v4f/pinctrl_soc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/soc/wch/ch32v/qingke_v4f/pinctrl_soc.h b/soc/wch/ch32v/qingke_v4f/pinctrl_soc.h index 527e9b5197c8b..d6c7590749fc2 100644 --- a/soc/wch/ch32v/qingke_v4f/pinctrl_soc.h +++ b/soc/wch/ch32v/qingke_v4f/pinctrl_soc.h @@ -10,7 +10,7 @@ /** * @brief Type to hold a pin's pinctrl configuration. */ -struct ch32v303_pinctrl_soc_pin { +struct ch32v30x_pinctrl_soc_pin { uint32_t config: 22; bool bias_pull_up: 1; bool bias_pull_down: 1; @@ -21,7 +21,7 @@ struct ch32v303_pinctrl_soc_pin { uint8_t slew_rate: 2; }; -typedef struct ch32v303_pinctrl_soc_pin pinctrl_soc_pin_t; +typedef struct ch32v30x_pinctrl_soc_pin pinctrl_soc_pin_t; #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ { \