Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions samples/modules/tflite-micro/micro_speech/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(micro_speech_openamp)

# These samples use local static initialization. Since Zephyr doesn't support the
# C++ ABI for thread-safe initialization of local statics and the constructors don't
# appear to require thread safety, we turn it off in the C++ compiler.
set(NO_THREADSAFE_STATICS $<TARGET_PROPERTY:compiler-cpp,no_threadsafe_statics>)
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${NO_THREADSAFE_STATICS}>)

# Define common paths
set(OPTIONAL_TFLITE_DIR $ENV{ZEPHYR_BASE}/../optional/modules/lib/tflite-micro/signal)

file(
GLOB
app_sources
src/*
src/inference/*
)

target_include_directories(
app
PRIVATE
src
${ZEPHYR_TFLITE_MICRO_MODULE_DIR}/signal
${ZEPHYR_TFLITE_MICRO_MODULE_DIR}/signal/micro/kernels/
${ZEPHYR_TFLITE_MICRO_MODULE_DIR}/signal/src
${LIBMETAL_INCLUDE_DIR}
${OPENAMP_INCLUDE_DIR}
${PLATFORM_DIR}
)

target_sources(
app
PRIVATE
${app_sources}

# Signal processing
${OPTIONAL_TFLITE_DIR}/src/fft_auto_scale.cc
${OPTIONAL_TFLITE_DIR}/src/max_abs.cc
${OPTIONAL_TFLITE_DIR}/src/msb_32.cc
${OPTIONAL_TFLITE_DIR}/src/energy.cc
${OPTIONAL_TFLITE_DIR}/src/filter_bank.cc
${OPTIONAL_TFLITE_DIR}/src/pcan_argc_fixed.cc
${OPTIONAL_TFLITE_DIR}/src/filter_bank_log.cc
${OPTIONAL_TFLITE_DIR}/src/log.cc
${OPTIONAL_TFLITE_DIR}/src/filter_bank_spectral_subtraction.cc

# Micro kernels
${OPTIONAL_TFLITE_DIR}/micro/kernels/energy.cc
${OPTIONAL_TFLITE_DIR}/micro/kernels/fft_auto_scale_common.cc
${OPTIONAL_TFLITE_DIR}/micro/kernels/filter_bank_square_root_common.cc
${OPTIONAL_TFLITE_DIR}/micro/kernels/filter_bank_spectral_subtraction.cc
${OPTIONAL_TFLITE_DIR}/micro/kernels/filter_bank.cc
${OPTIONAL_TFLITE_DIR}/micro/kernels/pcan.cc
${OPTIONAL_TFLITE_DIR}/micro/kernels/filter_bank_log.cc
)

if ("${BOARD_ARCH}" STREQUAL "xtensa")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be if("${ARCH}" STREQUAL "xtensa")

target_sources(
app
PRIVATE

# Xtensa kernels
${OPTIONAL_TFLITE_DIR}/micro/kernels/xtensa/fft_auto_scale_kernel.cc
${OPTIONAL_TFLITE_DIR}/micro/kernels/xtensa/filter_bank_square_root.cc
${OPTIONAL_TFLITE_DIR}/micro/kernels/xtensa/xtensa_square_root.S
)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CONFIG_LOG_PRINTK=n
CONFIG_IPM_IMX_MAX_DATA_SIZE_16=n
CONFIG_IPM_IMX_MAX_DATA_SIZE_4=y
CONFIG_OPENAMP_WITH_DCACHE=y

#vendor-specific resource table
CONFIG_OPENAMP_VENDOR_RSC_TABLE=y
CONFIG_OPENAMP_VENDOR_RSC_TABLE_FILE="nxp_resource_table.c"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 NXP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright should be Copyright 2025 NXP

*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
/*
* shared memory reserved for the inter-processor communication
*/
zephyr,ipc_shm = &dspsram3;
zephyr,ipc = &mailbox0;
};

dspsram3: memory@942f0000 {
compatible = "mmio-sram";
reg = <0x942f0000 0x110000>;
};
};

&mailbox0 {
status = "okay";
};
21 changes: 21 additions & 0 deletions samples/modules/tflite-micro/micro_speech/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# tflite
CONFIG_CPP=y
CONFIG_STD_CPP17=y
CONFIG_TENSORFLOW_LITE_MICRO=y
CONFIG_MAIN_STACK_SIZE=6144 # tflm arena size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the comment on top of the config:

# stack size needed to safely initialize
# and run TensorFlow Lite Micro operations
# in the main thread
CONFIG_MAIN_STACK_SIZE=6144

CONFIG_REQUIRES_FLOAT_PRINTF=y

# rpmsg
CONFIG_KERNEL_BIN_NAME="micro_speech_openamp"
CONFIG_PRINTK=n
CONFIG_IPM=y
CONFIG_HEAP_MEM_POOL_SIZE=5120 # rpmsg buffers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above:

# rpmsg buffers + OpenAMP overhead + safety margin
CONFIG_HEAP_MEM_POOL_SIZE=5120

I also believe this can be decreased, but didn't check which value is accepted

CONFIG_OPENAMP=y
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=8
CONFIG_OPENAMP_RSC_TABLE=y
CONFIG_OPENAMP_MASTER=n
CONFIG_SHELL=n

# logging
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
20 changes: 20 additions & 0 deletions samples/modules/tflite-micro/micro_speech/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sample:
description: Micro Speech OpenAMP Sample
name: micro speech openamp
common:
tags: tensorflow
modules:
- tflite-micro
harness: console
harness_config:
type: multi_line
ordered: false
regex:
- "Detected: (yes|no|silence|unknown)"
tests:
sample.tensorflow.micro_speech_openamp:
platform_allow:
- imx8mp_evk/mimx8ml8/adsp
integration_platforms:
- imx8mp_evk/mimx8ml8/adsp
tags: tensorflow, openamp, ipc, audio
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONFIG_LOG_PRINTK=n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all these snippets files.
Keep only imx8mp support since this was tested and mentioned in the README.

CONFIG_IPM_IMX_MAX_DATA_SIZE_16=n
CONFIG_IPM_IMX_MAX_DATA_SIZE_4=y
CONFIG_OPENAMP_WITH_DCACHE=y
CONFIG_SHELL=n

#vendor-specific resource table
CONFIG_OPENAMP_VENDOR_RSC_TABLE=y
CONFIG_OPENAMP_VENDOR_RSC_TABLE_FILE="nxp_resource_table.c"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove file

* Copyright 2024 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
/*
* shared memory reserved for the inter-processor communication
*/
zephyr,ipc_shm = &dspsram3;
zephyr,ipc = &mailbox0;
};

dspsram3: memory@942f0000 {
compatible = "mmio-sram";
reg = <0x942f0000 0x110000>;
};
};

&mailbox0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: nxp-openamp-imx8-adsp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove file

boards:
/imx8qxp_mek\/mimx8qx6\/adsp|imx8qm_mek\/mimx8qm6\/adsp/:
append:
EXTRA_DTC_OVERLAY_FILE: nxp-openamp-imx8-adsp.overlay
EXTRA_CONF_FILE: nxp-openamp-imx8-adsp.conf
Loading