Skip to content

Commit 09d5b9d

Browse files
nordic-pikrkartben
authored andcommitted
tests: pwm: pwm_gpio_loopback: add nrf platforms
Add Nordic platforms and rename the defines to avoid redefining a nrf driver internal symbols Signed-off-by: Piotr Krzyzanowski <[email protected]>
1 parent 18f02a7 commit 09d5b9d

File tree

4 files changed

+97
-13
lines changed

4 files changed

+97
-13
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Test requires wire connection between:
6+
* - PWM130 OUT[0] at P0.00 <-> GPIO input at P0.01
7+
* - PWM120 OUT[0] at P7.00 <-> GPIO input at P1.09
8+
* - PWM120 OUT[1] at P7.01 <-> GPIO input at P1.05
9+
*/
10+
11+
/ {
12+
zephyr,user {
13+
pwms = <&pwm130 0 160000 PWM_POLARITY_NORMAL>,
14+
<&pwm120 0 80000 PWM_POLARITY_NORMAL>,
15+
<&pwm120 1 80000 PWM_POLARITY_NORMAL>;
16+
gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>,
17+
<&gpio1 9 GPIO_ACTIVE_HIGH>,
18+
<&gpio1 5 GPIO_ACTIVE_HIGH>;
19+
};
20+
};
21+
22+
&pinctrl {
23+
pwm130_default: pwm130_default {
24+
group1 {
25+
psels = <NRF_PSEL(PWM_OUT0, 0, 0)>;
26+
};
27+
};
28+
29+
pwm130_sleep: pwm130_sleep {
30+
group1 {
31+
psels = <NRF_PSEL(PWM_OUT0, 0, 0)>;
32+
low-power-enable;
33+
};
34+
};
35+
36+
pwm120_default: pwm120_default {
37+
group1 {
38+
psels = <NRF_PSEL(PWM_OUT0, 7, 0)>,
39+
<NRF_PSEL(PWM_OUT1, 7, 1)>;
40+
};
41+
};
42+
pwm120_sleep: pwm120_sleep {
43+
group1 {
44+
psels = <NRF_PSEL(PWM_OUT0, 7, 0)>,
45+
<NRF_PSEL(PWM_OUT1, 7, 1)>;
46+
low-power-enable;
47+
};
48+
};
49+
};
50+
51+
&gpio1 {
52+
status = "okay";
53+
};
54+
55+
&pwm120 {
56+
status = "okay";
57+
pinctrl-0 = <&pwm120_default>;
58+
pinctrl-1 = <&pwm120_sleep>;
59+
pinctrl-names = "default", "sleep";
60+
memory-regions = <&dma_fast_region>;
61+
};
62+
63+
&dma_fast_region {
64+
status = "okay";
65+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Test requires jumper between:
6+
* - PWM20 OUT[0] at P1.10 <-> GPIO input at P1.11
7+
*/
8+
9+
/ {
10+
zephyr,user {
11+
pwms = <&pwm20 0 160000 PWM_POLARITY_NORMAL>;
12+
gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>;
13+
};
14+
};

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222

2323
static struct gpio_callback gpio_cb;
2424

25-
#define PWM_COUNT DT_PROP_LEN(DT_PATH(zephyr_user), pwms)
26-
#define PWM_CONFIG_ENTRY(idx, node_id) PWM_DT_SPEC_GET_BY_IDX(node_id, idx)
27-
#define PWM_CONFIG_ARRAY(node_id) \
25+
#define TEST_PWM_COUNT DT_PROP_LEN(DT_PATH(zephyr_user), pwms)
26+
#define TEST_PWM_CONFIG_ENTRY(idx, node_id) PWM_DT_SPEC_GET_BY_IDX(node_id, idx)
27+
#define TEST_PWM_CONFIG_ARRAY(node_id) \
2828
{ \
29-
LISTIFY(PWM_COUNT, PWM_CONFIG_ENTRY, (,), node_id) \
29+
LISTIFY(TEST_PWM_COUNT, TEST_PWM_CONFIG_ENTRY, (,), node_id) \
3030
}
3131

32-
#define GPIO_COUNT DT_PROP_LEN(DT_PATH(zephyr_user), gpios)
33-
#define GPIO_CONFIG_ENTRY(idx, node_id) GPIO_DT_SPEC_GET_BY_IDX(node_id, gpios, idx)
34-
#define GPIO_CONFIG_ARRAY(node_id) \
32+
#define TEST_GPIO_COUNT DT_PROP_LEN(DT_PATH(zephyr_user), gpios)
33+
#define TEST_GPIO_CONFIG_ENTRY(idx, node_id) GPIO_DT_SPEC_GET_BY_IDX(node_id, gpios, idx)
34+
#define TEST_GPIO_CONFIG_ARRAY(node_id) \
3535
{ \
36-
LISTIFY(GPIO_COUNT, GPIO_CONFIG_ENTRY, (,), node_id) \
36+
LISTIFY(TEST_GPIO_COUNT, TEST_GPIO_CONFIG_ENTRY, (,), node_id) \
3737
}
3838

39-
static const struct pwm_dt_spec pwms_dt[] = PWM_CONFIG_ARRAY(DT_PATH(zephyr_user));
40-
static const struct gpio_dt_spec gpios_dt[] = GPIO_CONFIG_ARRAY(DT_PATH(zephyr_user));
39+
static const struct pwm_dt_spec pwms_dt[] = TEST_PWM_CONFIG_ARRAY(DT_PATH(zephyr_user));
40+
static const struct gpio_dt_spec gpios_dt[] = TEST_GPIO_CONFIG_ARRAY(DT_PATH(zephyr_user));
4141

4242
static struct test_context {
4343
uint32_t last_edge_time;
@@ -218,7 +218,7 @@ static void test_run(const struct pwm_dt_spec *pwm_dt, const struct gpio_dt_spec
218218

219219
ZTEST(pwm_gpio_loopback, test_pwm)
220220
{
221-
for (int i = 0; i < PWM_COUNT; i++) {
221+
for (int i = 0; i < TEST_PWM_COUNT; i++) {
222222
zassert_true(device_is_ready(pwms_dt[i].dev), "PWM device is not ready");
223223
zassert_true(device_is_ready(gpios_dt[i].port), "GPIO device is not ready");
224224

@@ -238,15 +238,15 @@ ZTEST(pwm_gpio_loopback, test_pwm)
238238

239239
ZTEST(pwm_gpio_loopback, test_pwm_cross)
240240
{
241-
for (int i = 0; i < PWM_COUNT; i++) {
241+
for (int i = 0; i < TEST_PWM_COUNT; i++) {
242242
/* Test case: [Duty: 40%] */
243243
test_run(&pwms_dt[i], &gpios_dt[i], 40, true);
244244
}
245245

246246
/* Set all channels and check if they retain the original
247247
* configuration without calling pwm_set again
248248
*/
249-
for (int i = 0; i < PWM_COUNT; i++) {
249+
for (int i = 0; i < TEST_PWM_COUNT; i++) {
250250
test_run(&pwms_dt[i], &gpios_dt[i], 40, false);
251251
}
252252
}

tests/drivers/pwm/pwm_gpio_loopback/testcase.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ tests:
1515
- esp32c6_devkitc
1616
- esp32s2_saola
1717
- esp32s3_devkitm/esp32s3/procpu
18+
19+
drivers.pwm.gpio_loopback.nrf:
20+
platform_allow:
21+
- nrf54h20dk/nrf54h20/cpuapp
22+
- nrf54l15dk/nrf54l15/cpuapp

0 commit comments

Comments
 (0)