NVIC_SetPriority causing hard fault

I’m trying to set up an interrupt for a SPI driver in my SPI0M task. In setting up the interrupt, my first call causes a hard fault. I’m calling the function NVIC_SetPriority(). I’m using a Nordic Semiconductor nRF9160 which is based on an ARM Cortex M33 core. This core also contains an MPU which I have enabled in my system.

If I make this task a privileged task, the system works. This implies that the task may be accessing memory without authorization and is being trapped by the MPU. I’ve tried adding the SPI0M and NVIC system registers to the allowed memory region access checked by the MPU to no avail.

Has anyone had this problem? How can I resolve this?


The following is from the architecture reference manual -

NVIC_IPRn, Interrupt Priority Register, n = 0 - 123

Sets or reads interrupt priorities.

Usage constraints
Privileged access permitted only. Unprivileged accesses generate a fault.

So this is a hardware restriction that you cannot set interrupt priority from unprivileged code.

OK, makes sense. So, I will set up the peripheral outside of the task in question. This should allow me to “un-privilege” my task that uses the peripheral. Thanks.