SDK 2.6.3, nRF5340 and how to customize DTM example

Hi,

i am working with the following setup:

- nrf5340

- SDK 2.6.3

- Direct Test Mode example with serial communication 

I see that DTM example has changed from 2.1.4 to 2.6.3, so that the communication with the netcore goes through the appcore (child image, remote_shell).

I wanted to avoid copying all the DTM example into my repo, so I managed to access its code by a CMakeLists.txt file that looks like this: 

# CMakeLists.txt
cmake_minimum_required(VERSION 3.20.0)

# This to immediately characterize ZEPHYR_BASE
find_package(Zephyr COMPONENTS extensions basic_settings)
zephyr_get(USER_VAR)

# Define the absolute path to the directory containing the DTM sample in the installed SDK
cmake_path(SET DTM_PATH NORMALIZE "${ZEPHYR_BASE}/../nrf/samples/bluetooth/direct_test_mode/")
message(STATUS "DTM_PATH=${DTM_PATH}")

# To compile the Direct Test Mode example directly from the SDK without copying, it is necessary to specify:
# 1. The configuration files for netcore and appcore (CONF_FILE)
# 2. The device tree overlay files for netcore and appcore(DTC_OVERLAY_FILE)
# 3. The KConfig file only for the netcore (KCONFIG_ROOT)
set(CONF_FILE 
    ${DTM_PATH}prj.conf;
    ${DTM_PATH}boards/nrf5340dk_nrf5340_cpunet.conf
    CACHE INTERNAL "Configuration files for netcore")
set(DTC_OVERLAY_FILE
    ${DTM_PATH}boards/nrf5340dk_nrf5340_cpunet.overlay;
    ${DTM_PATH}conf/remote_shell_nrf53.overlay
    remote_shell_cpunet.overlay     # Local file to change the TX and RX pin of UART
    CACHE INTERNAL "Devicetree overlays for netcore")
set(KCONFIG_ROOT "${DTM_PATH}KConfig")

set(remote_shell_CONF_FILE 
    ${DTM_PATH}child_image/remote_shell/prj.conf
    CACHE INTERNAL "Configuration files for appcore")
set(remote_shell_DTC_OVERLAY_FILE
    ${DTM_PATH}child_image/remote_shell/boards/nrf5340dk_nrf5340_cpuapp.overlay;
    ${CMAKE_CURRENT_SOURCE_DIR}/remote_shell_cpuapp.overlay # Local file to change the TX and RX pin of UART
    CACHE INTERNAL "Devicetree overlay for appcore")

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

# Import the SDK's sample as your source
add_subdirectory(${ZEPHYR_NRF_MODULE_DIR}/samples/bluetooth/direct_test_mode app)

My project directory looks like this:

remote_shell_cpu*.overlay files are the one used to changed the tx and rx pin of the uart (they both includes remote_shell_pinctrl.dtsi)

In this configuration, i can build the DTM example and i can test it on my custom board.

Question 1: is this a good approach ? is there another better, maybe by using the sysbuild ?

I would like to know if it is possible with the describe configuration (no copy of the example), inject some code into the child image of the DTM example, that is the app core.

I dont want to redefine the main function of the code running on the app_core (remote_shell). I was thinking to create a small thread where i can perform just a couple of configuration/initialization that we need on our custom board. Like, creating the file app_core_thread.c as follows:

#include <zephyr/kernel.h>

static void my_thread_fn(void *p1, void *p2, void *p3) {
    (void) p1;
    (void) p2;
    (void) p3;
    //Perfom customization
    // let the task be deleted
}
K_THREAD_DEFINE(my_thread_id, 256, my_thread_fn, NULL, NULL, NULL, 10, 0, 0);

I tried several approaches but none of them worked.

Question 2: is there a way to inject code in an child image (in this case, the remote shell of DTM example) based on the configuration described above (no hard copy of the example in my repo) ?

Thanks in advance for your support.

Kind regards

Riccardo Gaiati

Parents
  • Hello,

    Sorry, it's not clear to me what you are really trying to solve here, you are of course free to do whatever you like. Normally if you plan to modify an existing NCS example the best is to copy it to somewhere outside of the NCS and modify and add overlays as you want.

    Kenneth

  • Hi Kenneth,

    i am trying to understand if it is possible to NOT COPY all the code of the DTM example in my repo, inject some modification in the child image (that is the app core) and build it via the CMakeLists.txt file i posted above.

    I managed to do the first part: have the example built without copying the code and tested on my custom board.

    What i miss is the possibility to inject some code in the child image.

    But probably it is not..

  • Actually it is possible.
    I managed to do what I was asking in this ticket:

    1. Build the DTM example for nrf5340 with SDK 2.6.3 for both the core WITHOUT copying any of the files from the SDK; use the CMakeLists.txt file reported above.
    2. Inject some code into the child image (remote shell) without affecting any code in the sample.
    3. Customize the TX and RX pin of the UART used to communicate with the app core

    I had to create a a module in the child_image/remote_shell where my custom c file is compiled and linked.

    In order to the custom code to be executed, i put the function in the macro SYS_INIT.

    The reason behind to do this is basically to not have to bring in my repo all the code from a sample that i do not want to change.

    If there is another way to achieve that, I would be very happy to know.

    Thanks

  • Thanks for sharing, this may be useful for others also.

    Kenneth

Reply Children
Related