Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nrf fromtree] tests: pwm: pwm_gpio_loopback: add nrf platforms #2439

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/boards/espressif/wifi/socs/esp32c3_usb.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

&wifi {
status = "okay";
};
1 change: 1 addition & 0 deletions tests/drivers/adc/adc_api/socs/esp32c3_usb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_ADC_ASYNC=n
35 changes: 35 additions & 0 deletions tests/drivers/adc/adc_api/socs/esp32c3_usb.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 Wolter HV <[email protected]>
* Copyright (c) 2023 Benjamin Björnsson <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
zephyr,user {
/* adjust channel number according to pinmux in board.dts */
io-channels = <&adc0 0>, <&adc0 1>;
};
};

&adc0 {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";

channel@0 {
reg = <0>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,resolution = <12>;
};

channel@1 {
reg = <1>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,resolution = <12>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
&timer0 {
status = "okay";
};

&rtc {
slow-clk-src = <ESP32_RTC_SLOW_CLK_SRC_RC_FAST_D256>;
};
3 changes: 3 additions & 0 deletions tests/drivers/dma/chan_blen_transfer/socs/esp32c3_usb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_DMA_TRANSFER_CHANNEL_NR_0=5
CONFIG_DMA_TRANSFER_CHANNEL_NR_1=0
CONFIG_HEAP_MEM_POOL_SIZE=32768
11 changes: 11 additions & 0 deletions tests/drivers/dma/chan_blen_transfer/socs/esp32c3_usb.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

&dma {
status = "okay";
};

tst_dma0: &dma { };
2 changes: 2 additions & 0 deletions tests/drivers/dma/loop_transfer/socs/esp32c3_usb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_DMA_LOOP_TRANSFER_CHANNEL_NR=0
CONFIG_DMA_LOOP_TRANSFER_SIZE=4094
11 changes: 11 additions & 0 deletions tests/drivers/dma/loop_transfer/socs/esp32c3_usb.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

&dma {
status = "okay";
};

tst_dma0: &dma { };
1 change: 1 addition & 0 deletions tests/drivers/flash/common/socs/esp32c3_usb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_HEAP_MEM_POOL_SIZE=16384
13 changes: 13 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/socs/esp32c3_usb.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
resources {
compatible = "test-gpio-basic-api";
out-gpios = <&gpio0 4 0>;
in-gpios = <&gpio0 5 0>;
};
};
34 changes: 34 additions & 0 deletions tests/drivers/pwm/pwm_api/socs/esp32c3_usb.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*/

#include <zephyr/dt-bindings/pwm/pwm.h>

/ {
aliases {
pwm-0 = &ledc0;
};
};

&pinctrl {
ledc0_default: ledc0_default {
group1 {
pinmux = <LEDC_CH0_GPIO2>;
output-enable;
};
};
};

&ledc0 {
pinctrl-0 = <&ledc0_default>;
pinctrl-names = "default";
status = "okay";
#address-cells = <1>;
#size-cells = <0>;
channel0@0 {
reg = <0x0>;
timer = <0>;
};
};
8 changes: 8 additions & 0 deletions tests/drivers/pwm/pwm_gpio_loopback/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(pwm_gpio)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
29 changes: 29 additions & 0 deletions tests/drivers/pwm/pwm_gpio_loopback/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

mainmenu "PWM GPIO loopback test"

source "Kconfig.zephyr"

config SAMPLING_TIME
int "Sampling wait time (ms)"
default 50
help
Time to wait for PWM edge sampling, in milliseconds.

config SKIP_EDGE_NUM
int "Number of edges to skip before sampling PWM"
default 2
help
Number of PWM edges to skip before starting sampling.
This parameter improves measurement precision as there can be significant
latency in the first sampled edge.

config ALLOWED_DEVIATION
int "Allowed deviation (%) for PWM timing checks"
default 5
range 0 100
help
Maximum allowed deviation (%) from the programmed values for the test to be
considered a PASS. For example, if set to 5, the measured period or duty cycle
can deviate by up to 5% from the programmed values for the test to pass.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*
* Test requires wire connection between:
* - PWM130 OUT[0] at P0.00 <-> GPIO input at P0.01
* - PWM120 OUT[0] at P7.00 <-> GPIO input at P1.09
* - PWM120 OUT[1] at P7.01 <-> GPIO input at P1.05
*/

/ {
zephyr,user {
pwms = <&pwm130 0 160000 PWM_POLARITY_NORMAL>,
<&pwm120 0 80000 PWM_POLARITY_NORMAL>,
<&pwm120 1 80000 PWM_POLARITY_NORMAL>;
gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>,
<&gpio1 9 GPIO_ACTIVE_HIGH>,
<&gpio1 5 GPIO_ACTIVE_HIGH>;
};
};

&pinctrl {
pwm130_default: pwm130_default {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 0, 0)>;
};
};

