nRF5340, UART interrupt-based reads in secure partition

I'm adapting the sample code for TF-M secure peripheral sample (NCS v2.5.0, nrf/samples/tfm/tfm_secure_peripheral) to also add a UART peripheral. But this sample uses the older API (nrfx) which so far I've struggled with finding example code for. I was able to infer from the timer setup in that sample project, and get code working that can do a blocking write, with functions like nrf_uarte_tx_buffer_set() and nrf_uarte_task_trigger(). But how can I perform reads? I need to be able to perform them non-blocking, and interrupt-based.

If I could get some sample projects that explain this, I'd appreciate it. Thank you in advance!

  • Hi,

    The SDK includes nrfx UARTE samples under modules/hal/nordic/nrfx/samples/src/nrfx_uarte/, including a non-blocking (interrupt-based) sample. (TF-M is not a Zephyr applicaiton, so you cannot use Zephyr APIS. But low-levle APIs like nrfx or HAL functionality can be used.)

  • I tried adding it to the secure peripheral sample and it builds but the board keeps restarting. Could you help debug this please?

    Attached is the project. For context, I am developing on Windows 10 w/ VS Code (and the nRF Connect extension). I'm also using an nRF5340DK.
    tfm_secure_peripheral_20241022.zip

    Summary of my changes include:

    • Editing secure_peripheral_partition/secure_peripheral_partition.c, w/ UART init and interrupt handler
    • Editing .conf file to add nrfx drivers for UART1
    • Editing secure_peripheral_partition/tfm_secure_peripheral_partition.yaml to add UART peripheral alongside timer and SPI
    • Creating build config preset for nRF5340DK

    Symptoms of the restarting:

    • No output on VCOM0 or VCOM1, even when I use RESET button to restart the board
    • Constant output of 'Booting TF-M v1.8.0' on secure partition output (nRF5340DK pin P0.25)

    This next note can be addressed later (priority right now is just getting the above to work) but ideally, I need output from app core, network core, and secure partition. I believe app core and network core will use UART0 and UART1 respectively, so I assume I need a separate one like UART2 for data transfer. I did try adjusting the code for UART2 but it failed to build with an error that looks like "C:/ncs/v2.5.0/modules/hal/nordic/nrfx/drivers/include/nrfx_uarte.h:70:35: error: 'NRFX_UARTE2_INST_IDX' undeclared (first use in this function); did you mean 'NRFX_UARTE1_INST_IDX'?"

  • Hi,

    I have not had a chance to test your applicaiton, but looking at it one thing sticks out. UART1 is used by logging in TF-M by default, and you have not disabled it. So here it looks like you are trying to use UART1 for two things at the same time? (both for logging and directly in your secure_peripheral_partition/secure_peripheral_partition.c)? Do you see a difference if you disable logging in TF-M (CONFIG_TFM_LOG_LEVEL_SILENCE)?

  • I tried adding CONFIG_TFM_LOG_LEVEL_SILENCE=y to prj.conf and could not build it. I got an error that looks like:

    C:/ncs/v2.5.0/modules/hal/nordic/nrfx/drivers/include/nrfx_uarte.h:70:35: error: 'NRFX_UARTE1_INST_IDX' undeclared (first use in this function); did you mean 'NRFX_UARTE_INSTANCE'?

  • Hi,

    Ah  yes. When disabling TF-M logging, that also disabled the UART driver etc. Setting CONFIG_TFM_SECURE_UART1=y should fix this.

    A colleague of me made a sample some time ago using UARTE0 via nrfx drivers in a modified secure periperal partision sample that you can refer to: tfm_secure_peripheral_uarte0.zip (This was made for SDK 2.2, but there has not been that many changes since then related to this)

Related