From e33a1f9943ed85dc5cfab4377835de17268ba04f Mon Sep 17 00:00:00 2001 From: Jorge Guzman Date: Fri, 24 Jul 2026 14:12:17 -0300 Subject: [PATCH] risc-v/gd32vw55x: add pwm example to gd32vw553k-start Add a "pwm" configuration that exercises the PWM driver on TIMER1. It is the nsh base plus the PWM driver, registered as /dev/pwm0 and driven by the pwm example (100 Hz, 50 % duty by default). TIMER1 channel 0 is routed to PA0 on the J1 header (AF1) so the waveform can be probed there; the other channels stay unrouted. Signed-off-by: Jorge Guzman --- .../boards/gd32vw553k-start/index.rst | 18 +++++++ .../gd32vw553k-start/configs/pwm/defconfig | 54 +++++++++++++++++++ .../gd32vw553k-start/include/board.h | 11 ++++ 3 files changed, 83 insertions(+) create mode 100644 boards/risc-v/gd32vw55x/gd32vw553k-start/configs/pwm/defconfig diff --git a/Documentation/platforms/risc-v/gd32vw55x/boards/gd32vw553k-start/index.rst b/Documentation/platforms/risc-v/gd32vw55x/boards/gd32vw553k-start/index.rst index 73906282b7e..1b933fde525 100644 --- a/Documentation/platforms/risc-v/gd32vw55x/boards/gd32vw553k-start/index.rst +++ b/Documentation/platforms/risc-v/gd32vw55x/boards/gd32vw553k-start/index.rst @@ -238,6 +238,24 @@ driver:: ``sht3x_register()`` in ``gd32_bringup.c`` (the i2ctool still finds it at its real address regardless). +pwm +--- + +NSH plus the PWM driver on TIMER1, registered as ``/dev/pwm0`` and driven by +the ``pwm`` example. Channel 0 (TIMER1_CH0) is routed to **PA0** on the J1 +header (AF1), so the waveform can be probed there. + +Run the example -- it drives a 5 s pulse train at the configured frequency and +duty (100 Hz, 50 % by default):: + + nsh> pwm + pwm_main: starting output with frequency: 100 channel: 1 duty: 00007fff + pwm_main: stopping output + +``pwm -f -d -t `` overrides the frequency, duty and +duration for a single run. Put an LED (with a series resistor) or a scope on +PA0 to see it. + littlefs -------- diff --git a/boards/risc-v/gd32vw55x/gd32vw553k-start/configs/pwm/defconfig b/boards/risc-v/gd32vw55x/gd32vw553k-start/configs/pwm/defconfig new file mode 100644 index 00000000000..e07066e0f7d --- /dev/null +++ b/boards/risc-v/gd32vw55x/gd32vw553k-start/configs/pwm/defconfig @@ -0,0 +1,54 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +CONFIG_ARCH="risc-v" +CONFIG_ARCH_BOARD="gd32vw553k-start" +CONFIG_ARCH_BOARD_GD32VW553K_START=y +CONFIG_ARCH_CHIP="gd32vw55x" +CONFIG_ARCH_CHIP_GD32VW553KM=y +CONFIG_ARCH_CHIP_GD32VW55X=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARDCTL_RESET=y +CONFIG_BOARD_LOOPSPERMSEC=16000 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_PWM=y +CONFIG_FS_PROCFS=y +CONFIG_GD32VW55X_PWM=y +CONFIG_GD32VW55X_TIMER1=y +CONFIG_GD32VW55X_UART2=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=64 +CONFIG_NSH_READLINE=y +CONFIG_NSH_STRERROR=y +CONFIG_RAM_SIZE=294400 +CONFIG_RAM_START=0x20000200 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=13 +CONFIG_START_MONTH=7 +CONFIG_START_YEAR=2026 +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=12 +CONFIG_UART2_RXBUFSIZE=128 +CONFIG_UART2_SERIAL_CONSOLE=y +CONFIG_UART2_TXBUFSIZE=128 diff --git a/boards/risc-v/gd32vw55x/gd32vw553k-start/include/board.h b/boards/risc-v/gd32vw55x/gd32vw553k-start/include/board.h index f5760c59eb6..da55b089268 100644 --- a/boards/risc-v/gd32vw55x/gd32vw553k-start/include/board.h +++ b/boards/risc-v/gd32vw55x/gd32vw553k-start/include/board.h @@ -95,6 +95,17 @@ # define GPIO_I2C1_SDA GPIO_I2C1_SDA_4 /* PB13, AF6 */ #endif +/* PWM. The board bringup registers /dev/pwm0 on TIMER1. Route its channel + * 0 (TIMER1_CH0) to PA0 on the J1 header (AF1; TIMER1 lives on AF1) so the + * output can be probed there. The other channels stay unrouted. + */ + +#ifdef CONFIG_GD32VW55X_PWM +# define GPIO_TIMER1_CH0OUT (GPIO_CFG_MODE_AF | GPIO_CFG_PUPD_NONE | \ + GPIO_CFG_PP | GPIO_CFG_SPEED_MAX | \ + GPIO_CFG_AF_1 | GPIO_CFG_PORT_A | GPIO_CFG_PIN_0) +#endif + /* LEDs *********************************************************************/ /* The GD32VW553K-START has three LEDs on GPIOC, driven push-pull and