Adding IPC to TF-M secure peripheral project

I would like to take Nordic's "TF-M secure peripheral partition" sample project, and modify it to take data received from the secure peripheral and send it wirelessly to another device. But I am running into some build errors and am unsure of how to fix it.

I'm working on a Windows 10 machine, with nRF5340DK's, and using NCS v2.5.0. I am using VS Code w/ the nRF Connect extensions for my development environment.

The "TF-M secure peripheral partition" sample project I mentioned comes from the NCS (at nrf/samples/tfm/tfm_secure_peripheral). I modified the sample slightly to get the SPI peripheral to interact with my sensor, and am able to read data from it.

Currently I am working on code to send data from the application core to the network core (before adding the wireless portion). I have previously worked with IPC for this (based off the sample project at NCS, path nrf/samples/ipc/ipc_service), so I am trying to integrate that code into this TF-M project. I tried adding the source code into the secure partition (as I assume it needs access to the data from the secure peripheral) and the build fails with the error looking like the following:

(Note that I trimmed down or modified the output slightly for brevity and privacy)

[77/224] Building C object secure_fw/partitions/partitions/secure_peripheral_partition_1/CMakeFiles/tfm_app_rot_partition_spp.dir/C_/ncs/v2.5.0/modules/tee/tf-m/trusted-firmware-m/platform/ext/common/syscalls_stub.o
[78/224] Building C object secure_fw/partitions/partitions/secure_peripheral_partition_1/CMakeFiles/tfm_app_rot_partition_spp.dir/secure_peripheral_partition.o
FAILED: (...command removed for brevity...)
In file included from C:/ncs/v2.5.0/zephyr/include/zephyr/sys/mem_manage.h:104,
                 from C:/ncs/v2.5.0/zephyr/include/zephyr/sys/device_mmio.h:47,
                 from C:/ncs/v2.5.0/zephyr/include/zephyr/device.h:15,
                 from C:/path_to_secure_peripheral_project/secure_peripheral_partition/secure_peripheral_partition.c:27:
C:/ncs/v2.5.0/zephyr/include/zephyr/sys/mem_manage.h: In function 'z_mem_phys_addr':
C:/ncs/v2.5.0/nrf/modules/tfm/tfm/boards/include/zephyr/sys/__assert.h:52:32: warning: implicit declaration of function 'tfm_core_panic' [-Wimplicit-function-declaration]
   52 | #define __ASSERT_POST_ACTION() tfm_core_panic()
      |                                ^~~~~~~~~~~~~~
C:/ncs/v2.5.0/nrf/modules/tfm/tfm/boards/include/zephyr/sys/__assert.h:93:25: note: in expansion of macro '__ASSERT_POST_ACTION'
   93 |                         __ASSERT_POST_ACTION();                                \
      |                         ^~~~~~~~~~~~~~~~~~~~
C:/ncs/v2.5.0/zephyr/include/zephyr/sys/mem_manage.h:158:9: note: in expansion of macro '__ASSERT'
  158 |         __ASSERT((addr >= CONFIG_SRAM_BASE_ADDRESS) &&
      |         ^~~~~~~~
In file included from C:/path_to_secure_peripheral_project/secure_peripheral_partition/secure_peripheral_partition.c:28:
C:/ncs/v2.5.0/zephyr/include/zephyr/ipc/ipc_service.h: At top level:
C:/ncs/v2.5.0/zephyr/include/zephyr/ipc/ipc_service.h:368:81: error: unknown type name 'k_timeout_t'
  368 | int ipc_service_get_tx_buffer(struct ipc_ept *ept, void **data, uint32_t *size, k_timeout_t wait);
      |                                                                                 ^~~~~~~~~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.EXE' --build 'c:\path_to_secure_peripheral_project\build'

To try and debug the issue, I've tried adding parts one by one to test. It seems that this error appears once I include the ipc_service.h header, like the following:

/* FILE: secure_peripheral/secure_peripheral_partition.c */

#include <psa/crypto.h>
#include <stdint.h>
/* ... (rest of includes; not shown here for brevity ... */
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/ipc/ipc_service.h>    // error when add this

/* ... (rest of file) ... */

I tried briefly looking into the CMakeLists.txt files, using the PSA API instead of this IPC code, etc. So far I haven't been able to find where my exact problem is occurring. If I could get some pointers with what to look more closely at, I'd appreciate the help. Thank you in advance!

Parents
  • (OP replying) Instead of adding IPC code to the secure partition, I tried adding it to the non-secure partition (I will look into transferring data between secure/non-secure later). It builds and can flash on my board; for quick testing, I flashed the entire IPC sample project (application and network core) and then flashed my main project (which should overwrite only application core).

    But it's not able to complete the setup of my endpoint. It keeps hanging at my k_sem_take() function call; if I change the timeout to K_NO_WAIT, I get -EBUSY (device is busy). Any thoughts on debugging this?

Reply
  • (OP replying) Instead of adding IPC code to the secure partition, I tried adding it to the non-secure partition (I will look into transferring data between secure/non-secure later). It builds and can flash on my board; for quick testing, I flashed the entire IPC sample project (application and network core) and then flashed my main project (which should overwrite only application core).

    But it's not able to complete the setup of my endpoint. It keeps hanging at my k_sem_take() function call; if I change the timeout to K_NO_WAIT, I get -EBUSY (device is busy). Any thoughts on debugging this?

Children
Related