Skip to content

Commit

Permalink
tests: gpio_api_1pin: rpi_pico2: Support using external pulldowns
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ajf58 committed Oct 8, 2024
1 parent 85e83e2 commit 4715202
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
13 changes: 13 additions & 0 deletions tests/drivers/gpio/gpio_api_1pin/boards/rpi_pico2.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2024 Andrew Featherstone <[email protected]>
*/

/ {
resources {
compatible = "test-gpio-external-pulldown";
/* Choice of pin on the header is arbitrary. */
gpios = <&pico_header 15 GPIO_ACTIVE_HIGH>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2024 Andrew Featherstone <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

description: |
This binding provides resources required to build and run the
tests/drivers/gpio/gpio_api_1pin test in Zephyr on certain hardware.
compatible: "test-gpio-external-pulldown"

properties:
gpios:
type: phandle-array
required: true
description: |
Identity of a GPIO that will be configured as both an output and input.
16 changes: 12 additions & 4 deletions tests/drivers/gpio/gpio_api_1pin/src/test_gpio_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/ztest.h>

#if DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
#define TEST_NODE DT_GPIO_CTLR(DT_ALIAS(led0), gpios)
#define TEST_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios)
#define TEST_PIN_DTS_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
/* If possible, use a dedicated GPIO with an external pulldown resistor.
* Otherwise, fallback to repurposing led0 as a GPIO. The latter won't always
* work as expected when reconfigured as an input.
*/
#if DT_NODE_HAS_STATUS(DT_INST(0, test_gpio_external_pulldown), okay)
#define TEST_NODE DT_GPIO_CTLR(DT_INST(0, test_gpio_external_pulldown), gpios)
#define TEST_PIN DT_GPIO_PIN(DT_INST(0, test_gpio_external_pulldown), gpios)
#define TEST_PIN_DTS_FLAGS DT_GPIO_FLAGS(DT_INST(0, test_gpio_external_pulldown), gpios)
#elif DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
#define TEST_NODE DT_GPIO_CTLR(DT_ALIAS(led0), gpios)
#define TEST_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios)
#define TEST_PIN_DTS_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
#else
#error Unsupported board
#endif
Expand Down
21 changes: 15 additions & 6 deletions tests/drivers/gpio/gpio_api_1pin/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
common:
tags:
- drivers
- gpio
depends_on: gpio
min_flash: 48
tests:
drivers.gpio.1pin:
tags:
- drivers
- gpio
depends_on: gpio
min_flash: 48
filter: >
dt_enabled_alias_with_parent_compat("led0", "gpio-leds")
and not dt_compat_enabled("test-gpio-external-pulldown")
# Fix exclude when we can exclude just sim run
platform_exclude:
- mps2/an385
- mps2/an521/cpu0
- neorv32
filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds")
drivers.gpio.1pin.external_pull_down:
# For testing boards that require a test fixture that provides a pulldown
# resistor on the GPIO used for the test.
filter: dt_compat_enabled("test-gpio-external-pulldown")
harness_config:
fixture: gpio_external_pull_down

0 comments on commit 4715202

Please sign in to comment.