Can an interrupt with the same priority as `configKERNEL_INTERRUPT_PRIORITY` cause a Hardfault INVPC?


FreeRTOS Kernel V10.0.0
MCU: nRF52840 SDK 17.1.0

Our device is fully functional, and we are currently performing various tests. During long-term testing, we found that the device occasionally resets, though very rarely — about once every two weeks. We recently confirmed that these resets are due to a Hardfault INVPC.

Upon investigation, we found that `configKERNEL_INTERRUPT_PRIORITY` was not set to the lowest value (0x7 or higher), but instead was configured to the same value (0x6) as other interrupts.

When we increased `configKERNEL_INTERRUPT_PRIORITY` to 5, a Hardfault INVPC occurred immediately, and the PC and LR values matched those of the original Hardfault observed in our device.

To verify whether the issue was caused by overlapping kernel and other interrupts, we artificially triggered a PendSV by adding `SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;` inside the GPIO interrupt handler. However, no Hardfault INVPC occurred during this test.

We are nearing the product launch and would like to resolve this issue.

Q1: Can a Hardfault INVPC occur if an interrupt with the same priority as `configKERNEL_INTERRUPT_PRIORITY` is triggered?

Q2: How can we intentionally cause a Hardfault INVPC by using an interrupt with the same priority as `configKERNEL_INTERRUPT_PRIORITY`? What should the code look like?

Additional Hardfault Information:

CFSR: 0x00040000
PC: `prvProcessTimerOrBlockTask()` -> `portYIELD_WITHIN_API()`
LR: End of `xTaskResumeAll()`
MSP: 0x2003fef8
PSP: 0x20032348 (same as `p_stackaddress`)

Thank you in advance for your help.

  • I just confirmed that the PWM interrupt priority (0x7) was lower than configKERNEL_INTERRUPT_PRIORITY (0x6), and this seems to have been the issue. We are planning to change configKERNEL_INTERRUPT_PRIORITY to 0x7. Would it still be a problem if there are interrupts with the same priority as configKERNEL_INTERRUPT_PRIORITY? Or should we change the PWM interrupt to 0x6 as well?

  • I thought that the interrupt priority can be lower or equal to configKERNEL_INTERRUPT_PRIORITY  if the ISR is calling FreeRTOS API. But reading the documentation and some forums, it seems that it is highly recommended to use the same interrupt priority as RTOS for interrupts calling RTOS API.

    bilas77 said:
    Would it still be a problem if there are interrupts with the same priority as configKERNEL_INTERRUPT_PRIORITY? Or should we change the PWM interrupt to 0x6 as well?

    Keep the RTOS functionality (configKERNEL_INTERRUPT_PRIORITY ) at lowest priority to be safe. Only change this value if you understand every context of your application and the scheduler. I have not done regression testing with interrupt priority lower than configKERNEL_INTERRUPT_PRIORITY , since I always assumed and tested that configKERNEL_INTERRUPT_PRIORITY  will be lowest.

Related