Skip to content

Commit fb9267c

Browse files
nordic-seglrlubos
authored andcommitted
tests: drivers: pwm: gpio_loopback: Enable test on PWM120 instance
Check if fast PWM instance PWM120 is working correctly. Check that PWM signal can be generated on all four PWM channels. Signed-off-by: Sebastian Głąb <[email protected]> (cherry picked from commit 1346e2b)
1 parent 45453e8 commit fb9267c

File tree

8 files changed

+295
-16
lines changed

8 files changed

+295
-16
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
config TEST_PWM_PERIOD_USEC
8+
int "PWM period in microseconds"
9+
default 200000
10+
help
11+
Set PWM signal period to TEST_PWM_PERIOD_USEC microseconds.
12+
In the test, PWM pulse width will be set to half of this value.
13+
The maximum allowable PWM period value is limited by the hardware design.
14+
15+
source "Kconfig.zephyr"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/dt-bindings/pwm/pwm.h>
8+
#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>
9+
10+
/* Test requires wire connection between:
11+
* - PWM120 OUT[0] at P7.0
12+
* - GPIO input at P1.09
13+
*/
14+
15+
/ {
16+
pwm_to_gpio_loopback: pwm_to_gpio_loopback {
17+
compatible = "test-pwm-to-gpio-loopback";
18+
pwms = <&pwm120 0 0 PWM_POLARITY_NORMAL>;
19+
gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
20+
};
21+
};
22+
23+
&pinctrl {
24+
pwm_default: pwm_default {
25+
group1 {
26+
psels = <NRF_PSEL(PWM_OUT0, 7, 0)>;
27+
};
28+
};
29+
pwm_sleep: pwm_sleep {
30+
group1 {
31+
psels = <NRF_PSEL(PWM_OUT0, 7, 0)>;
32+
low-power-enable;
33+
};
34+
};
35+
};
36+
37+
&gpio1 {
38+
status = "okay";
39+
};
40+
41+
&pwm120 {
42+
status = "okay";
43+
pinctrl-0 = <&pwm_default>;
44+
pinctrl-1 = <&pwm_sleep>;
45+
pinctrl-names = "default", "sleep";
46+
memory-regions = <&dma_fast_region>;
47+
};
48+
49+
&dma_fast_region {
50+
status = "okay";
51+
};
52+
53+
&pwm130 {
54+
status = "disabled";
55+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/dt-bindings/pwm/pwm.h>
8+
#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>
9+
10+
/* Test requires wire connection between:
11+
* - PWM120 OUT[1] at P7.1
12+
* - GPIO input at P1.05
13+
*/
14+
15+
/ {
16+
pwm_to_gpio_loopback: pwm_to_gpio_loopback {
17+
compatible = "test-pwm-to-gpio-loopback";
18+
pwms = <&pwm120 1 0 PWM_POLARITY_NORMAL>;
19+
gpios = <&gpio1 5 GPIO_ACTIVE_HIGH>;
20+
};
21+
};
22+
23+
&pinctrl {
24+
pwm_default: pwm_default {
25+
group1 {
26+
psels = <NRF_PSEL(PWM_OUT1, 7, 1)>;
27+
};
28+
};
29+
pwm_sleep: pwm_sleep {
30+
group1 {
31+
psels = <NRF_PSEL(PWM_OUT1, 7, 1)>;
32+
low-power-enable;
33+
};
34+
};
35+
};
36+
37+
&gpio1 {
38+
status = "okay";
39+
};
40+
41+
&pwm120 {
42+
status = "okay";
43+
pinctrl-0 = <&pwm_default>;
44+
pinctrl-1 = <&pwm_sleep>;
45+
pinctrl-names = "default", "sleep";
46+
memory-regions = <&dma_fast_region>;
47+
};
48+
49+
&dma_fast_region {
50+
status = "okay";
51+
};
52+
53+
&pwm130 {
54+
status = "disabled";
55+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/dt-bindings/pwm/pwm.h>
8+
#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>
9+
10+
/* Test requires wire connection between:
11+
* - PWM120 OUT[2] at P7.6
12+
* - GPIO input at P1.06
13+
*/
14+
15+
/ {
16+
pwm_to_gpio_loopback: pwm_to_gpio_loopback {
17+
compatible = "test-pwm-to-gpio-loopback";
18+
pwms = <&pwm120 2 0 PWM_POLARITY_NORMAL>;
19+
gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>;
20+
};
21+
};
22+
23+
&pinctrl {
24+
pwm_default: pwm_default {
25+
group1 {
26+
psels = <NRF_PSEL(PWM_OUT2, 7, 6)>;
27+
};
28+
};
29+
pwm_sleep: pwm_sleep {
30+
group1 {
31+
psels = <NRF_PSEL(PWM_OUT2, 7, 6)>;
32+
low-power-enable;
33+
};
34+
};
35+
};
36+
37+
&gpio1 {
38+
status = "okay";
39+
};
40+
41+
&pwm120 {
42+
status = "okay";
43+
pinctrl-0 = <&pwm_default>;
44+
pinctrl-1 = <&pwm_sleep>;
45+
pinctrl-names = "default", "sleep";
46+
memory-regions = <&dma_fast_region>;
47+
};
48+
49+
&dma_fast_region {
50+
status = "okay";
51+
};
52+
53+
&pwm130 {
54+
status = "disabled";
55+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/dt-bindings/pwm/pwm.h>
8+
#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>
9+
10+
/* Test requires wire connection between:
11+
* - PWM120 OUT[3] at P7.7
12+
* - GPIO input at P1.08
13+
*/
14+
15+
/ {
16+
pwm_to_gpio_loopback: pwm_to_gpio_loopback {
17+
compatible = "test-pwm-to-gpio-loopback";
18+
pwms = <&pwm120 3 0 PWM_POLARITY_NORMAL>;
19+
gpios = <&gpio1 8 GPIO_ACTIVE_HIGH>;
20+
};
21+
};
22+
23+
&pinctrl {
24+
pwm_default: pwm_default {
25+
group1 {
26+
psels = <NRF_PSEL(PWM_OUT3, 7, 7)>;
27+
};
28+
};
29+
pwm_sleep: pwm_sleep {
30+
group1 {
31+
psels = <NRF_PSEL(PWM_OUT3, 7, 7)>;
32+
low-power-enable;
33+
};
34+
};
35+
};
36+
37+
&gpio1 {
38+
status = "okay";
39+
};
40+
41+
&pwm120 {
42+
status = "okay";
43+
pinctrl-0 = <&pwm_default>;
44+
pinctrl-1 = <&pwm_sleep>;
45+
pinctrl-names = "default", "sleep";
46+
memory-regions = <&dma_fast_region>;
47+
};
48+
49+
&dma_fast_region {
50+
status = "okay";
51+
};
52+
53+
&pwm130 {
54+
status = "disabled";
55+
};

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ static void *pwm_loopback_setup(void)
1818
k_object_access_grant(out.dev, k_current_get());
1919
k_object_access_grant(in.port, k_current_get());
2020

21+
TC_PRINT("Testing PWM device %s, channel %d\n", out.dev->name, out.channel);
22+
TC_PRINT("GPIO loopback at %s, pin %d\n", in.port->name, in.pin);
23+
TC_PRINT("===================================================================\n");
24+
2125
return NULL;
2226
}
2327

tests/drivers/pwm/gpio_loopback/src/test_pwm_to_gpio_loopback.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
#include "test_pwm_to_gpio_loopback.h"
1313

14-
#define TEST_PWM_PERIOD_USEC 200000
15-
#define TEST_PWM_PULSE_USEC 100000
16-
1714
#define NUMBER_OF_CYCLE_TO_CAPTURE 5
1815

1916
static struct gpio_callback pwm_input_cb_data;
@@ -56,14 +53,20 @@ static void test_capture(uint32_t period, uint32_t pulse, pwm_flags_t flags)
5653

5754
int err = 0;
5855

59-
TC_PRINT("Testing PWM capture @ %u/%u usec\n", pulse, period);
56+
TC_PRINT("Pulse/period: %u/%u usec\n", pulse, period);
6057

6158
get_test_devices(&out, &in);
6259

60+
/* clear edge counters */
61+
high = 0;
62+
low = 0;
63+
64+
/* configure and enable PWM */
6365
err = pwm_set(out.dev, out.channel, PWM_USEC(period), PWM_USEC(pulse),
6466
out.flags ^= (flags & PWM_POLARITY_MASK));
6567
zassert_equal(err, 0, "failed to set pwm output (err %d)", err);
6668

69+
/* configure and enable GPIOTE */
6770
err = gpio_pin_configure_dt(&in, GPIO_INPUT);
6871
zassert_equal(err, 0, "failed to configure input pin (err %d)", err);
6972

@@ -73,23 +76,22 @@ static void test_capture(uint32_t period, uint32_t pulse, pwm_flags_t flags)
7376
gpio_init_callback(&pwm_input_cb_data, pwm_input_captured_callback, BIT(in.pin));
7477
gpio_add_callback(in.port, &pwm_input_cb_data);
7578

76-
if (gpio_pin_get_dt(&in)) {
77-
high = 1;
78-
low = 0;
79-
} else {
80-
high = 0;
81-
low = 1;
82-
}
83-
84-
k_usleep(NUMBER_OF_CYCLE_TO_CAPTURE * period);
79+
/* NUMBER_OF_CYCLE_TO_CAPTURE periods plus 1/4 of period to catch the last edge */
80+
k_usleep((NUMBER_OF_CYCLE_TO_CAPTURE * period) + (period >> 2));
8581

8682
TC_PRINT("PWM output -high state counter: %d -low state counter: %d\n", high, low);
8783
zassert((high >= NUMBER_OF_CYCLE_TO_CAPTURE) && (low >= NUMBER_OF_CYCLE_TO_CAPTURE),
8884
"PWM not captured");
8985
}
9086

91-
ZTEST(pwm_loopback, test_pulse_capture)
87+
ZTEST(pwm_loopback, test_pwm_polarity_normal)
88+
{
89+
test_capture(CONFIG_TEST_PWM_PERIOD_USEC, (CONFIG_TEST_PWM_PERIOD_USEC >> 1),
90+
PWM_POLARITY_NORMAL);
91+
}
92+
93+
ZTEST(pwm_loopback, test_pwm_polarity_inverted)
9294
{
93-
test_capture(TEST_PWM_PERIOD_USEC, TEST_PWM_PULSE_USEC, PWM_POLARITY_NORMAL);
94-
test_capture(TEST_PWM_PERIOD_USEC, TEST_PWM_PULSE_USEC, PWM_POLARITY_INVERTED);
95+
test_capture(CONFIG_TEST_PWM_PERIOD_USEC, (CONFIG_TEST_PWM_PERIOD_USEC >> 1),
96+
PWM_POLARITY_INVERTED);
9597
}

tests/drivers/pwm/gpio_loopback/testcase.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,41 @@ tests:
1919
- nrf54h20dk/nrf54h20/cpuapp
2020
- nrf54l15dk/nrf54l15/cpuapp
2121
- nrf54l15pdk/nrf54l15/cpuapp
22+
23+
drivers.pwm.gpio_loopback.fast_p7_0:
24+
platform_allow:
25+
- nrf54h20dk/nrf54h20/cpuapp
26+
integration_platforms:
27+
- nrf54h20dk/nrf54h20/cpuapp
28+
extra_args:
29+
DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_fast_p7_0.overlay"
30+
CONFIG_TEST_PWM_PERIOD_USEC=10000
31+
32+
drivers.pwm.gpio_loopback.fast_p7_1:
33+
platform_allow:
34+
- nrf54h20dk/nrf54h20/cpuapp
35+
integration_platforms:
36+
- nrf54h20dk/nrf54h20/cpuapp
37+
extra_args:
38+
DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_fast_p7_1.overlay"
39+
CONFIG_TEST_PWM_PERIOD_USEC=10000
40+
41+
drivers.pwm.gpio_loopback.fast_p7_6:
42+
build_only: true
43+
platform_allow:
44+
- nrf54h20dk/nrf54h20/cpuapp
45+
integration_platforms:
46+
- nrf54h20dk/nrf54h20/cpuapp
47+
extra_args:
48+
DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_fast_p7_6.overlay"
49+
CONFIG_TEST_PWM_PERIOD_USEC=10000
50+
51+
drivers.pwm.gpio_loopback.fast_p7_7:
52+
build_only: true
53+
platform_allow:
54+
- nrf54h20dk/nrf54h20/cpuapp
55+
integration_platforms:
56+
- nrf54h20dk/nrf54h20/cpuapp
57+
extra_args:
58+
DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_fast_p7_7.overlay"
59+
CONFIG_TEST_PWM_PERIOD_USEC=10000

0 commit comments

Comments
 (0)