Enable GPIO IRQ in TFM 1.3 with zephry v2.7.0 on nrf5340DK

I want to enable GPIO IRQ in Trusted firmware-m 1.3 on nrf5340DK. I have TFM 1.3 which comes with zephyr v2.7.0 image flashed to board. followed the steps of https://www.trustedfirmware.org/docs/tech_forum_20210819BriefUpdatesInterruptHandling.pdf and tfm_slih_test_service which has TIMER0 interrupt handler.

Steps1: Assigning the interrupt GPIOTE0 and TIMER0 in secure partition manifest file.

Steps2: Assigning the MMIO region of GPIOTE0 and TIMER0 in secure partition manifest file.

Step3: Enable(psa_irq_enable) for both GPIOTE0,TIMER0 and Start (tfm_plat_test_secure_timer_start) the TIMER0.

Step4: waiting for interrupt SIGNAL defined in secure partition manifest file for GPIOTE0 and TIMER0) using psa_wait(PSA_WAIT_ANY, PSA_BLOCK) in the secure partition source code.

But do not receive any signal for TIMER0 and GPIOTE0.

Q1) at least TIMER0 signal should be received after the timer start?

Q2)Are there any steps i missed to enable IRQ in TFM secure partition?

Q3)Also, for GPIOTE i need to enable IRQ on the particular pin of port0 ex P0.8, How can i know the signal generated for the interrupt is for P0.8?

Q4)In tfm_secure_irq_handling.rst it mentions "it is important the macro name matches the platform's handler function for that IRQ source."

- In case ``source`` is defined IRQ macro, the name of the handler becomes
``void <macro>_Handler(void)``.

I do not understand why we need to have a handler function name matching with IRQ source when we have to wait on psa_wait(PSA_WAIT_ANY, PSA_BLOCK) for IRQ signal?

Thanks

