Skip to content

Commit

Permalink
applications: machine_learning: Adapt to nRF54H20 with sysbuild
Browse files Browse the repository at this point in the history
Adapts the application to the nRF54H20 SoC and sysbuild.
The `sensor_hub.zdebug` configuration has simulated sensor data.
The `sensor_hub.zdebug.singlecore` configuration works
with the ADXL362 acceleration sensor

Ref: NCSDK-27407

Signed-off-by: Marcin Jelinski <[email protected]>
  • Loading branch information
maje-emb authored and anangl committed Jun 5, 2024
1 parent f9eea0a commit ae8803b
Show file tree
Hide file tree
Showing 54 changed files with 1,668 additions and 67 deletions.
3 changes: 2 additions & 1 deletion applications/machine_learning/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ project("Machine learning"
# NORDIC SDK APP START
target_sources(app PRIVATE
src/main.c
)
)
# NORDIC SDK APP END

# Include application events and configuration headers
Expand All @@ -35,6 +35,7 @@ zephyr_include_directories(
)

# Application sources
add_subdirectory(common/src/modules)
add_subdirectory(src/events)
add_subdirectory(src/modules)
add_subdirectory(src/util)
Expand Down
2 changes: 1 addition & 1 deletion applications/machine_learning/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

menu "Machine learning application"
rsource "src/Kconfig.ml_app"
rsource "common/Kconfig"
rsource "src/events/Kconfig"
rsource "src/modules/Kconfig"
rsource "src/util/Kconfig"
Expand Down
14 changes: 10 additions & 4 deletions applications/machine_learning/Kconfig.sysbuild
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ choice BOOTLOADER
endchoice

config NRF_DEFAULT_IPC_RADIO
default y if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS

config NETCORE_IPC_RADIO_BT_HCI_IPC
default y if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS
default y if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS || BOARD_NRF54H20DK_NRF54H20_CPUAPP

config SECURE_BOOT
default y if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS
Expand All @@ -26,4 +23,13 @@ config NETCORE_APP_UPDATE
config PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY
default y if BOARD_NRF5340DK_NRF5340_CPUAPP

config ML_APP_INCLUDE_REMOTE_IMAGE
bool "Include remote image build"
depends on SOC_NRF54H20_CPUAPP

config ML_APP_REMOTE_BOARD
string "The name of the board to be used by remote image"
depends on ML_APP_INCLUDE_REMOTE_IMAGE
default "nrf54h20dk/nrf54h20/cpuppr" if BOARD_NRF54H20DK_NRF54H20_CPUAPP

source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"
36 changes: 33 additions & 3 deletions applications/machine_learning/app_desc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,46 @@ The application supports the following build types:
- :file:`prj_rtt.conf`
- ``thingy53/nrf5340/cpuapp`` and ``thingy53/nrf5340/cpuapp/ns``
- Debug version of the application that uses RTT for printing logs instead of USB CDC.
* - Single-core
- :file:`prj_singlecore.conf`
- ``nrf54h20dk/nrf54h20/cpuapp``
- Configuration that does not use :term:`Peripheral Processor (PPR) <Peripheral Processor (PPR, pronounced “Pepper”)>` for data sampling.
Data is collected with the application CPU instead.

Building and running
********************

.. |sample path| replace:: :file:`applications/machine_learning`

The nRF Machine Learning application is built the same way as any other |NCS| application or sample.
Building the default configurations requires an Internet connection, because the machine learning model source files are downloaded from the web during the application build.

.. include:: /includes/build_and_run_ns.txt
.. |application path| replace:: :file:`applications/machine_learning`

.. include:: /includes/application_build_and_run.txt

nRF54H20 DK
To build the application for the nRF54H20 DK with the sensor sampling done by the Application core (single-core application), run the following command:

.. code-block:: console
west build -b nrf54h20dk/nrf54h20/cpuapp -- -DSHIELD=pca63566 -DFILE_SUFFIX="singlecore"
or use twister test case:

.. code-block:: console
west build -b nrf54h20dk/nrf54h20/cpuapp -T applications.machine_learning.sensor_hub.zdebug.singlecore .
To build the application for the nRF54H20 DK with the simulated sensor on the PPR core (dual-core application), run the following command:

.. code-block:: console
west build -b nrf54h20dk/nrf54h20/cpuapp -- -DSB_CONFIG_ML_APP_INCLUDE_REMOTE_IMAGE=y -Dmachine_learning_SNIPPET=nordic-ppr
or use twister test case:

