Skip to content

Commit f136a83

Browse files
committed
samples: pwm: add the CH32V003EVT to the blinky_pwm and led/pwm samples
The CH32V003 has a single red LED that can be driven by GPIO or by CH1 of TIM2. Add to the samples. Signed-off-by: Michael Hope <[email protected]>
1 parent 2f6647d commit f136a83

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed

boards/wch/ch32v003evt/ch32v003evt-pinctrl.dtsi

+9
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@
1818
bias-pull-up;
1919
};
2020
};
21+
22+
red_pwm_pinctrl: red_pwm_pinctrl {
23+
group1 {
24+
pinmux = <TIM2_CH1_PD4_0>;
25+
output-high;
26+
drive-push-pull;
27+
slew-rate = "max-speed-10mhz";
28+
};
29+
};
2130
};

boards/wch/ch32v003evt/ch32v003evt.dts

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <wch/ch32v0/ch32v003f4p.dtsi>
99
#include "ch32v003evt-pinctrl.dtsi"
10+
#include <zephyr/dt-bindings/pwm/pwm.h>
1011

1112
/ {
1213
model = "ch32v003evt";
@@ -34,8 +35,19 @@
3435
};
3536
};
3637

38+
pwmleds: pwmleds {
39+
compatible = "pwm-leds";
40+
status = "disabled";
41+
42+
red_pwm: red_pwm0 {
43+
pwms = <&tim2 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
44+
label = "Red LED";
45+
};
46+
};
47+
3748
aliases {
3849
led0 = &red_led;
50+
pwm-led0 = &red_pwm;
3951
};
4052
};
4153

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_LOG_MODE_MINIMAL=y
2+
CONFIG_CBPRINTF_NANO=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2025 Michael Hope <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
leds {
9+
status = "disabled";
10+
};
11+
};
12+
13+
&pwmleds {
14+
status = "okay";
15+
};
16+
17+
&tim2 {
18+
status = "okay";
19+
/*
20+
* The sample runs from 1 Hz to 128 Hz, ceil(48 MHz / 65536 / 1 Hz)
21+
* is 733, and the prescaler property is one less than that.
22+
*/
23+
prescaler = <732>;
24+
pinctrl-0 = <&red_pwm_pinctrl>;
25+
pinctrl-names = "default";
26+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_LOG_MODE_MINIMAL=y
2+
CONFIG_CBPRINTF_NANO=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2025 Michael Hope <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
leds {
9+
status = "disabled";
10+
};
11+
};
12+
13+
&pwmleds {
14+
status = "okay";
15+
};
16+
17+
&tim2 {
18+
status = "okay";
19+
/*
20+
* The sample blinks the LED at 0.5 Hz, ceil(48 MHz / 65536 / 0.5 Hz)
21+
* is 1465, and the prescaler property is one less than that.
22+
*/
23+
prescaler = <1464>;
24+
pinctrl-0 = <&red_pwm_pinctrl>;
25+
pinctrl-names = "default";
26+
};

0 commit comments

Comments
 (0)