Skip to content

Commit 3e27f75

Browse files
committed
tests: drivers: pwm: Update PWM events test
Add COMPAREMATCH event testing and PPI trace debug option. Signed-off-by: Bartosz Miller <[email protected]>
1 parent 52ea3d7 commit 3e27f75

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

tests/drivers/pwm/pwm_events/boards/nrf54h20dk_nrf54h20_cpuapp.overlay

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ tst_timer: &timer131 {
1818
status = "okay";
1919
};
2020

21-
pwm_led: &led2 {
21+
pwm_led: &led3 {
22+
status = "okay";
23+
};
24+
25+
debug_pin: &led1 {
2226
status = "okay";
2327
};

tests/drivers/pwm/pwm_events/boards/nrf54l15dk_nrf54l15_cpuapp.overlay

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ tst_timer: &timer20 {
1616
status = "okay";
1717
};
1818

19-
pwm_led: &led2 {
19+
pwm_led: &led3 {
20+
status = "okay";
21+
};
22+
23+
debug_pin: &led1 {
2024
status = "okay";
2125
};

tests/drivers/pwm/pwm_events/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ tst_timer: &timer20 {
1616
status = "okay";
1717
};
1818

19-
pwm_led: &led2 {
19+
pwm_led: &led3 {
20+
status = "okay";
21+
};
22+
23+
debug_pin: &led1 {
2024
status = "okay";
2125
};

tests/drivers/pwm/pwm_events/boards/nrf54ls05dk_nrf54ls05b_cpuapp.overlay

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ tst_timer: &timer20 {
1919
pwm_led: &led0 {
2020
status = "okay";
2121
};
22+
23+
debug_pin: &led1 {
24+
status = "okay";
25+
};

tests/drivers/pwm/pwm_events/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ CONFIG_NRFX_TIMER=y
33
CONFIG_NRFX_GPPI=y
44

55
CONFIG_ZTEST=y
6+
7+
# Enable for debugging purposes only
8+
CONFIG_PPI_TRACE=n

tests/drivers/pwm/pwm_events/src/main.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
#include <nrfx_timer.h>
1111
#include <helpers/nrfx_gppi.h>
1212

13+
#include <debug/ppi_trace.h>
14+
1315
#define PWM_OUTPUT_PIN NRF_DT_GPIOS_TO_PSEL(DT_NODELABEL(pwm_led), gpios)
1416

17+
#if defined(CONFIG_PPI_TRACE)
18+
#define DEBUG_PIN NRF_DT_GPIOS_TO_PSEL(DT_NODELABEL(debug_pin), gpios)
19+
#endif
20+
1521
#define SLEEP_TIME_MS 500
1622

1723
struct pwm_events_fixture {
@@ -30,6 +36,7 @@ static void configure_pwm(nrfx_pwm_t *pwm)
3036
NRF_PWM_PIN_NOT_CONNECTED, NRF_PWM_PIN_NOT_CONNECTED);
3137

3238
pwm_config.count_mode = NRF_PWM_MODE_UP_AND_DOWN;
39+
pwm_config.top_value = 0x1000;
3340

3441
zassert_ok(nrfx_pwm_init(pwm, &pwm_config, NULL, NULL), "NRFX PWM init failed\n");
3542
}
@@ -72,11 +79,27 @@ static void run_pwm_event_test_case(struct pwm_events_fixture *fixture,
7279
uint32_t pwm_event_address;
7380
uint32_t timer_cc_before, timer_cc_after;
7481

82+
#if defined(CONFIG_PPI_TRACE)
83+
void *handle;
84+
#endif
85+
7586
pwm_event_address = nrf_pwm_event_address_get(fixture->pwm->p_reg, tested_pwm_event);
7687
setup_dppi_connection(&fixture->gppi_handle, fixture->domain_id,
7788
fixture->timer_task_address, pwm_event_address);
78-
7989
nrf_pwm_event_clear(fixture->pwm->p_reg, tested_pwm_event);
90+
91+
#if defined(CONFIG_PPI_TRACE)
92+
/*
93+
* Note that configuring PPI trace
94+
* will break DPPI connection to the timer.
95+
* Timer will not count events
96+
*/
97+
handle = ppi_trace_config(DEBUG_PIN, pwm_event_address);
98+
zassert_not_null(handle, "PPI trace configuration failed\n");
99+
ppi_trace_enable(handle);
100+
#endif
101+
102+
80103
timer_cc_before = nrfx_timer_capture(fixture->test_timer, NRF_TIMER_CC_CHANNEL0);
81104
nrfx_pwm_simple_playback(fixture->pwm, fixture->pwm_sequence, 1, NRFX_PWM_FLAG_STOP);
82105
k_msleep(SLEEP_TIME_MS);
@@ -89,6 +112,10 @@ static void run_pwm_event_test_case(struct pwm_events_fixture *fixture,
89112
nrf_pwm_event_clear(fixture->pwm->p_reg, tested_pwm_event);
90113
clear_dppi_connection(&fixture->gppi_handle, fixture->domain_id,
91114
fixture->timer_task_address, pwm_event_address);
115+
116+
#if defined(CONFIG_PPI_TRACE)
117+
ppi_trace_disable(handle);
118+
#endif
92119
}
93120

94121
ZTEST_F(pwm_events, test_pwm_stop_event)
@@ -117,12 +144,18 @@ ZTEST_F(pwm_events, test_pwm_loopsdone_event)
117144
run_pwm_event_test_case(fixture, NRF_PWM_EVENT_LOOPSDONE, 1, "LOOPSDONE");
118145
}
119146

147+
ZTEST_F(pwm_events, test_pwm_comparematch_event)
148+
{
149+
run_pwm_event_test_case(fixture, offsetof(NRF_PWM_Type, EVENTS_COMPAREMATCH[0]),
150+
fixture->pwm_sequence->length * 2, "COMPAREMATCH");
151+
}
152+
120153
static void *test_setup(void)
121154
{
122155
static struct pwm_events_fixture fixture;
123156
static nrfx_timer_t test_timer = NRFX_TIMER_INSTANCE(DT_REG_ADDR(DT_NODELABEL(tst_timer)));
124157
static nrfx_pwm_t pwm = NRFX_PWM_INSTANCE(DT_REG_ADDR(DT_NODELABEL(dut_pwm)));
125-
static nrf_pwm_values_common_t pwm_duty_cycle_values[] = {0x500, 0x600};
158+
static nrf_pwm_values_common_t pwm_duty_cycle_values[] = {0x500, 0x600, 0x500, 0x600};
126159
static nrf_pwm_sequence_t pwm_sequence = {.values = {pwm_duty_cycle_values},
127160
.length = ARRAY_SIZE(pwm_duty_cycle_values),
128161
.repeats = 0,

0 commit comments

Comments
 (0)