Accessing timers from the secure world/TFM custom partition?

My programm uses both the non-secure world and the secure world, with the non-secure-world largely just calling functions inside a custom partition of TFM in the secure world.

In the secure world I want to use a timer, but that leads to the runtime error "FATAL ERROR: BusFault" when the line accessing the timer is called (also checked with addr2line).
(I can run the code inside the non-secure world with the timer. Currently/At first i want to use timer0 for the non-secure world and timer1 for the secure world. In both files i included the header nrfx_timer.h using "#include <nrfx_timer.h>".)
(This is SDK v2.6.1 with a nRF9161.)


Timer-part of prj.conf

CONFIG_NRFX_TIMER0=y
CONFIG_NRFX_TIMER1=y
CONFIG_NRF_TIMER1_SECURE=y


Working timer-code in non-secure world (in main.c)
NRF_TIMER0->MODE=0;
NRF_TIMER0->BITMODE=3;            //3 = 32bit
NRF_TIMER0->PRESCALER=0;
NRF_TIMER0->CC[0] = 0;
NRF_TIMER0->CC[1] = 0;
NRF_TIMER0->CC[2] = 0;
NRF_TIMER0->CC[3] = 0;
NRF_TIMER0->CC[4] = 0;
NRF_TIMER0->TASKS_START=1;
NRF_TIMER0->TASKS_CAPTURE[0] = 1;
int testint = 5+8;
NRF_TIMER0->TASKS_CAPTURE[1] = 1;
printf("NRF_TIMER0->CC[0] is %u \n", NRF_TIMER0->CC[0]);
printf("NRF_TIMER0->CC[1] is %u \n", NRF_TIMER0->CC[1]);


Non-Working timer-code in custom secure partition (leads to immediate runtime error "FATAL ERROR: BusFault")
NRF_TIMER1->MODE=0;        //also tried NRF_TIMER1_S->MODE=0; but doesn't work either

(I also tried instead setting the timers in the non-secure world with the NS postfix ("NRF_TIMER0_NS->MODE=0" instead of "NRF_TIMER0->MODE=0" and in the secure world with S postfix (NRF_TIMER1_S->MODE=0 instead of NRF_TIMER1->MODE=0, but it led to the same result.)

How to modify the configuration or the code in general so that i can access the timer inside the custom secure partition?

Parents
  • Hi gdl,

    Configuring a peripheral to be used in the secure domain is demonstrated in the TF-M secure peripheral partition sample. Have you taken a look at it yet?

    Also, depends on what you are trying to implement, you might not need a TIMER peripheral, and might be able to use something simpler, such as the timing features in the Zephyr Kernel.

    As you mentioned that you want to do most things in the secure domain, I would like to remind you that doing that is not necessarily more secured, and the modem can only be accessed from the non-secure domain.

    Hieu

Reply
  • Hi gdl,

    Configuring a peripheral to be used in the secure domain is demonstrated in the TF-M secure peripheral partition sample. Have you taken a look at it yet?

    Also, depends on what you are trying to implement, you might not need a TIMER peripheral, and might be able to use something simpler, such as the timing features in the Zephyr Kernel.

    As you mentioned that you want to do most things in the secure domain, I would like to remind you that doing that is not necessarily more secured, and the modem can only be accessed from the non-secure domain.

    Hieu

Children
  • Hey Hieu
    Many Thanks. I didn't correctly fully configure the yaml and it seems to work now.

    As you mentioned that you want to do most things in the secure domain, I would like to remind you that doing that is not necessarily more secured, and the modem can only be accessed from the non-secure domain.

    Sry i said that unclear. Later somebody else will write the extensive actual code for the non-secure world, but for now development is mainly about the secure-world.

    Also, depends on what you are trying to implement, you might not need a TIMER peripheral, and might be able to use something simpler, such as the timing features in the Zephyr Kernel.

    I'm trying to make some performance measurements. But i wouldn't be able to use the timing-features of zephyr in the custom secure partition/TFM or could i (as the secure world doesn't use zephyr if i didn't misunderstand it)?


    Also is there any way to use one timer (or sth similar) from both the non-secure and the secure world?

  • Hi gdl,

    I am glad to know things are working.

    gdl said:
    I'm trying to make some performance measurements. But i wouldn't be able to use the timing-features of zephyr in the custom secure partition/TFM or could i (as the secure world doesn't use zephyr if i didn't misunderstand it)?

    I don't think you made any misunderstanding. I am a novice in this topic myself and misunderstood things.

    On this note, I want to add that there is also the RTC peripheral, which has much lower resolution and accuracy, but also much lower current consumption. However, as you are only making measurements during development, I assume power efficiency isn't much of a concern.

    gdl said:
    Also is there any way to use one timer (or sth similar) from both the non-secure and the secure world?

    I don't think so. That would violate the principle of isolation, wouldn't it?

Related