Skip to content

Commit 540e00d

Browse files
nordic-seglnordic-piks
authored andcommitted
tests: drivers: gpio: Add test for SWD and GPIO on the same pin
Add test that confirms that package pin where SWD interface is located, can be used as an ordinary GPIO. Signed-off-by: Sebastian Głąb <[email protected]>
1 parent bbed9cc commit 540e00d

File tree

7 files changed

+214
-0
lines changed

7 files changed

+214
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(gpio_swd)
11+
12+
FILE(GLOB app_sources src/main.c)
13+
target_sources(app PRIVATE ${app_sources})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This test was initially dedicated to nrf54ls05b which has SWD and GPIO shared on the same package pin:
2+
- SWDIO at P1.29,
3+
- SWDCLK at P1.30.
4+
5+
SWD functionality shall be disabled some time after the reset and package pin shall behave as an ordinary GPIO.
6+
Currently, this is blocked by lack of support in MDK - to be added in MDK 8.73.0.
7+
Missing implementation, details available in NRFX-8363.
8+
9+
Test checks that:
10+
- selected GPIO can be configured as input;
11+
- selected GPIO can be configured as output;
12+
- when pin is configured as output HIGH, reading state of the pin returns HIGH;
13+
- when pin is configured as output LOW, reading state of the pin returns LOW;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
/* Test requirements:
9+
* No other driver on out-gpios[n]
10+
*/
11+
zephyr,user {
12+
out-gpios = <&gpio1 8 GPIO_ACTIVE_HIGH>, <&gpio1 10 GPIO_ACTIVE_HIGH>,
13+
<&gpio2 8 GPIO_ACTIVE_HIGH>, <&gpio2 10 GPIO_ACTIVE_HIGH>;
14+
};
15+
};
16+
17+
&gpio1 {
18+
status = "okay";
19+
};
20+
21+
&gpio2 {
22+
status = "okay";
23+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
/* Test requirements:
9+
* No other driver on out-gpios[n]
10+
*/
11+
zephyr,user {
12+
out-gpios = <&gpio1 0 GPIO_ACTIVE_HIGH>, <&gpio1 31 GPIO_ACTIVE_HIGH>,
13+
<&gpio1 29 GPIO_ACTIVE_HIGH>, <&gpio1 30 GPIO_ACTIVE_HIGH>;
14+
};
15+
};
16+
17+
&gpio1 {
18+
status = "okay";
19+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_GPIO=y
2+
CONFIG_ZTEST=y
3+
CONFIG_LOG=y
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/logging/log.h>
8+
LOG_MODULE_REGISTER(gpio_swd, LOG_LEVEL_INF);
9+
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/drivers/gpio.h>
12+
#include <zephyr/ztest.h>
13+
14+
15+
#if !DT_NODE_HAS_PROP(DT_PATH(zephyr_user), out_gpios)
16+
#error "Unsupported board: out_gpios are not defined"
17+
#endif
18+
19+
const struct gpio_dt_spec out_pins[] = {
20+
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), out_gpios, GPIO_DT_SPEC_GET_BY_IDX, (,))
21+
};
22+
BUILD_ASSERT(ARRAY_SIZE(out_pins) > 0, "missing out pins");
23+
const uint8_t npins = ARRAY_SIZE(out_pins);
24+
25+
26+
/**
27+
* @brief Test if GPIOs can be configured as inputs.
28+
*/
29+
ZTEST(gpio_swd, test_configure_input)
30+
{
31+
uint8_t i;
32+
int rc;
33+
34+
for (i = 0; i < npins; i++) {
35+
rc = gpio_pin_configure_dt(&out_pins[i], GPIO_INPUT);
36+
zassert_equal(rc, 0, "[%d]: Port %s, pin %d, config GPIO_INPUT failed",
37+
i, out_pins[i].port->name, out_pins[i].pin);
38+
}
39+
}
40+
41+
/**
42+
* @brief Test if GPIOs can be configured as outputs.
43+
*/
44+
ZTEST(gpio_swd, test_configure_output)
45+
{
46+
uint8_t i;
47+
int rc;
48+
49+
for (i = 0; i < npins; i++) {
50+
rc = gpio_pin_configure_dt(&out_pins[i], GPIO_OUTPUT);
51+
zassert_equal(rc, 0, "[%d]: Port %s, pin %d, config GPIO_OUTPUT failed",
52+
i, out_pins[i].port->name, out_pins[i].pin);
53+
}
54+
}
55+
56+
/**
57+
* @brief Test if GPIOs configured as output can have its value set.
58+
*/
59+
ZTEST(gpio_swd, test_set_output)
60+
{
61+
uint8_t i;
62+
int rc;
63+
64+
for (i = 0; i < npins; i++) {
65+
rc = gpio_pin_configure_dt(&out_pins[i], GPIO_OUTPUT_HIGH);
66+
zassert_equal(rc, 0, "[%d]: Port %s, pin %d, config high failed",
67+
i, out_pins[i].port->name, out_pins[i].pin);
68+
rc = gpio_pin_get_dt(&out_pins[i]);
69+
zassert_equal(rc, 1, "[%d]: Port %s, pin %d is not high",
70+
i, out_pins[i].port->name, out_pins[i].pin);
71+
72+
rc = gpio_pin_configure_dt(&out_pins[i], GPIO_OUTPUT_LOW);
73+
zassert_equal(rc, 0, "[%d]: Port %s, pin %d, config low failed",
74+
i, out_pins[i].port->name, out_pins[i].pin);
75+
rc = gpio_pin_get_dt(&out_pins[i]);
76+
zassert_equal(rc, 0, "[%d]: Port %s, pin %d is not low",
77+
i, out_pins[i].port->name, out_pins[i].pin);
78+
}
79+
}
80+
81+
/**
82+
* @brief Test if GPIOs configured as output can have its value set.
83+
*/
84+
ZTEST(gpio_swd, test_set_output_after_5_seconds)
85+
{
86+
uint8_t i;
87+
int rc;
88+
89+
k_msleep(5000);
90+
for (i = 0; i < npins; i++) {
91+
rc = gpio_pin_configure_dt(&out_pins[i], GPIO_OUTPUT_HIGH);
92+
zassert_equal(rc, 0, "[%d]: Port %s, pin %d, config high failed",
93+
i, out_pins[i].port->name, out_pins[i].pin);
94+
rc = gpio_pin_get_dt(&out_pins[i]);
95+
zassert_equal(rc, 1, "[%d]: Port %s, pin %d is not high",
96+
i, out_pins[i].port->name, out_pins[i].pin);
97+
98+
rc = gpio_pin_configure_dt(&out_pins[i], GPIO_OUTPUT_LOW);
99+
zassert_equal(rc, 0, "[%d]: Port %s, pin %d, config low failed",
100+
i, out_pins[i].port->name, out_pins[i].pin);
101+
rc = gpio_pin_get_dt(&out_pins[i]);
102+
zassert_equal(rc, 0, "[%d]: Port %s, pin %d is not low",
103+
i, out_pins[i].port->name, out_pins[i].pin);
104+
}
105+
}
106+
107+
static void *suite_setup(void)
108+
{
109+
uint8_t i;
110+
111+
TC_PRINT("Test executed on %s\n", CONFIG_BOARD_TARGET);
112+
TC_PRINT("GPIO count: %d\n", npins);
113+
for (i = 0; i < npins; i++) {
114+
TC_PRINT("%d: Port %s, pin %d\n", i, out_pins[i].port->name, out_pins[i].pin);
115+
}
116+
TC_PRINT("===================================================================\n");
117+
118+
for (i = 0; i < npins; i++) {
119+
zassert_true(gpio_is_ready_dt(&out_pins[i]), "OUT[%d] is not ready", i);
120+
}
121+
122+
return NULL;
123+
}
124+
125+
ZTEST_SUITE(gpio_swd, NULL, suite_setup, NULL, NULL, NULL);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
common:
2+
tags:
3+
- drivers
4+
- gpio
5+
- ci_tests_drivers_gpio
6+
depends_on: gpio
7+
harness: ztest
8+
harness_config:
9+
fixture: gpio_loopback
10+
11+
tests:
12+
drivers.gpio.gpio_swd:
13+
platform_allow:
14+
- nrf54l15dk/nrf54l15/cpuapp
15+
- nrf54ls05dk/nrf54ls05b/cpuapp
16+
- [email protected]/nrf54ls05b/cpuapp
17+
integration_platforms:
18+
- nrf54ls05dk/nrf54ls05b/cpuapp

0 commit comments

Comments
 (0)