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?

  • 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

Related