[utest][pwm] Add configurable PWM matrix test

This commit is contained in:
CYFS
2026-09-01 09:33:32 +08:00
committed by Rbb666
parent 7a2af55ffb
commit f62b0ad85d
6 changed files with 865 additions and 0 deletions
+6
View File
@@ -1,3 +1,4 @@
import os
from building import *
cwd = GetCurrentDir()
@@ -29,4 +30,9 @@ if GetDepend(['RT_USING_RANDOM']):
if len(src):
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')
+39
View File
@@ -0,0 +1,39 @@
menu "PWM Test"
config RT_UTEST_PWM
bool "PWM Frequency and Duty-cycle Matrix Test"
default n
select RT_USING_PWM
help
Run configurable PWM groups. Channels in one group run concurrently,
while groups run in order. Each channel can keep a fixed output, sweep
once and hold its last point, or repeat its sweep for the group duration.
if RT_UTEST_PWM
config RT_PWM_TC_CONFIG_FILE
string "PWM test configuration header"
default "pwm_tc_config.h"
help
The header defines PWM_TC_GROUPS and PWM_TC_GROUP_COUNT. Keep the
default for the built-in example, or provide a board-specific header
from a compiler include path. Channel enable switches, device names,
channel numbers, output modes, and waveform points are kept in that
header because Kconfig cannot represent dynamic group/channel arrays.
config RT_PWM_TC_MAX_CHANNELS
int "Maximum concurrent channels in one PWM test group"
range 1 64
default 8
help
This limits enabled channels, not the total number of configured and
disabled channel entries in a group.
config RT_PWM_TC_TIMEOUT
int "PWM test timeout in seconds"
range 1 3600
default 30
endif
endmenu
+13
View File
@@ -0,0 +1,13 @@
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
src = []
CPPPATH = [cwd, cwd + '/../../include']
if GetDepend(['RT_UTEST_PWM']):
src += ['pwm_tc.c']
group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES', 'RT_USING_PWM'], CPPPATH = CPPPATH)
Return('group')
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,177 @@
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-08-25 RT-Thread add the default PWM matrix test configuration
*/
#ifndef __PWM_TC_CONFIG_H__
#define __PWM_TC_CONFIG_H__
/*
* Channel catalog
*
* Set ENABLED to RT_TRUE to include a channel in every group below, or
* RT_FALSE to skip it. Disabled channels are not looked up or started.
* READBACK_TOLERANCE is in permyriad; 0 disables PWM_CMD_GET verification.
* The default enables only channel 1, which sweeps continuously in each group.
*/
#define PWM_TC_CFG_CHANNEL_1_ENABLED RT_TRUE
#define PWM_TC_CFG_CHANNEL_1_DEVICE_NAME "pwm12"
#define PWM_TC_CFG_CHANNEL_1_NUMBER 0
#define PWM_TC_CFG_CHANNEL_1_READBACK_TOLERANCE 500U
#define PWM_TC_CFG_CHANNEL_2_ENABLED RT_FALSE
#define PWM_TC_CFG_CHANNEL_2_DEVICE_NAME "pwm2"
#define PWM_TC_CFG_CHANNEL_2_NUMBER 1
#define PWM_TC_CFG_CHANNEL_2_READBACK_TOLERANCE 0U
#define PWM_TC_CFG_CHANNEL_3_ENABLED RT_FALSE
#define PWM_TC_CFG_CHANNEL_3_DEVICE_NAME "pwm3"
#define PWM_TC_CFG_CHANNEL_3_NUMBER 1
#define PWM_TC_CFG_CHANNEL_3_READBACK_TOLERANCE 0U
#define PWM_TC_CFG_CHANNEL_4_ENABLED RT_FALSE
#define PWM_TC_CFG_CHANNEL_4_DEVICE_NAME "pwm4"
#define PWM_TC_CFG_CHANNEL_4_NUMBER 1
#define PWM_TC_CFG_CHANNEL_4_READBACK_TOLERANCE 0U
/* Group timing */
#define PWM_TC_CFG_GROUP_1_DURATION_MS 2000U
#define PWM_TC_CFG_GROUP_2_DURATION_MS 1000U
/*
* Waveform point tables
*
* PWM_TC_POINT_PERCENT takes frequency in Hz and duty cycle in percent.
* PWM_TC_POINT takes frequency in Hz and duty cycle in permyriad.
*/
static const struct pwm_tc_point pwm_tc_channel_1_sweep_points[] = {
PWM_TC_POINT_PERCENT(2500, 10),
PWM_TC_POINT_PERCENT(2500, 50),
PWM_TC_POINT_PERCENT(5000, 25),
PWM_TC_POINT_PERCENT(5000, 75),
};
static const struct pwm_tc_point pwm_tc_channel_2_sweep_points[] = {
PWM_TC_POINT_PERCENT(500, 20),
PWM_TC_POINT_PERCENT(1500, 40),
PWM_TC_POINT_PERCENT(4000, 60),
};
static const struct pwm_tc_point pwm_tc_channel_2_fixed_points[] = {
PWM_TC_POINT_PERCENT(10000, 65),
};
static const struct pwm_tc_point pwm_tc_channel_3_sweep_points[] = {
PWM_TC_POINT_PERCENT(800, 15),
PWM_TC_POINT_PERCENT(1800, 35),
PWM_TC_POINT_PERCENT(3200, 55),
};
static const struct pwm_tc_point pwm_tc_channel_3_fixed_points[] = {
PWM_TC_POINT_PERCENT(6000, 30),
};
static const struct pwm_tc_point pwm_tc_channel_4_sweep_points[] = {
PWM_TC_POINT_PERCENT(1200, 25),
PWM_TC_POINT_PERCENT(2400, 50),
PWM_TC_POINT_PERCENT(4800, 75),
};
static const struct pwm_tc_point pwm_tc_channel_4_fixed_points[] = {
PWM_TC_POINT_PERCENT(8000, 70),
};
/*
* Group 1 channel behavior
*
* Channels in a group run concurrently. Each channel selects its own output
* mode, point table, and step interval in milliseconds.
*/
static const struct pwm_tc_channel pwm_tc_group_1_channels[] = {
PWM_TC_CHANNEL_CONFIG(PWM_TC_CFG_CHANNEL_1_ENABLED,
PWM_TC_CFG_CHANNEL_1_DEVICE_NAME,
PWM_TC_CFG_CHANNEL_1_NUMBER,
PWM_TC_MODE_SWEEP_LOOP,
pwm_tc_channel_1_sweep_points,
200U,
PWM_TC_CFG_CHANNEL_1_READBACK_TOLERANCE),
PWM_TC_CHANNEL_CONFIG(PWM_TC_CFG_CHANNEL_2_ENABLED,
PWM_TC_CFG_CHANNEL_2_DEVICE_NAME,
PWM_TC_CFG_CHANNEL_2_NUMBER,
PWM_TC_MODE_FIXED,
pwm_tc_channel_2_fixed_points,
0U,
PWM_TC_CFG_CHANNEL_2_READBACK_TOLERANCE),
PWM_TC_CHANNEL_CONFIG(PWM_TC_CFG_CHANNEL_3_ENABLED,
PWM_TC_CFG_CHANNEL_3_DEVICE_NAME,
PWM_TC_CFG_CHANNEL_3_NUMBER,
PWM_TC_MODE_SWEEP_ONCE,
pwm_tc_channel_3_sweep_points,
250U,
PWM_TC_CFG_CHANNEL_3_READBACK_TOLERANCE),
PWM_TC_CHANNEL_CONFIG(PWM_TC_CFG_CHANNEL_4_ENABLED,
PWM_TC_CFG_CHANNEL_4_DEVICE_NAME,
PWM_TC_CFG_CHANNEL_4_NUMBER,
PWM_TC_MODE_FIXED,
pwm_tc_channel_4_fixed_points,
0U,
PWM_TC_CFG_CHANNEL_4_READBACK_TOLERANCE),
};
/* Group 2 channel behavior */
static const struct pwm_tc_channel pwm_tc_group_2_channels[] = {
PWM_TC_CHANNEL_CONFIG(PWM_TC_CFG_CHANNEL_1_ENABLED,
PWM_TC_CFG_CHANNEL_1_DEVICE_NAME,
PWM_TC_CFG_CHANNEL_1_NUMBER,
PWM_TC_MODE_SWEEP_LOOP,
pwm_tc_channel_1_sweep_points,
200U,
PWM_TC_CFG_CHANNEL_1_READBACK_TOLERANCE),
PWM_TC_CHANNEL_CONFIG(PWM_TC_CFG_CHANNEL_2_ENABLED,
PWM_TC_CFG_CHANNEL_2_DEVICE_NAME,
PWM_TC_CFG_CHANNEL_2_NUMBER,
PWM_TC_MODE_SWEEP_ONCE,
pwm_tc_channel_2_sweep_points,
300U,
PWM_TC_CFG_CHANNEL_2_READBACK_TOLERANCE),
PWM_TC_CHANNEL_CONFIG(PWM_TC_CFG_CHANNEL_3_ENABLED,
PWM_TC_CFG_CHANNEL_3_DEVICE_NAME,
PWM_TC_CFG_CHANNEL_3_NUMBER,
PWM_TC_MODE_FIXED,
pwm_tc_channel_3_fixed_points,
0U,
PWM_TC_CFG_CHANNEL_3_READBACK_TOLERANCE),
PWM_TC_CHANNEL_CONFIG(PWM_TC_CFG_CHANNEL_4_ENABLED,
PWM_TC_CFG_CHANNEL_4_DEVICE_NAME,
PWM_TC_CFG_CHANNEL_4_NUMBER,
PWM_TC_MODE_SWEEP_LOOP,
pwm_tc_channel_4_sweep_points,
350U,
PWM_TC_CFG_CHANNEL_4_READBACK_TOLERANCE),
};
/* Test group list; groups run in array order. */
static const struct pwm_tc_group pwm_tc_groups[] = {
{
"mixed-output-loop",
pwm_tc_group_1_channels,
PWM_TC_ARRAY_SIZE(pwm_tc_group_1_channels),
PWM_TC_CFG_GROUP_1_DURATION_MS,
},
{
"mixed-output-sweep",
pwm_tc_group_2_channels,
PWM_TC_ARRAY_SIZE(pwm_tc_group_2_channels),
PWM_TC_CFG_GROUP_2_DURATION_MS,
},
};
#define PWM_TC_GROUPS pwm_tc_groups
#define PWM_TC_GROUP_COUNT PWM_TC_ARRAY_SIZE(pwm_tc_groups)
#endif /* __PWM_TC_CONFIG_H__ */
+1
View File
@@ -16,6 +16,7 @@ menu "RT-Thread Utestcases"
rsource "../../../components/drivers/core/utest/Kconfig"
rsource "../../../components/drivers/audio/utest/Kconfig"
rsource "../../../components/drivers/ipc/utest/Kconfig"
rsource "../../../components/drivers/misc/utest/Kconfig"
rsource "../../../components/drivers/pin/utest/Kconfig"
rsource "../../../components/drivers/serial/utest/Kconfig"
rsource "../../../components/drivers/smp_call/utest/Kconfig"