Skip to content

Add support for WCH CH32L103 #89451

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions dts/riscv/wch/ch32l103/ch32l103.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2025 Paul Wedeck
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <wch/ch32v208/ch32v208.dtsi>


/ {
soc {
dma1: dma@40020000 {
compatible = "wch,wch-dma";
reg = <0x40020000 0x90>;
clocks = <&rcc CH32V20X_V30X_CLOCK_DMA1>;
#dma-cells = <1>;
interrupt-parent = <&pfic>;
interrupts = <27>, <28>, <29>, <30>, <31>, <32>, <33>, <62>;
dma-channels = <8>;
};
};
};

&clk_hse {
clock-frequency = <DT_FREQ_M(25)>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HSE frequency depends on the crystal on the board, so move this out to the board definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I set it here is because ch32v208.dtsi sets it to a value larger than is supported by the l103.
The board uses a 8MHz crystal and sets the correct frequency in the board dts, so this rather marks the max value instead of the actual value.
Is is this a valid reasoning (for zephyr) or should I remove this part?

};

&clk_lsi {
clock-frequency = <DT_FREQ_K(40)>;
};

&sram0 {
reg = <0x20000000 DT_SIZE_K(20)>;
};

&flash {
reg = <0x40022000 0x28>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very similar to the definition in ch32v208.dtsi. Is the included file wrong? If so, should this fix be there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this was already wrong for the v208. Should I include a commit here or add a separate pr?

};

&flash0 {
reg = <0 DT_SIZE_K(64)>;
};

&gpioa {
ngpios = <16>;
};

&gpiob {
ngpios = <16>;
};

&gpioc {
gpio-reserved-ranges = <0 13>;
ngpios = <16>;
};

&gpiod {
ngpios = <2>;
};

&usart4 {
interrupts = <61>;
};

&cpu0 {
clock-frequency = <DT_FREQ_M(96)>;
};
7 changes: 7 additions & 0 deletions dts/riscv/wch/ch32l103/ch32l103c8t.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2025 Paul Wedeck
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <wch/ch32l103/ch32l103.dtsi>
15 changes: 15 additions & 0 deletions dts/riscv/wch/ch32l103/ch32l103f8p.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2025 Paul Wedeck
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <wch/ch32l103/ch32l103.dtsi>

&gpioa {
gpio-reserved-ranges = <9, 3>, <15, 1>;
};

&gpiob {
gpio-reserved-ranges = <0, 1>, <2, 4>, <9, 7>;
};
15 changes: 15 additions & 0 deletions dts/riscv/wch/ch32l103/ch32l103f8u.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2025 Paul Wedeck
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <wch/ch32l103/ch32l103.dtsi>

&gpioa {
gpio-reserved-ranges = <15, 1>;
};

&gpiob {
gpio-reserved-ranges = <2, 4>, <8, 2>, <12, 1>;
};
15 changes: 15 additions & 0 deletions dts/riscv/wch/ch32l103/ch32l103g8r.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2025 Paul Wedeck
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <wch/ch32l103/ch32l103.dtsi>

&gpioa {
gpio-reserved-ranges = <15, 1>;
};

&gpiob {
gpio-reserved-ranges = <2, 1>, <4, 1>, <9, 1>;
};
11 changes: 11 additions & 0 deletions dts/riscv/wch/ch32l103/ch32l103k8u.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2025 Paul Wedeck
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <wch/ch32l103/ch32l103.dtsi>

&gpiob {
gpio-reserved-ranges = <10, 5>;
};
12 changes: 12 additions & 0 deletions soc/wch/ch32v/qingke_v4c/Kconfig.defconfig.ch32l103
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2025 Paul Wedeck
# SPDX-License-Identifier: Apache-2.0

if SOC_CH32L103

config VECTOR_TABLE_SIZE
default 68

config NUM_IRQS
default 128

endif # SOC_CH32L103
9 changes: 9 additions & 0 deletions soc/wch/ch32v/qingke_v4c/Kconfig.soc.ch32l103
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2025 Paul Wedeck
# SPDX-License-Identifier: Apache-2.0

config SOC_CH32L103
bool
select SOC_SERIES_QINGKE_V4C

config SOC
default "ch32l103" if SOC_CH32L103
1 change: 1 addition & 0 deletions soc/wch/ch32v/soc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ family:
- name: qingke-v4c
socs:
- name: ch32v208
- name: ch32l103