pwm130_sleep: pwm130_sleep {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 0, 0)>;
low-power-enable;
};
};

pwm120_default: pwm120_default {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 7, 0)>,
<NRF_PSEL(PWM_OUT1, 7, 1)>;
};
};
pwm120_sleep: pwm120_sleep {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 7, 0)>,
<NRF_PSEL(PWM_OUT1, 7, 1)>;
low-power-enable;
};
};
};

&gpio1 {
status = "okay";
};

&pwm120 {
status = "okay";
pinctrl-0 = <&pwm120_default>;
pinctrl-1 = <&pwm120_sleep>;
pinctrl-names = "default", "sleep";
memory-regions = <&dma_fast_region>;
};

&dma_fast_region {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*
* Test requires jumper between:
* - PWM20 OUT[0] at P1.10 <-> GPIO input at P1.11
*/

/ {
zephyr,user {
pwms = <&pwm20 0 160000 PWM_POLARITY_NORMAL>;
gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>;
};
};
2 changes: 2 additions & 0 deletions tests/drivers/pwm/pwm_gpio_loopback/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_PWM=y
CONFIG_ZTEST=y
66 changes: 66 additions & 0 deletions tests/drivers/pwm/pwm_gpio_loopback/socs/esp32_procpu.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
*/

#include <zephyr/dt-bindings/pwm/pwm.h>
#include <zephyr/dt-bindings/gpio/gpio.h>
#include <zephyr/dt-bindings/gpio/espressif-esp32-gpio.h>

/ {
zephyr,user {
/* GPIO input pins order must match PWM pinctrl config */
gpios = <&gpio0 2 ESP32_GPIO_PIN_OUT_EN>,
<&gpio0 3 ESP32_GPIO_PIN_OUT_EN>,
<&gpio0 4 ESP32_GPIO_PIN_OUT_EN>,
<&gpio0 5 ESP32_GPIO_PIN_OUT_EN>;

pwms = <&ledc0 0 160000 PWM_POLARITY_NORMAL>,
<&ledc0 5 80000 PWM_POLARITY_INVERTED>,
<&ledc0 9 1000000 PWM_POLARITY_NORMAL>,
<&ledc0 10 1000000 PWM_POLARITY_INVERTED>;
};
};

&pinctrl {
ledc0_default: ledc0_default {
group1 {
pinmux = <LEDC_CH0_GPIO2>,
<LEDC_CH5_GPIO3>,
<LEDC_CH9_GPIO4>,
<LEDC_CH10_GPIO5>;
input-enable;
};
};
};

&ledc0 {
pinctrl-0 = <&ledc0_default>;
pinctrl-names = "default";
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

channel0@0 {
reg = <0x0>;
timer = <0>;
};

channel5@5 {
reg = <0x5>;
timer = <1>;
};

/* HS channel */
channel9@9 {
reg = <0x9>;
timer = <0>;
};

/* share same timer with ch9 */
channel10@a {
reg = <0xa>;
timer = <0>;
};
};
48 changes: 48 additions & 0 deletions tests/drivers/pwm/pwm_gpio_loopback/socs/esp32c2.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*/

#include <zephyr/dt-bindings/pwm/pwm.h>
#include <zephyr/dt-bindings/gpio/gpio.h>
#include <zephyr/dt-bindings/gpio/espressif-esp32-gpio.h>

/ {
zephyr,user {
/* GPIO input pins order must match PWM pinctrl config */
gpios = <&gpio0 2 ESP32_GPIO_PIN_OUT_EN>,
<&gpio0 3 ESP32_GPIO_PIN_OUT_EN>;

pwms = <&ledc0 0 160000 PWM_POLARITY_NORMAL>,
<&ledc0 5 80000 PWM_POLARITY_INVERTED>;
};
};

&pinctrl {
ledc0_default: ledc0_default {
group1 {
pinmux = <LEDC_CH0_GPIO2>,
<LEDC_CH5_GPIO3>;
input-enable;
};
};
};

&ledc0 {
pinctrl-0 = <&ledc0_default>;
pinctrl-names = "default";
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

channel0@0 {
reg = <0x0>;
timer = <0>;
};

channel5@5 {
reg = <0x5>;
timer = <1>;
};
};
Loading
Loading