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!

  • Currently looking into integrating code from your colleague's example into my own.

    However, if you have any thoughts about the following, I'd appreciate your thoughts on what else I can try. I've found that:

    • Adding CONFIG_TFM_SECURE_UART1=y puts me back at the board constantly restarting.
    • Your colleague's example doesn't build in SDK 2.5.0. I didn't expect it to immediately build, but just to document, I'm seeing this build error
      • Traceback (most recent call last):
        File "C:/ncs/v2.5.0/modules/tee/tf-m/trusted-firmware-m/tools/tfm_parse_manifest_list.py", line 723, in <module>
        main()
        File "C:/ncs/v2.5.0/modules/tee/tf-m/trusted-firmware-m/tools/tfm_parse_manifest_list.py", line 711, in main
        context = process_partition_manifests(manifest_lists,
        File "C:/ncs/v2.5.0/modules/tee/tf-m/trusted-firmware-m/tools/tfm_parse_manifest_list.py", line 303, in process_partition_manifests
        logging.info(" {:40s} ON".format(manifest_item['description']))
        KeyError: 'description'
        CMake Error at tools/CMakeLists.txt:192 (message):
        Manifest tool failed to generate files!
  • Hello. So it's been about a week since I first posted the project files that I've been trying. Even though I've been getting suggestions, it's clear that my specific project has not been looked at, tried out on your end, etc. I'd like to ask if this question's priority could be moved up, and if I could get someone else (i.e., a senior engineer) to help provide more concrete and technical support please.

  • Hi,

    I am also helping in this ticket, and I am jumping in to give you an answer today, since Einar has gone home for the day. He will be back tomorrow.

    I tried my hand on strapping together the TF-M Secure Peripheral sample and the nrfx UARTE sample. While I would in no words call this test tidy, it at least works.

    Connect an UART reader to P0.25 and P0.26, and you should be able to see the following:

    [Sec Thread] Secure image initializing!
    Booting TF-M v1.8.0
    Starting nrfx_uarte non-blocking example.
    Content of TX buffer: Nordic Semiconductor
    Content of RX buffer: 
    Nordic Semiconductor
    

    The "Contect" stuff is logging, but the last line "Nordic Semiconductor" is written over UART using nrfx.

    tfm_secure_peripheral_uart1.zip

    I hope having code that runs can give you a good starting point to do what you want.
    Let us know if this is what you need

  • I tried out your code but it is still not working. I'm still seeing the UART (at P0.25) constantly outputting 'Booting TF-M v1.8.0' (must be constantly restarting I assume).

    [Sec Thread] Secure image initializing!
    Booting TF-M v1.8.0
    Nordic Semiconductor[Sec Thread] Secure image initializing!
    Booting TF-M v1.8.0
    Nordic Semiconductor[Sec Thread] Secure image initializing!
    Booting TF-M v1.8.0
    Nordic Semiconductor
    ... (this keeps repeating over and over)

    I've tried doing an 'erase & flash', making sure nothing is running on the network core (flashed the 'empty_net_core' project at NCS v2.5.0, nrf/samples/nrf5340/empty_net_core), etc.

    Also recall that my original question is to get UART working specifically with reading (not writing) data. So I'm expecting code that also shows the basics of reading (using interrupts).

  • Hi,

    The nrfx approach (which was used in the project you got yesterday) was not ideal, as interrupts needs to be handled specially in TF-M and that was not the case ther. It turns out that the cleanest is to avoid nrfx and use the lower-level HAL direcly, in th esame way as is allready done for SPIM in the sample. I put together a very simple sample now which does that: tfm_secure_peripheral_uarte_hal.zip. This is a minimal change from the existing sample in the SDK, but it does work and demonstrate both Tx and interrupt driven Rx. It sends "Nordic Seminoductor" once, and handles incomming Rx data. It does not process the data in any way, and just re-starts Rx when data is received, so to see that it works you can put a breakpoint in tfm_uarte1_irq_flih() before sending data and see taht the uart_rx_buf is populated with the received data:

    In addition to the changes in the secure_peripheral_partition.c file and prj.conf, there are also some changes in the tfm_secure_peripheral_partition.yaml needed for the interrupt handling (search for UARTE1 in that file), this is as described under Secure interrupt in the sample documentation.

Related