Skip to content

Commit aeecc3c

Browse files
ajf58kartben
authored andcommitted
tests: gpio_api_1pin: rpi_pico2: Support using external pulldowns
Extend gpio_api_1pin so that tests can require a test fixture to provide an external pulldown resistor to the board under test. Use the new test-gpio-external-pulldown device tree binding to define where that GPIO is, and, finally, add a device tree overlay for the Raspberry Pi Pico 2 board that defines where the pulldown provided by the fixture will be. Tested locally using `--fixture gpio_external_pull_down` when running Twister on the command line, or by creating and using a Hardware Map file, in combination with a modified Pico 2. Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
1 parent dae7787 commit aeecc3c

File tree

4 files changed

+58
-10
lines changed

4 files changed

+58
-10
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2024 Andrew Featherstone <andrew.featherstone@gmail.com>
5+
*/
6+
7+
/ {
8+
resources {
9+
compatible = "test-gpio-external-pulldown";
10+
/* Choice of pin on the header is arbitrary. */
11+
gpios = <&pico_header 15 GPIO_ACTIVE_HIGH>;
12+
};
13+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) 2024 Andrew Featherstone <andrew.featherstone@gmail.com>
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: |
8+
This binding provides resources required to build and run the
9+
tests/drivers/gpio/gpio_api_1pin test in Zephyr on certain hardware.
10+
11+
compatible: "test-gpio-external-pulldown"
12+
13+
properties:
14+
gpios:
15+
type: phandle-array
16+
required: true
17+
description: |
18+
Identity of a GPIO that will be configured as both an output and input.

tests/drivers/gpio/gpio_api_1pin/src/test_gpio_api.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@
1111
#include <zephyr/drivers/gpio.h>
1212
#include <zephyr/ztest.h>
1313

14-
#if DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
15-
#define TEST_NODE DT_GPIO_CTLR(DT_ALIAS(led0), gpios)
16-
#define TEST_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios)
17-
#define TEST_PIN_DTS_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
14+
/* If possible, use a dedicated GPIO with an external pulldown resistor.
15+
* Otherwise, fallback to repurposing led0 as a GPIO. The latter won't always
16+
* work as expected when reconfigured as an input.
17+
*/
18+
#if DT_NODE_HAS_STATUS(DT_INST(0, test_gpio_external_pulldown), okay)
19+
#define TEST_NODE DT_GPIO_CTLR(DT_INST(0, test_gpio_external_pulldown), gpios)
20+
#define TEST_PIN DT_GPIO_PIN(DT_INST(0, test_gpio_external_pulldown), gpios)
21+
#define TEST_PIN_DTS_FLAGS DT_GPIO_FLAGS(DT_INST(0, test_gpio_external_pulldown), gpios)
22+
#elif DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
23+
#define TEST_NODE DT_GPIO_CTLR(DT_ALIAS(led0), gpios)
24+
#define TEST_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios)
25+
#define TEST_PIN_DTS_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
1826
#else
1927
#error Unsupported board
2028
#endif

tests/drivers/gpio/gpio_api_1pin/testcase.yaml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
common:
2+
tags:
3+
- drivers
4+
- gpio
5+
depends_on: gpio
6+
min_flash: 48
17
tests:
28
drivers.gpio.1pin:
3-
tags:
4-
- drivers
5-
- gpio
6-
depends_on: gpio
7-
min_flash: 48
9+
filter: >
10+
dt_enabled_alias_with_parent_compat("led0", "gpio-leds")
11+
and not dt_compat_enabled("test-gpio-external-pulldown")
812
# Fix exclude when we can exclude just sim run
913
platform_exclude:
1014
- mps2/an385
1115
- mps2/an521/cpu0
1216
- neorv32
13-
filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds")
1417
drivers.gpio.1pin.aw9523b:
1518
tags:
1619
- drivers
@@ -27,3 +30,9 @@ tests:
2730
dt_compat_enabled("arduino-header-r3")
2831
extra_dtc_overlay_files:
2932
- "boards/aw9523b_on_arduino_header.overlay"
33+
drivers.gpio.1pin.external_pull_down:
34+
# For testing boards that require a test fixture that provides a pulldown
35+
# resistor on the GPIO used for the test.
36+
filter: dt_compat_enabled("test-gpio-external-pulldown")
37+
harness_config:
38+
fixture: gpio_external_pull_down

0 commit comments

Comments
 (0)