.. code-block:: console
west build -b nrf54h20dk/nrf54h20/cpuapp -T applications.machine_learning.sensor_hub.zdebug .
Selecting a build type
======================
Expand Down
12 changes: 12 additions & 0 deletions applications/machine_learning/common/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Common"

rsource "src/Kconfig.ml_app"
rsource "src/modules/Kconfig"

endmenu
11 changes: 11 additions & 0 deletions applications/machine_learning/common/src/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Copyright (c) 2024 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_sources_ifdef(CONFIG_ML_APP_EVENT_PROXY
app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/event_proxy.c)

target_sources_ifdef(CONFIG_ML_APP_SENSOR_STUB_GEN
app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/sensor_stub_gen.c)
12 changes: 12 additions & 0 deletions applications/machine_learning/common/src/modules/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Common modules"

rsource "Kconfig.event_proxy"
rsource "Kconfig.sensor_stub_gen"

endmenu
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menuconfig ML_APP_EVENT_PROXY
bool "Event proxy module"
depends on SOC_SERIES_NRF54HX
depends on EVENT_MANAGER_PROXY
select APP_EVENT_MANAGER_POSTINIT_HOOK
help
Enable and initialize event manager proxy subsystem on application
start. Subscribtion to events is done based on configuration file.

if ML_APP_EVENT_PROXY

config ML_APP_REMOTE_CORE_INITIALIZATION_TIMEOUT
int "Remote core initialization timeout [ms]"
range 10 10000
default 2000
help
The time to wait for remote cores to report its readines. The time is
given in miliseconds.

module = ML_APP_EVENT_PROXY
module-str = event proxy module
source "subsys/logging/Kconfig.template.log_config"

endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menuconfig ML_APP_SENSOR_STUB_GEN
bool "Sensor stub data generator"

if ML_APP_SENSOR_STUB_GEN

config ML_APP_SENSOR_STUB_GEN_TRIG_TIMEOUT_MS
int "Wave signal change timeout [ms]"
default 1000
help
The timeout triggers selecting next simulated wave signal.

module = ML_APP_SENSOR_STUB_GEN
module-str = sensor stub gen
source "subsys/logging/Kconfig.template.log_config"

endif # ML_APP_SENSOR_STUB_GEN
65 changes: 65 additions & 0 deletions applications/machine_learning/common/src/modules/event_proxy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/kernel.h>

#include "event_proxy_def.h"

#include <zephyr/ipc/ipc_service.h>
#include <event_manager_proxy.h>

#define MODULE event_proxy

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(MODULE, CONFIG_ML_APP_EVENT_PROXY_LOG_LEVEL);

#define EVENT_PROXY_INIT_TIMEOUT CONFIG_ML_APP_REMOTE_CORE_INITIALIZATION_TIMEOUT


static int event_proxy_init(void)
{
int ret = 0;

for (size_t i = 0; i < ARRAY_SIZE(proxy_configs); i++) {
const struct event_proxy_config *pcfg = proxy_configs[i];
const struct device *inst = pcfg->ipc;

ret = event_manager_proxy_add_remote(inst);
if (ret) {
LOG_ERR("Can not add %s remote: %d", inst->name, ret);
__ASSERT_NO_MSG(false);
return ret;
}

for (size_t e_idx = 0; e_idx < pcfg->events_cnt; e_idx++) {
ret = event_manager_proxy_subscribe(inst, pcfg->events[e_idx]);
if (ret) {
LOG_ERR("Can not subscribe to remote %s: %d",
pcfg->events[e_idx]->name, ret);
__ASSERT_NO_MSG(false);
return ret;
}
}
}

ret = event_manager_proxy_start();
if (ret) {
LOG_ERR("Can not start: %d", ret);
__ASSERT_NO_MSG(false);
return ret;
}

ret = event_manager_proxy_wait_for_remotes(K_MSEC(EVENT_PROXY_INIT_TIMEOUT));
if (ret) {
LOG_ERR("Remotes not ready: %d", ret);
__ASSERT_NO_MSG(false);
return ret;
}

return 0;
}

APP_EVENT_MANAGER_HOOK_POSTINIT_REGISTER(event_proxy_init);
Loading

0 comments on commit ae8803b

Please sign in to comment.