Skip to content

Commit b7fb2e8

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 TIM2 CH1. Add to the samples. Signed-off-by: Michael Hope <[email protected]>
1 parent eacfbbb commit b7fb2e8

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-0
lines changed

boards/wch/ch32v003evt/ch32v003evt-pinctrl.dtsi

+9
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@
2626
drive-open-drain;
2727
};
2828
};
29+
30+
red_pwm_pinctrl: red_pwm_pinctrl {
31+
group1 {
32+
pinmux = <TIM2_CH1_PD4_0>;
33+
output-high;
34+
drive-push-pull;
35+
slew-rate = "max-speed-10mhz";
36+
};
37+
};
2938
};

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
#include <zephyr/dt-bindings/gpio/gpio.h>
1213
#include <zephyr/dt-bindings/i2c/i2c.h>
@@ -37,8 +38,19 @@
3738
};
3839
};
3940

41+
pwmleds: pwmleds {
42+
compatible = "pwm-leds";
43+
status = "disabled";
44+
45+
red_pwm: red_pwm0 {
46+
pwms = <&pwm2 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
47+
label = "Red LED";
48+
};
49+
};
50+
4051
aliases {
4152
led0 = &red_led;
53+
pwm-led0 = &red_pwm;
4254
};
4355
};
4456

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,30 @@
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+
};
25+
26+
&pwm2 {
27+
status = "okay";
28+
pinctrl-0 = <&red_pwm_pinctrl>;
29+
pinctrl-names = "default";
30+
};
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)