Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


taskYIELD() causes hang inPIC24f interupt

Posted by Sean on November 16, 2010
Per the FreeRTOS documentation to handle API calls inside of an interrupt I need to taskYIELD if necessary, I have the following ISR:

void __attribute__ ((__interrupt__, no_auto_psv)) _T4Interrupt(void)
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
IFS1bits.T4IF = 0;

xQueueSendToBackFromISR(queue_name, &queue_data, &xHigherPriorityTaskWoken);

if(xHigherPriorityTaskWoken == pdTRUE)
taskYIELD(); // Force context switch

Everytime xHigherPriorityTaskWoken is true and the taskYIELD() executes, my processor resets. I've debugged to determine this is correct. If I comment out the taskYIELD, everything works smoothly.

The only thing I can think is that the priority of this interrupt is 7 and the tick timer has priority 1, but I'm not disabling any interrupts and per the RTOS docs this should be the correct method to use.

RE: taskYIELD() causes hang inPIC24f interupt

Posted by Ricky on November 16, 2010
The correct function to use to switch tasks inside an interrupt is vTaskSwitchContext, not taskYield. So your code should look like this:

if(xHigherPriorityTaskWoken == pdTRUE)
vTaskSwitchContext(); // Force context switch

RE: taskYIELD() causes hang inPIC24f interupt

Posted by Richard on November 16, 2010
I think in this case calling taskYIELD() is the correct thing to do - but this must be done as the very last thing in the ISR routine. Is it the last line of executable code?

FreeRTOS\Demo\PIC24_MPLAB\serial\serial.c has an example ISR.


RE: taskYIELD() causes hang inPIC24f interupt

Posted by Sean on November 16, 2010
I've solved the problem. It turns out I was getting a stack overflow on my IDLE task. I had been assuming that the stack used for interrupts was from the task executing when the interrupt occurred which wouldn't have caused any stack issues.

Could someone shed some light on what consumes the IDLE task's stack during operation? (I have no user defined IDLE hook or anything that should be used during idle time).

(It looks like taskYIELD() is correct, when I switched it out with vTaskSwitchContext() I got strange behavior)

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner