No context switching after portYIELD_FROM_ISR() cortex M4

hi everyone I´m using the TM4c123 cortex m4 of TI and i’m trying to use the interrupts in FreeRTOS… here is the situation I’ve two tasks running, the Task 1 is blocking after attempting to get a binary semaphore(this task has the higher priority) then the Task 2 is running a simple for loop, waiting for an interrupt(the interrupt is the Rx of the UART0) then in the ISR(UARTIntHandler) call the xSemaphoreGiveFromISR and then the portYIELDFROMISR and here comes the problem because i’m expecting the running task will be the Task 1 because of the call to give the semaphore, but the Task 2 is actually running here is the simplified code also i put FreeRTOSconfig.h ~~~ void ConfigureUART(void) { // Configure GPIO Pins for UART mode. // Enable the GPIO Peripheral used by the UART. //… ROMIntPrioritySet(INTUART0, 0xA3 );//Here im setting the interrupt priority portDISABLEINTERRUPTS(); UARTIntDisable(INTUART0, UARTINTTX | UARTINTRI); ROMIntEnable(INTUART0); ROMUARTIntEnable(UART0BASE, UARTINTRX | UARTINTRT); } ~~~ ~~~ void vTask1 (void *pvParamaters) { while(1) { xSemaphoreTake( xBinarySemaphore, portMAX_DELAY ); //blocking the task ROM_UARTCharGetNonBlocking(UART0_BASE)…; } } ~~~ ~~~ void vTask2 (void *pvParamaters) { while(1) { for ( u1 = 0; u1 < mainDELAY_LOOP_COUNT; u1++ ){} } } ~~~ ~~~ void UARTIntHandler(void) { xSemaphoreGiveFromISR( xBinarySemaphore, &xHigherPriorityTaskWoken ); ROMUARTIntClear(INTUART0, UARTINTRX | UARTINTRT); if( xHigherPriorityTaskWoken ) { portYIELDFROMISR( xHigherPriorityTaskWoken );//After this, the context switch to Task 1 never happens } } ~~~ ~~~ int main(void) { ROMSysCtlClockSet(SYSCTLSYSDIV1 | SYSCTLUSEOSC | SYSCTLXTAL16MHZ |SYSCTLOSC_MAIN); ConfigureUART(); xBinarySemaphore = xSemaphoreCreateBinary(); xHigherPriorityTaskWoken = pdFALSE; xTaskCreate( vTask1, “Task 1”, 100, NULL, 2, NULL ); xTaskCreate( vTask2, “Task 2”, 100, NULL, 1, NULL );
vTaskStartScheduler(); while(1) { } } ~~~ ~~~ FreeRTOSConfig.h

define configUSE_PREEMPTION 1

define configUSETIMESLICING 1

define configMAX_PRIORITIES ( 5 )

define configIDLESHOULDYIELD 0

define configUSE16BIT_TICKS 0 /* Only for 8 and 16-bit hardware. */

/* Constants that describe the hardware and memory usage. */

define configCPUCLOCKHZ ( ( unsigned long ) 16000000 )

define configMINIMALSTACKSIZE ( ( unsigned short ) 200 )

define configMAXTASKNAME_LEN ( 12 )

define configTICKRATEHZ ( ( portTickType ) 1000 )

define configTOTALHEAPSIZE ( ( size_t ) ( 20240 ) )

/* Constants that build features in or out. */

define configUSE_MUTEXES 1

define configUSETICKLESSIDLE 0

define configUSEAPPLICATIONTASK_TAG 0

define configUSENEWLIBREENTRANT 0

define configUSECOROUTINES 0

define configUSECOUNTINGSEMAPHORES 1

define configUSERECURSIVEMUTEXES 1

define configUSEQUEUESETS 0

define configUSETASKNOTIFICATIONS 1

//—————————————————–

define INCLUDE_vTaskPrioritySet 1

define INCLUDE_uxTaskPriorityGet 1

define INCLUDE_vTaskDelete 1

define INCLUDE_vTaskCleanUpResources 0

define INCLUDE_vTaskSuspend 1

define INCLUDE_vTaskDelayUntil 1

define INCLUDE_vTaskDelay 1

define INCLUDE_uxTaskGetStackHighWaterMark 0

define INCLUDE_xTaskGetIdleTaskHandle 0

define INCLUDE_eTaskGetState 1

define INCLUDE_xTaskResumeFromISR 0

define INCLUDE_xTaskGetCurrentTaskHandle 1

define INCLUDE_xTaskGetSchedulerState 0

define INCLUDE_xSemaphoreGetMutexHolder 0

define INCLUDE_xTimerPendFunctionCall 1

/* I’m not understanding the following 2 Macros but i saw this in a demo */

define configLIBRARYLOWESTINTERRUPT_PRIORITY 0x07

define configLIBRARYMAXSYSCALLINTERRUPTPRIORITY 5

/* Here i set the Kernel interrupt level and the priority level fromISR function calls */

define configKERNELINTERRUPTPRIORITY ( 7 << 5 ) /* Priority 7, or 0xE0 */

define configMAXSYSCALLINTERRUPT_PRIORITY ( 5 << 5 ) /* Priority 5, or 0xA0 */

~~~ i will appreciate any help or clue to get the code running thanks in advance :))))) P.S: If anyone knows another technique to deferred an Interrupt in order to receive data from Uart I would appreciate it very much.

No context switching after portYIELD_FROM_ISR() cortex M4

At first glance there is not anything obviously wrong with your code. There is no need to test xHigherPriorityTaskWoken before passing it to portYIELDFROMISR, and xHigherPriorityTaskWoken should be initialised to 0, but neither of those are going to be the source of the problem. Which version of FreeRTOS are you using and do you have configASSERT defined? The reason I ask about the version is that the newer the version the more assert points there are. You say Task1 should run immediately, implying it does not, but does it run at all after the semaphore is given? Task notifications can be used in place of semaphores as they are much lighter weight.

No context switching after portYIELD_FROM_ISR() cortex M4

Thanks for the reply!, Which version of FreeRTOS are you using I’m using the FreeRTOS V9.0.0
do you have configASSERT defined? Yes, in FreeRTOSConfig I’ve… ~~~

define configASSERT( x ) if( ( x ) == 0 ) {

                               taskDISABLE_INTERRUPTS(); for( ;; ); 
                               }
~~~
You say Task1 should run immediately, implying it does not, but does it run at all after the semaphore is given? Task 1 just executes at the first time after vTaskStartScheduler(); then it never runs… :/
Task notifications can be used in place of semaphores as they are much lighter weight. I also have tried with task notifications but actually when i call vTaskNotifyGiveFromISR() xHigherPriorityTaskWoken never change to pdTRUE(1)

No context switching after portYIELD_FROM_ISR() cortex M4

Hi there, I’ve tried a simple modification in the code, specifically, inside the ISR ~~~ void UARTIntHandler(void) { xHigherPriorityTaskWoken = pdFALSE; while(ROMUARTCharsAvail(UART0BASE)) {
ROMUARTCharGetNonBlocking(UART0BASE); }
xSemaphoreGiveFromISR( xBinarySemaphore, &xHigherPriorityTaskWoken ); portYIELDFROMISR( xHigherPriorityTaskWoken ); ROMUARTIntClear(INTUART0, UARTINTRX | UARTINTRT); } ~~~ If i clean the fifo here, the Task 1 is executed after the end of the ISR but i do not realy want this because of the time spending inside the ISR, does anyone knows a better way to deferred the work of an ISR? thanks… 🙂