Skip to content

Commit 5a338ff

Browse files
LucasTamborkartben
authored andcommitted
samples: boards: espressif: ulp: Add interrupt sample
Add an interrupt triggered by HP Core sample Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
1 parent 243f7c4 commit 5a338ff

File tree

11 files changed

+178
-0
lines changed

11 files changed

+178
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../interrupt_ulp_lpcore/zephyr)
7+
8+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
9+
10+
message(STATUS "${CONFIG_BOARD_TARGET} compile as Master in this sample")
11+
project(interrupt_ulp_hpcore)
12+
13+
target_sources(app PRIVATE src/main.c)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
source "share/sysbuild/Kconfig"
5+
6+
config ULP_REMOTE_BOARD
7+
string
8+
default "esp32c6_devkitc/esp32c6/lpcore" if $(BOARD) = "esp32c6_devkitc"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.. zephyr:code-sample:: interrupt-ulp
2+
:name: Interrupt ULP
3+
4+
HP Core interrupt LP Core.
5+
6+
Overview
7+
********
8+
9+
This sample shows how to trigger LP Core interrupt from the HP core.
10+
11+
Building and Flashing
12+
*********************
13+
14+
Build the sample code as follows:
15+
16+
.. zephyr-app-commands::
17+
:zephyr-app: samples/boards/espressif/ulp/lp_core/interrupt_ulp
18+
:board: esp32c6_devkitc/esp32c6/hpcore
19+
:west-args: --sysbuild
20+
:goals: build
21+
:compact:
22+
23+
Flash it to the device with the command:
24+
25+
.. zephyr-app-commands::
26+
:zephyr-app: samples/boards/espressif/ulp/lp_core/interrupt_ulp
27+
:board: esp32c6_devkitc/esp32c6/hpcore
28+
:west-args: --sysbuild
29+
:goals: flash
30+
:compact:
31+
32+
Sample Output
33+
=============
34+
35+
Console output on the HP core:
36+
37+
.. code-block:: console
38+
39+
Triggering ULP interrupt...
40+
Triggering ULP interrupt...
41+
Triggering ULP interrupt...
42+
Triggering ULP interrupt...
43+
Triggering ULP interrupt...
44+
45+
Console output on the LP core:
46+
47+
.. code-block:: console
48+
49+
LP PMU interrupt received: 0
50+
LP PMU interrupt received: 1
51+
LP PMU interrupt received: 2
52+
LP PMU interrupt received: 3
53+
LP PMU interrupt received: 4
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&lp_uart {
8+
status = "okay";
9+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ULP_COPROC_ENABLED=y
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
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+
message(STATUS "${BOARD} compiles as remote in this sample")
9+
project(interrupt_ulp_lpcore)
10+
11+
target_sources(app PRIVATE src/main.c)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# nothing here
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include "ulp_lp_core_utils.h"
9+
#include "ulp_lp_core_interrupts.h"
10+
11+
volatile uint32_t lp_core_pmu_intr_count;
12+
13+
void ulp_lp_core_lp_pmu_intr_handler(void)
14+
{
15+
ulp_lp_core_sw_intr_clear();
16+
lp_core_pmu_intr_count++;
17+
printf("LP PMU interrupt received: %d\n", lp_core_pmu_intr_count);
18+
}
19+
20+
int main(void)
21+
{
22+
lp_core_pmu_intr_count = 0;
23+
ulp_lp_core_intr_enable();
24+
ulp_lp_core_sw_intr_enable(true);
25+
26+
while (1) {
27+
/* Wait forever, handling interrupts */
28+
asm volatile("wfi");
29+
}
30+
return 0;
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sample:
2+
name: ESP32-C6 LP_CORE Interrupt Sample
3+
tests:
4+
sample.boards.espressif.ulp.lp_core.interrupt_ulp:
5+
platform_allow:
6+
- esp32c6_devkitc/esp32c6/hpcore
7+
tags:
8+
- samples
9+
sysbuild: true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <ulp_lp_core.h>
9+
#include <zephyr/kernel.h>
10+
11+
int main(void)
12+
{
13+
while (1) {
14+
printf("Triggering ULP interrupt...\n");
15+
ulp_lp_core_sw_intr_trigger();
16+
k_sleep(K_MSEC(1000));
17+
}
18+
19+
return 0;
20+
}

0 commit comments

Comments
 (0)