Skip to content

Commit ff60bec

Browse files
nordic-baminordic-piks
authored andcommitted
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 eef45c3 commit ff60bec

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-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: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
#include <nrfx_pwm.h>
1010
#include <nrfx_timer.h>
1111
#include <helpers/nrfx_gppi.h>
12+
#include <debug/ppi_trace.h>
1213

1314
#define PWM_OUTPUT_PIN NRF_DT_GPIOS_TO_PSEL(DT_NODELABEL(pwm_led), gpios)
1415

16+
#if defined(CONFIG_PPI_TRACE)
17+
#define DEBUG_PIN NRF_DT_GPIOS_TO_PSEL(DT_NODELABEL(debug_pin), gpios)
18+
#endif
19+
1520
#define SLEEP_TIME_MS 500
1621

1722
struct pwm_events_fixture {
@@ -30,6 +35,7 @@ static void configure_pwm(nrfx_pwm_t *pwm)
3035
NRF_PWM_PIN_NOT_CONNECTED, NRF_PWM_PIN_NOT_CONNECTED);
3136

3237
pwm_config.count_mode = NRF_PWM_MODE_UP_AND_DOWN;
38+
pwm_config.top_value = 0x1000;
3339

3440
zassert_ok(nrfx_pwm_init(pwm, &pwm_config, NULL, NULL), "NRFX PWM init failed\n");
3541
}
@@ -72,11 +78,27 @@ static void run_pwm_event_test_case(struct pwm_events_fixture *fixture,
7278
uint32_t pwm_event_address;
7379
uint32_t timer_cc_before, timer_cc_after;
7480

81+
#if defined(CONFIG_PPI_TRACE)
82+
void *handle;
83+
#endif
84+
7585
pwm_event_address = nrf_pwm_event_address_get(fixture->pwm->p_reg, tested_pwm_event);
7686
setup_dppi_connection(&fixture->gppi_handle, fixture->domain_id,
7787
fixture->timer_task_address, pwm_event_address);
78-
7988
nrf_pwm_event_clear(fixture->pwm->p_reg, tested_pwm_event);
89+
90+
#if defined(CONFIG_PPI_TRACE)
91+
/*
92+
* Note that configuring PPI trace
93+
* will break DPPI connection to the timer.
94+
* Timer will not count events
95+
*/
96+
handle = ppi_trace_config(DEBUG_PIN, pwm_event_address);
97+
zassert_not_null(handle, "PPI trace configuration failed\n");
98+
ppi_trace_enable(handle);
99+
#endif
100+
101+
80102
timer_cc_before = nrfx_timer_capture(fixture->test_timer, NRF_TIMER_CC_CHANNEL0);
81103
nrfx_pwm_simple_playback(fixture->pwm, fixture->pwm_sequence, 1, NRFX_PWM_FLAG_STOP);
82104
k_msleep(SLEEP_TIME_MS);
@@ -89,6 +111,10 @@ static void run_pwm_event_test_case(struct pwm_events_fixture *fixture,
89111
nrf_pwm_event_clear(fixture->pwm->p_reg, tested_pwm_event);
90112
clear_dppi_connection(&fixture->gppi_handle, fixture->domain_id,
91113
fixture->timer_task_address, pwm_event_address);
114+
115+
#if defined(CONFIG_PPI_TRACE)
116+
ppi_trace_disable(handle);
117+
#endif
92118
}
93119

94120
ZTEST_F(pwm_events, test_pwm_stop_event)
@@ -117,12 +143,18 @@ ZTEST_F(pwm_events, test_pwm_loopsdone_event)
117143
run_pwm_event_test_case(fixture, NRF_PWM_EVENT_LOOPSDONE, 1, "LOOPSDONE");
118144
}
119145

146+
ZTEST_F(pwm_events, test_pwm_comparematch_event)
147+
{
148+
run_pwm_event_test_case(fixture, offsetof(NRF_PWM_Type, EVENTS_COMPAREMATCH[0]),
149+
fixture->pwm_sequence->length * 2, "COMPAREMATCH");
150+
}
151+
120152
static void *test_setup(void)
121153
{
122154
static struct pwm_events_fixture fixture;
123155
static nrfx_timer_t test_timer = NRFX_TIMER_INSTANCE(DT_REG_ADDR(DT_NODELABEL(tst_timer)));
124156
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};
157+
static nrf_pwm_values_common_t pwm_duty_cycle_values[] = {0x500, 0x600, 0x500, 0x600};
126158
static nrf_pwm_sequence_t pwm_sequence = {.values = {pwm_duty_cycle_values},
127159
.length = ARRAY_SIZE(pwm_duty_cycle_values),
128160
.repeats = 0,

0 commit comments

Comments
 (0)