From ddb66e5b632ca8c96e2bfcd2564f4433060bdb74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Fri, 26 Apr 2024 14:10:48 +0200 Subject: [PATCH] samples: boards: nrf: Add sample using Coresight STM on nrf54h20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add sample that demonstrates logging using Coresight STM and ETR buffer handled by the application core. Application is using sysbuild and 2 cores: cpuapp and cpurad. cpuapp is logging to STM and handling ETR buffer where data from STM is collected and cpurad is only logging to STM. Signed-off-by: Krzysztof Chruściński --- .../boards/nrf/coresight_stm/CMakeLists.txt | 17 ++++ .../boards/nrf/coresight_stm/Kconfig.sysbuild | 9 ++ samples/boards/nrf/coresight_stm/prj.conf | 1 + .../nrf/coresight_stm/remote/CMakeLists.txt | 12 +++ .../boards/nrf/coresight_stm/remote/prj.conf | 1 + samples/boards/nrf/coresight_stm/sample.yaml | 13 +++ samples/boards/nrf/coresight_stm/src/main.c | 98 +++++++++++++++++++ .../boards/nrf/coresight_stm/sysbuild.cmake | 16 +++ 8 files changed, 167 insertions(+) create mode 100644 samples/boards/nrf/coresight_stm/CMakeLists.txt create mode 100644 samples/boards/nrf/coresight_stm/Kconfig.sysbuild create mode 100644 samples/boards/nrf/coresight_stm/prj.conf create mode 100644 samples/boards/nrf/coresight_stm/remote/CMakeLists.txt create mode 100644 samples/boards/nrf/coresight_stm/remote/prj.conf create mode 100644 samples/boards/nrf/coresight_stm/sample.yaml create mode 100644 samples/boards/nrf/coresight_stm/src/main.c create mode 100644 samples/boards/nrf/coresight_stm/sysbuild.cmake diff --git a/samples/boards/nrf/coresight_stm/CMakeLists.txt b/samples/boards/nrf/coresight_stm/CMakeLists.txt new file mode 100644 index 00000000000..facbc05da92 --- /dev/null +++ b/samples/boards/nrf/coresight_stm/CMakeLists.txt @@ -0,0 +1,17 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +if(NOT (CONFIG_BOARD_NRF54H20DK_NRF54H20_CPUAPP)) + message(FATAL_ERROR "${BOARD}${BOARD_QUALIFIERS} is not supported for this sample") +endif() + +project(nrf_coresight_stm) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/boards/nrf/coresight_stm/Kconfig.sysbuild b/samples/boards/nrf/coresight_stm/Kconfig.sysbuild new file mode 100644 index 00000000000..ae4c8048615 --- /dev/null +++ b/samples/boards/nrf/coresight_stm/Kconfig.sysbuild @@ -0,0 +1,9 @@ +# Copyright 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +source "share/sysbuild/Kconfig" + +config RAD_CORE_BOARD +string + default "nrf54h20dk/nrf54h20/cpurad" if $(BOARD) = "nrf54h20dk" diff --git a/samples/boards/nrf/coresight_stm/prj.conf b/samples/boards/nrf/coresight_stm/prj.conf new file mode 100644 index 00000000000..1bb8bf6d7fd --- /dev/null +++ b/samples/boards/nrf/coresight_stm/prj.conf @@ -0,0 +1 @@ +# empty diff --git a/samples/boards/nrf/coresight_stm/remote/CMakeLists.txt b/samples/boards/nrf/coresight_stm/remote/CMakeLists.txt new file mode 100644 index 00000000000..93cb458f960 --- /dev/null +++ b/samples/boards/nrf/coresight_stm/remote/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(nrf_coresight_stm) + +target_sources(app PRIVATE ../src/main.c) diff --git a/samples/boards/nrf/coresight_stm/remote/prj.conf b/samples/boards/nrf/coresight_stm/remote/prj.conf new file mode 100644 index 00000000000..1bb8bf6d7fd --- /dev/null +++ b/samples/boards/nrf/coresight_stm/remote/prj.conf @@ -0,0 +1 @@ +# empty diff --git a/samples/boards/nrf/coresight_stm/sample.yaml b/samples/boards/nrf/coresight_stm/sample.yaml new file mode 100644 index 00000000000..07e17766279 --- /dev/null +++ b/samples/boards/nrf/coresight_stm/sample.yaml @@ -0,0 +1,13 @@ +sample: + name: Logging using Coresight STM on nrf54h20 +common: + sysbuild: true +tests: + sample.boards.nrf.coresight_stm.dict: + platform_allow: + - nrf54h20dk/nrf54h20/cpuapp + integration_platforms: + - nrf54h20dk/nrf54h20/cpuapp + build_only: true + required_snippets: + - nordic-log-stm-dict diff --git a/samples/boards/nrf/coresight_stm/src/main.c b/samples/boards/nrf/coresight_stm/src/main.c new file mode 100644 index 00000000000..c203910b127 --- /dev/null +++ b/samples/boards/nrf/coresight_stm/src/main.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +LOG_MODULE_REGISTER(app); + +#define TEST_LOG(rpt, item) \ + ({ \ + uint32_t t = k_cycle_get_32(); \ + for (uint32_t i = 0; i < rpt; i++) { \ + __DEBRACKET item; \ + } \ + t = k_cycle_get_32() - t; \ + k_msleep(200); \ + t; \ + }) + +static char *core_name = "unknown"; + +static void get_core_name(void) +{ + if (strstr(CONFIG_BOARD_TARGET, "cpuapp")) { + core_name = "app"; + } else if (strstr(CONFIG_BOARD_TARGET, "cpurad")) { + core_name = "rad"; + } else if (strstr(CONFIG_BOARD_TARGET, "cpuppr")) { + core_name = "ppr"; + } +} + +static uint32_t t_to_ns(uint32_t t, uint32_t rpt, uint32_t freq) +{ + return (uint32_t)(((uint64_t)t * 1000000000) / (uint64_t)(rpt * freq)); +} + +static void timing_report(uint32_t t, uint32_t rpt, const char *str) +{ + uint32_t ns = t_to_ns(t, rpt, CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC); + + printk("%s: Timing for %s: %d.%dus\n", core_name, str, ns / 1000, (ns % 1000) / 10); +} + +int main(void) +{ + uint32_t t; + uint32_t delta; + uint32_t rpt = 10; + uint32_t rpt_tp = 20; + uint32_t t0, t1, t2, t3, t_s, t_tp, t_tpd; + char str[] = "test string"; + + get_core_name(); + + t = k_cycle_get_32(); + delta = k_cycle_get_32() - t; + + t0 = TEST_LOG(rpt, (LOG_INF("test no arguments"))); + t0 -= delta; + + t1 = TEST_LOG(rpt, (LOG_INF("test with one argument %d", 100))); + t1 -= delta; + + t2 = TEST_LOG(rpt, (LOG_INF("test with two arguments %d %d", 100, 10))); + t2 -= delta; + + t3 = TEST_LOG(rpt, (LOG_INF("test with three arguments %d %d %d", 100, 10, 1))); + t3 -= delta; + + t_s = TEST_LOG(rpt, (LOG_INF("test with string %s", str))); + t_s -= delta; + + if (IS_ENABLED(CONFIG_LOG_FRONTEND_STMESP)) { + t_tp = TEST_LOG(rpt_tp, (log_frontend_stmesp_tp(5))); + t_tp -= delta; + + t_tpd = TEST_LOG(rpt_tp, (log_frontend_stmesp_tp_d32(6, 10))); + t_tpd -= delta; + } + + timing_report(t0, rpt, "log message with 0 arguments"); + timing_report(t1, rpt, "log message with 1 argument"); + timing_report(t2, rpt, "log message with 2 arguments"); + timing_report(t3, rpt, "log message with 3 arguments"); + timing_report(t_s, rpt, "log_message with string"); + + if (IS_ENABLED(CONFIG_LOG_FRONTEND_STMESP)) { + timing_report(t_tp, rpt_tp, "tracepoint"); + timing_report(t_tpd, rpt_tp, "tracepoint_d32"); + } + + return 0; +} diff --git a/samples/boards/nrf/coresight_stm/sysbuild.cmake b/samples/boards/nrf/coresight_stm/sysbuild.cmake new file mode 100644 index 00000000000..c2eaeeaa20f --- /dev/null +++ b/samples/boards/nrf/coresight_stm/sysbuild.cmake @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if("${SB_CONFIG_RAD_CORE_BOARD}" STREQUAL "") + message(FATAL_ERROR + "Target ${BOARD} not supported for this sample. " + "There is no remote board selected in Kconfig.sysbuild") +endif() + +set(RAD_APP remote) + +ExternalZephyrProject_Add( + APPLICATION ${RAD_APP} + SOURCE_DIR ${APP_DIR}/${RAD_APP} + BOARD ${SB_CONFIG_RAD_CORE_BOARD} +)