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:

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();
    
    
}

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 :

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();
    
    
}

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,

Parents
  • I'd like to know exactly why you want to change UART interrupt priority. The reason I ask is that the SoftDevice will crash if the application spends too much time at priority 2. There might be another way to achieve your goal, but I need to know what your goal is. I'm guessing it is to ensure that you do not lose any data on the UART and in that case you'd want to use a combination of UART and DMA to ensure that you can receive data without loss when your application is running in regular priority as defined in our SDK (6 or 7). 

    The UARTE — Universal asynchronous receiver/transmitter with EasyDMA peripheral has EasyDMA (Direct Memory Access to RAM), this enables the UARTE peripheral to receive the the UART transmission, place it into RAM, and notify the application through the EVENTS_ENDRX event. 
    See Reception for details. 



Reply
  • I'd like to know exactly why you want to change UART interrupt priority. The reason I ask is that the SoftDevice will crash if the application spends too much time at priority 2. There might be another way to achieve your goal, but I need to know what your goal is. I'm guessing it is to ensure that you do not lose any data on the UART and in that case you'd want to use a combination of UART and DMA to ensure that you can receive data without loss when your application is running in regular priority as defined in our SDK (6 or 7). 

    The UARTE — Universal asynchronous receiver/transmitter with EasyDMA peripheral has EasyDMA (Direct Memory Access to RAM), this enables the UARTE peripheral to receive the the UART transmission, place it into RAM, and notify the application through the EVENTS_ENDRX event. 
    See Reception for details. 



Children
No Data
Related