This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Dynamic change of Interrupt priority (sd_nvic_SetPriority)

Hi everyone,

Device : nRF52832

SDK version : 14.2

Softdevice : S132 v5.0

I am facing a problem when changing the interrupt priority dynamically. Let me explain the context of my application. My BLE module is basically a bridge between BLE and UART. I am a slave for the BLE and master for the UART.

I would like to have UART priority set to 2 when I am waiting for an answer from the nested device over UART, and UART priority set to 7 when I am not waiting for an answer (since I am the master for that communication).

The code was already developped for another application using a cortex-M4 from NXP and works perfectly fine.

Below you can see the intruction used for that:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
void RS485ManageIRQ(){
//Timeout when finished receiving bytes
//Currently the priority is 2
//Now set the priority to 7 for the next interrupt
__disable_irq(); // Avoid irq restart at priority change
NVIC_SetPriority(pRS485Vars->UART_IRQn, RS485_INTP_NEWPACK); // Set priority under real time
__enable_irq();
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Now I am facing a problem since Nordic does not recommend (forbid?) to disable IRQ using __disable_irq() since it blocks the time-critical operation of the softdevice.

But in all documentation I found, it is strongly recommended to disable all IRQ before using the function NVIC_SetPriority.

Actually now my code looks like this :

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
void RS485ManageIRQ(){
//Timeout when finished receiving bytes
//Currently the priority is 2
//Now set the priority to 7 for the next interrupt
//__disable_irq(); //cannot disable all IRQ
sd_nvic_SetPriority(nrf_drv_get_IRQn((void *)pRS485Vars->Reg.pUart), RS485_INTP_CALLBACK); // Set priority under real time
//__enable_irq();
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I am actually using the sd_ wrapper function for the NVIC_SetPriority, since no SVC calls are made inside it I assume that this should not be a problem calling it from interrupt level 2.

Using sd_nvic_critical_region_enter/exit function instead of __disable_irq() is not sufficient if I want to follow the recommendation since it disable only the application interruption.

Do you recommend a workaround to dynamically change the interrupt priority?

This is my first message on the DevZone, I hope that I explained my issue well enough.

Best regards,