Skip to content

Commit 2d4a119

Browse files
KozhinovAlexandercfriedt
authored andcommitted
tests: drivers: interrupt_controller: add new test for STM32 EXTI
add exti driver tests for stm32 platform Signed-off-by: Alexander Kozhinov <[email protected]>
1 parent 6303018 commit 2d4a119

File tree

10 files changed

+245
-0
lines changed

10 files changed

+245
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2025 Alexander Kozhinov <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
8+
project(test_intc_exti_stm32)
9+
10+
target_sources(app PRIVATE src/main.c)
11+
12+
target_include_directories(app PRIVATE inc)
13+
14+
target_compile_definitions(app PRIVATE _POSIX_C_SOURCE=200809L)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2025 Alexander Kozhinov <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
source "Kconfig.zephyr"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Alexander Kozhinov <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
/**
9+
* NOTE: For this test, a _configurable_ EXTI line that doesn't conflict
10+
* with other users should be specified, along with the associated IRQn.
11+
*
12+
* On most STM32 series so far, EXTI line 16 is configurable, generates an
13+
* interrupt on IRQn 1, and corresponds to events raised by the PVD. Since
14+
* the PVD is not available in Zephyr yet, there is no risk of conflict.
15+
*
16+
* This overlay will be used by default and configures EXTI line 16 with
17+
* IRQn 1 for use by the test, which should work on most hardware. Series
18+
* where this does not apply can define their own overlay to override it.
19+
*/
20+
21+
/ {
22+
resources {
23+
compatible = "test-st-stm32-exti";
24+
exti-line-nr = <16>;
25+
exti-line-irq-nr = <1>;
26+
exti-line-irq-prio = <0>;
27+
status = "okay";
28+
};
29+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2025 Alexander Kozhinov <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
/ {
9+
resources {
10+
exti-line-nr = <34>;
11+
};
12+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2025 Alexander Kozhinov <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
/ {
9+
resources {
10+
exti-line-nr = <16>;
11+
exti-line-irq-nr = <0>;
12+
};
13+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2025 Alexander Kozhinov <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
/ {
9+
resources {
10+
exti-line-nr = <66>;
11+
exti-line-irq-nr = <0>;
12+
};
13+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright (c) 2025 Alexander Kozhinov <[email protected]>
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/interrupt_controller/intc_exti_stm32 test in Zephyr.
10+
11+
compatible: "test-st-stm32-exti"
12+
13+
properties:
14+
15+
exti-line-nr:
16+
type: int
17+
required: true
18+
description: |
19+
Number of the EXTI line to use for the test.
20+
21+
exti-line-irq-nr:
22+
type: int
23+
required: true
24+
description: |
25+
IRQn of the interrupt triggered by the specified EXTI line.
26+
27+
exti-line-irq-prio:
28+
type: int
29+
required: true
30+
description: |
31+
Priority of the interrupt triggered by the specified EXTI line.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2025 Alexander Kozhinov <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_EXTI_STM32=y
5+
CONFIG_ZTEST=y
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2025 Alexander Kozhinov <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
#include <zephyr/irq.h>
9+
#include <zephyr/init.h>
10+
#include <zephyr/device.h>
11+
#include <zephyr/kernel.h>
12+
#include <zephyr/sys/atomic.h>
13+
#include <zephyr/drivers/interrupt_controller/intc_exti_stm32.h>
14+
15+
16+
#define EXTI_DT_NODE DT_INST(0, st_stm32_exti)
17+
#define EXTI_NUM_LINES_TOTAL DT_PROP(EXTI_DT_NODE, num_lines)
18+
#define EXTI_NUM_LINES_GPIO DT_PROP(EXTI_DT_NODE, num_gpio_lines)
19+
20+
#define TEST_EXTI_LINE_NR DT_PROP(DT_INST(0, test_st_stm32_exti), exti_line_nr)
21+
#define TEST_EXTI_IRQ_NR DT_PROP(DT_INST(0, test_st_stm32_exti), exti_line_irq_nr)
22+
#define TEST_EXTI_IRQ_PRIO DT_PROP(DT_INST(0, test_st_stm32_exti), exti_line_irq_prio)
23+
24+
25+
BUILD_ASSERT(TEST_EXTI_LINE_NR < EXTI_NUM_LINES_TOTAL, "Invalid EXTI line number");
26+
27+
static atomic_t is_test_exti_isr_called;
28+
29+
static void test_exti_isr(void)
30+
{
31+
zassert_true(stm32_exti_is_pending(TEST_EXTI_LINE_NR));
32+
stm32_exti_clear_pending(TEST_EXTI_LINE_NR);
33+
34+
atomic_set(&is_test_exti_isr_called, true);
35+
}
36+
37+
ZTEST(intc_exti_stm32, test_sw_interrupt_rising_trigger)
38+
{
39+
int ret = 0;
40+
41+
ret = stm32_exti_enable(TEST_EXTI_LINE_NR,
42+
STM32_EXTI_TRIG_RISING,
43+
STM32_EXTI_MODE_IT);
44+
zassert_ok(ret, "Failed to enable EXTI line %d", TEST_EXTI_LINE_NR);
45+
46+
atomic_set(&is_test_exti_isr_called, false);
47+
48+
ret = stm32_exti_sw_interrupt(TEST_EXTI_LINE_NR);
49+
zassert_ok(ret, "Failed to fire SW interrupt on EXTI line %d",
50+
TEST_EXTI_LINE_NR);
51+
52+
zassert_equal(is_test_exti_isr_called, true,
53+
"ISR was not called for EXTI line %d", TEST_EXTI_LINE_NR);
54+
}
55+
56+
ZTEST(intc_exti_stm32, test_sw_interrupt_falling_trigger)
57+
{
58+
int ret = 0;
59+
60+
ret = stm32_exti_enable(TEST_EXTI_LINE_NR,
61+
STM32_EXTI_TRIG_FALLING,
62+
STM32_EXTI_MODE_IT);
63+
zassert_ok(ret, "Failed to enable EXTI line %d", TEST_EXTI_LINE_NR);
64+
65+
atomic_set(&is_test_exti_isr_called, false);
66+
67+
ret = stm32_exti_sw_interrupt(TEST_EXTI_LINE_NR);
68+
zassert_ok(ret, "Failed to fire SW interrupt on EXTI line %d",
69+
TEST_EXTI_LINE_NR);
70+
71+
zassert_equal(is_test_exti_isr_called, true,
72+
"ISR was not called for EXTI line %d", TEST_EXTI_LINE_NR);
73+
}
74+
75+
ZTEST(intc_exti_stm32, test_sw_interrupt_both_triggers)
76+
{
77+
int ret = 0;
78+
79+
ret = stm32_exti_enable(TEST_EXTI_LINE_NR,
80+
STM32_EXTI_TRIG_BOTH,
81+
STM32_EXTI_MODE_IT);
82+
zassert_ok(ret, "Failed to enable EXTI line %d", TEST_EXTI_LINE_NR);
83+
84+
atomic_set(&is_test_exti_isr_called, false);
85+
86+
ret = stm32_exti_sw_interrupt(TEST_EXTI_LINE_NR);
87+
zassert_ok(ret, "Failed to fire SW interrupt on EXTI line %d",
88+
TEST_EXTI_LINE_NR);
89+
90+
zassert_equal(is_test_exti_isr_called, true,
91+
"ISR was not called for EXTI line %d", TEST_EXTI_LINE_NR);
92+
}
93+
94+
static void *test_exti_intc_init(void)
95+
{
96+
IRQ_CONNECT(
97+
TEST_EXTI_IRQ_NR, TEST_EXTI_IRQ_PRIO,
98+
test_exti_isr, NULL, 0
99+
);
100+
101+
irq_enable(TEST_EXTI_IRQ_NR);
102+
103+
return NULL;
104+
}
105+
106+
ZTEST_SUITE(intc_exti_stm32, NULL, test_exti_intc_init, NULL, NULL, NULL);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2025 Alexander Kozhinov <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
common:
5+
tags:
6+
- drivers
7+
- interrupt
8+
min_ram: 8
9+
harness: ztest
10+
11+
tests:
12+
drivers.interrupt_controller.intc_exti_stm32:
13+
extra_args:
14+
- DTC_OVERLAY_FILE="boards/exti_default_resources.overlay"
15+
- platform:nucleo_c071rb/stm32c071xx:EXTRA_DTC_OVERLAY_FILE="boards/nucleo_c071rb_stm32c071xx.overlay"
16+
- platform:stm32h7s78_dk/stm32h7s7xx:EXTRA_DTC_OVERLAY_FILE="boards/stm32h7s78_dk_stm32h7s7xx.overlay"
17+
- platform:stm32n6570_dk/stm32n657xx/sb:EXTRA_DTC_OVERLAY_FILE="boards/stm32n6570_dk_stm32n657xx_sb.overlay"
18+
filter: dt_compat_enabled("st,stm32-exti") and dt_compat_enabled("test-st-stm32-exti")

0 commit comments

Comments
 (0)