samples: boards: nrf: Add sample using Coresight STM on nrf54h20

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 <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2024-04-26 14:10:48 +02:00 committed by Anas Nashif
commit ddb66e5b63
8 changed files with 167 additions and 0 deletions

View file

@ -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)

View file

@ -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"

View file

@ -0,0 +1 @@
# empty

View file

@ -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)

View file

@ -0,0 +1 @@
# empty

View file

@ -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

View file

@ -0,0 +1,98 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/logging/log.h>
#include <zephyr/logging/log_frontend_stmesp.h>
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;
}

View file

@ -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}
)