Parents
  • Hi Einar,

    I see that 'tfm_slih_test' works on my nrf5340DK board. But not tfm_flih_test. “timer0_handler()” is called both in tfm_slih_test.c or our custom tfm service as long as  “CONFIG_TFM_REGRESSION_NS=y” in tfm_regression_test client sample. Further by experimenting, I found that slih timer interrupt is called if I remove all tests except below 2 tests, and I see that ‘register_testsuite_ns_core_positive’ just returns a ‘CORE_TEST_ERRNO_SUCCESS’, ‘register_testsuite_ns_qcbor’ runs some 20 something qcbr lib test and nothing is related timer interrupt. But if these 2 test are run then timer0 interrupt always work. Commenting any of these tests just disable the timer interrupt.

     

    static struct test_suite_t test_suites[] = {

        /* List test cases which are compliant with level 1 isolation */

    #if defined(TFM_PARTITION_INITIAL_ATTESTATION) || defined(FORWARD_PROT_MSG)

        /* Non-secure QCBOR library test cases */

        {&register_testsuite_ns_qcbor, 0, 0, 0},

    #endif

    /* Non-secure core test cases */

    {&register_testsuite_ns_core_positive, 0, 0, 0},

        /* End of test suites */

        {0, 0, 0, 0}

    };

    I see that SLIH, timer0_handler is when TFM_TIMER0_IRQ_SIGNAL is received in psa_wait() and send by SPM. This is how SLIH is working in test suite and my own custom service as long as “CONFIG_TFM_REGRESSION_NS=y” is enabled as discussed above.

     

    static void timer0_handler(void)

    {

        tfm_plat_test_secure_timer_stop();

        psa_irq_disable(TFM_TIMER0_IRQ_SIGNAL);

    }

    static void slih_test_case_2(void) {

        psa_irq_enable(TFM_TIMER0_IRQ_SIGNAL);

        tfm_plat_test_secure_timer_start();

        while (psa_wait(TFM_TIMER0_IRQ_SIGNAL, PSA_BLOCK) != TFM_TIMER0_IRQ_SIGNAL);

        timer0_handler();

    }

     

    In tfm_plat_test.h, defines a macro that put the timer start function in Read-only section of the partition.

     

    TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_SLIH_TEST", "APP-ROT")

    tfm_plat_test_secure_timer_start, tfm_plat_test_secure_timer_stop

     

    1. now I need to know why timer0 interrupt is working only when “register_testsuite_ns_qcbor” and “register_testsuite_ns_core_positive” is run in tests?

    2. Any clue why FLIH timer interrupts not working?

    3. What are the number of configurable priorities on your Interrupt Controller (NVIC)?

    4. Is there any sample to enable GPTIOE or any other peripheral interrupt sample in TFM test suite? Currently, I see only the Timer interrupt sample.

    Thanks

    Yaduvir

  • Hi Yaduvir,

    I must admit this is quite new for us and there is a lot of work on this these days, so there are some differences between TF-M, Zephyr and NCS, and even between Zephyr 2.7.0 and Zephyr master.

    The IRQ tests does not fully work on the Nordic platform yet, so you should not rely on them. There is a fix in this PR.

    The tests use TIMER0, so if you are running the tests in addition to your other code you may need to use a different timer instance.

    Regarding priorities, there are 8 interrupt priorities.

    Einar

  • I tried testing GPIO interrupts on Zephyr 3.0.0-rc1 on the nrf5340DK board. It still not working though the release has GPIO interrupts added to nrf5340DK. I do see that there is some implementation missing from GPIO interrupts implementation.

    I wanted to enable interrupts on P0.0 - P0.7 pins of port0. and tested on both methods GPIOTE0 and GPIO but didnt receive any of the SLIH

    1./home/osboxes/zephyrproject/modules/tee/tf-m/trusted-firmware-m/platform/ext/target/nordic_nrf/common/nrf5340/tfm_interrupts.c

    +//spu_peripheral_config_non_secure((uint32_t)NRF_P0, false);   (commented this line to enable Port 0 in secure mode)

    Enable pin P0.0 - P0.7 interrupts

    +//spu_gpio_config_non_secure(0, TFM_PERIPHERAL_GPIO0_PIN_MASK_SECURE, true);
    + spu_gpio_config_non_secure(0, 0x0f, true);  

    2.modules/tee/tf-m/trusted-firmware-m/platform/ext/target/nordic_nrf/common/nrf5340/target_cfg.c

    Missing "struct tfm_peripheral_gpiote0", i added this. 


    #if TFM_PERIPHERAL_GPIOTE0_SECURE
    struct platform_data_t tfm_peripheral_gpiote0 = {
    NRF_GPIOTE0_S_BASE,
    NRF_GPIOTE0_S_BASE + (sizeof(NRF_GPIOTE_Type) - 1),
    };
    #endif

    3.modules/tee/tf-m/trusted-firmware-m/platform/ext/target/nordic_nrf/common/nrf5340/tfm_peripherals_def.h

       3.1 This line was missing, so i added GPIOTE0

                   +extern struct platform_data_t tfm_peripheral_gpiote0;

                   + #define TFM_PERIPHERAL_GPIOTE0 (&tfm_peripheral_gpiote0)

       3.2 These macros are missing for GPIO Ports

             TFM_GPIO0_IRQ, TFM_GPIO1_IRQ as GPIO0_IRQn number not defined in 

    4. modules/hal/nordic/nrfx/mdk/nrf5340_application.h

    Missing, GPIO0_IRQn, GPIO1_IRQn  define in the header.

    5.modules/tee/tf-m/trusted-firmware-m/platform/ext/target/nordic_nrf/nrf5340dk_nrf5340_cpuapp/tfm_peripherals_config.h

    Missing, added these lines

    +#define TFM_PERIPHERAL_GPIOTE0_SECURE 1

    +#define TFM_PERIPHERAL_GPIO1_SECURE 1

    Questions:

    1) Only GPIOTE0 IRQ number is defined in number 3) above. does that mean GPIO interrupts can be received through GPIOTE and not through GPIO directly?

    2)Timer0 and Timer1 interrupts are working but not GPIO, is GPIO interrupts implemented in Zephyr 3.0.0-rc1?, There is no test for gpio interrupts in tfm_regression_test. i tested GPIO interrupts by adding a test and modifying ".yaml" file.


    "irqs": [
    {
    "source": "TFM_GPIOTE0_IRQ",
    "name": "TFM_GPIOTE0_IRQ",
    "handling": "SLIH",
    }

    OR

    "irqs": [
    {
    "source": "TFM_GPIO0_IRQ",
    "name": "TFM_GPIO0_IRQ",
    "handling": "SLIH",
    }

    Build command is:

     west build -b nrf5340dk_nrf5340_cpuapp_ns zephyr/samples/tfm_integration/tfm_regression_test

    Thanks

    Yaduvir

  • Hi Yaduvir,

    I am sorry for the late reply. I have checked with the team workin on TF-M, and this is still not supported. It is being worked on though, and I will update here as soon as soon as we have some code in (pull requests) you can refer to.

    Einar

Reply Children
No Data
Related