RISC V port context switching from ISR

Hello, I am implementing FreeRTOS RISC V port on a MiV RV32 processor core running on M2GL025 creative board. The port requires “return statement” at the end of any ISR to keep it enable for the next interrupt, however if we want to wake a high priority task from ISR we need a call to “portEND_SWITCHING_ISR()” macro which would immediately invoke a context switch. So at this point it becomes confusing, How can we invoke a context switch from ISR and still let the ISR return to its trap handler script where it could complete the ISR execution?

Moreover, after some debugging it appears that if I omit the “return” statement from ISR call the processor will never came out of ISR and keep executing the ISR routine over and over again until some exception occurs for access fault. My ISR function is follows:

uint8_t External_31_IRQHandler()
   BaseType_t xHiPriTaskWoken= pdFALSE;


   xTaskNotifyFromISR(  my_task_handle, signal, 0x01, &xHiPriTaskWoken);

   portEND_SWITCHING_ISR( xHiPriTaskWoken );


Can someone help me with this problem?


Interrupt handler entry points cannot return values, so I assume External_31_IRQHandler() is not the entry point but a subroutine called from that entry point. That means the following might be options for you:

  • replace the interrupt entry point code so you don’t need to return a value from the function it calls (External_31_IRQHandler() in this case).

  • look at what is done with the return value, and do that inside of External_31_IRQHandler() instead.

  • somehow communicate back to the interrupt entry point whether a context switch is required, and perform the context switch there.

  • don’t bother calling portEND_SWITCHING_ISR(), which means the task that was unblocked will not run immediately after the interrupt exits, but the next time the currently running task blocks or the tick interrupt executes. If that is acceptable depends on your application.

  • manually re-enable the interrupt within External_31_IRQHandler() before calling portEND_SWITCHING_ISR().

somehow communicate whether a context switch is required or not will also have to be passed out of