From 5a338ff5bbf3cdd87f044e2b288b20aa4206ce2d Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Tue, 28 Jan 2025 10:22:09 -0300 Subject: [PATCH] samples: boards: espressif: ulp: Add interrupt sample Add an interrupt triggered by HP Core sample Signed-off-by: Lucas Tamborrino --- .../ulp/lp_core/interrupt_ulp/CMakeLists.txt | 13 +++++ .../lp_core/interrupt_ulp/Kconfig.sysbuild | 8 +++ .../ulp/lp_core/interrupt_ulp/README.rst | 53 +++++++++++++++++++ .../ulp/lp_core/interrupt_ulp/app.overlay | 9 ++++ .../ulp/lp_core/interrupt_ulp/prj.conf | 1 + .../interrupt_ulp/remote/CMakeLists.txt | 11 ++++ .../ulp/lp_core/interrupt_ulp/remote/prj.conf | 1 + .../lp_core/interrupt_ulp/remote/src/main.c | 31 +++++++++++ .../ulp/lp_core/interrupt_ulp/sample.yaml | 9 ++++ .../ulp/lp_core/interrupt_ulp/src/main.c | 20 +++++++ .../ulp/lp_core/interrupt_ulp/sysbuild.cmake | 22 ++++++++ 11 files changed, 178 insertions(+) create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/CMakeLists.txt create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/Kconfig.sysbuild create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/README.rst create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/app.overlay create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/prj.conf create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/CMakeLists.txt create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/prj.conf create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/src/main.c create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/sample.yaml create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/src/main.c create mode 100644 samples/boards/espressif/ulp/lp_core/interrupt_ulp/sysbuild.cmake diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/CMakeLists.txt b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/CMakeLists.txt new file mode 100644 index 00000000000..b3a3727cbf6 --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd. +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../interrupt_ulp_lpcore/zephyr) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +message(STATUS "${CONFIG_BOARD_TARGET} compile as Master in this sample") +project(interrupt_ulp_hpcore) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/Kconfig.sysbuild b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/Kconfig.sysbuild new file mode 100644 index 00000000000..1a54b95872b --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/Kconfig.sysbuild @@ -0,0 +1,8 @@ +# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd. +# SPDX-License-Identifier: Apache-2.0 + +source "share/sysbuild/Kconfig" + +config ULP_REMOTE_BOARD + string + default "esp32c6_devkitc/esp32c6/lpcore" if $(BOARD) = "esp32c6_devkitc" diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/README.rst b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/README.rst new file mode 100644 index 00000000000..f443dc83d94 --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/README.rst @@ -0,0 +1,53 @@ +.. zephyr:code-sample:: interrupt-ulp + :name: Interrupt ULP + + HP Core interrupt LP Core. + +Overview +******** + +This sample shows how to trigger LP Core interrupt from the HP core. + +Building and Flashing +********************* + +Build the sample code as follows: + +.. zephyr-app-commands:: + :zephyr-app: samples/boards/espressif/ulp/lp_core/interrupt_ulp + :board: esp32c6_devkitc/esp32c6/hpcore + :west-args: --sysbuild + :goals: build + :compact: + +Flash it to the device with the command: + +.. zephyr-app-commands:: + :zephyr-app: samples/boards/espressif/ulp/lp_core/interrupt_ulp + :board: esp32c6_devkitc/esp32c6/hpcore + :west-args: --sysbuild + :goals: flash + :compact: + +Sample Output +============= + +Console output on the HP core: + +.. code-block:: console + + Triggering ULP interrupt... + Triggering ULP interrupt... + Triggering ULP interrupt... + Triggering ULP interrupt... + Triggering ULP interrupt... + +Console output on the LP core: + +.. code-block:: console + + LP PMU interrupt received: 0 + LP PMU interrupt received: 1 + LP PMU interrupt received: 2 + LP PMU interrupt received: 3 + LP PMU interrupt received: 4 diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/app.overlay b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/app.overlay new file mode 100644 index 00000000000..244dc34aa97 --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/app.overlay @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&lp_uart { + status = "okay"; +}; diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/prj.conf b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/prj.conf new file mode 100644 index 00000000000..7d425a10aa2 --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/prj.conf @@ -0,0 +1 @@ +CONFIG_ULP_COPROC_ENABLED=y diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/CMakeLists.txt b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/CMakeLists.txt new file mode 100644 index 00000000000..e0de5eca7a3 --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd. +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +message(STATUS "${BOARD} compiles as remote in this sample") +project(interrupt_ulp_lpcore) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/prj.conf b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/prj.conf new file mode 100644 index 00000000000..b2a4ba59104 --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/prj.conf @@ -0,0 +1 @@ +# nothing here diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/src/main.c b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/src/main.c new file mode 100644 index 00000000000..e6cf1bcee93 --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/remote/src/main.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "ulp_lp_core_utils.h" +#include "ulp_lp_core_interrupts.h" + +volatile uint32_t lp_core_pmu_intr_count; + +void ulp_lp_core_lp_pmu_intr_handler(void) +{ + ulp_lp_core_sw_intr_clear(); + lp_core_pmu_intr_count++; + printf("LP PMU interrupt received: %d\n", lp_core_pmu_intr_count); +} + +int main(void) +{ + lp_core_pmu_intr_count = 0; + ulp_lp_core_intr_enable(); + ulp_lp_core_sw_intr_enable(true); + + while (1) { + /* Wait forever, handling interrupts */ + asm volatile("wfi"); + } + return 0; +} diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/sample.yaml b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/sample.yaml new file mode 100644 index 00000000000..15e3e7ee481 --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/sample.yaml @@ -0,0 +1,9 @@ +sample: + name: ESP32-C6 LP_CORE Interrupt Sample +tests: + sample.boards.espressif.ulp.lp_core.interrupt_ulp: + platform_allow: + - esp32c6_devkitc/esp32c6/hpcore + tags: + - samples + sysbuild: true diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/src/main.c b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/src/main.c new file mode 100644 index 00000000000..504d39c438c --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/src/main.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +int main(void) +{ + while (1) { + printf("Triggering ULP interrupt...\n"); + ulp_lp_core_sw_intr_trigger(); + k_sleep(K_MSEC(1000)); + } + + return 0; +} diff --git a/samples/boards/espressif/ulp/lp_core/interrupt_ulp/sysbuild.cmake b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/sysbuild.cmake new file mode 100644 index 00000000000..ec4b67f12bd --- /dev/null +++ b/samples/boards/espressif/ulp/lp_core/interrupt_ulp/sysbuild.cmake @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2024 Espressif + +# Add external project +ExternalZephyrProject_Add( + APPLICATION interrupt_ulp_lpcore + SOURCE_DIR ${APP_DIR}/remote + BOARD ${SB_CONFIG_ULP_REMOTE_BOARD} + ) + +# Add dependencies so that the remote sample will be built first +# This is required because some primary cores need information from the +# remote core's build, such as the output image's LMA +add_dependencies(interrupt_ulp interrupt_ulp_lpcore) +sysbuild_add_dependencies(CONFIGURE interrupt_ulp interrupt_ulp_lpcore) +sysbuild_add_dependencies(FLASH interrupt_ulp_lpcore interrupt_ulp) + +if(SB_CONFIG_BOOTLOADER_MCUBOOT) + # Make sure MCUboot is flashed first + sysbuild_add_dependencies(FLASH interrupt_ulp mcuboot) +endif()