Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


my code is getting crash within few seconds after calling xQueueSendToBackFromISR

Posted by paulmurugan on February 27, 2015

Hello Together,

Problem: my code is getting crash within few seconds after my activation of timer input capture interrupt

I have used freeRTOS for freescale HCS12X series microcontroller and developed code for periodic tasks and for interrupt task (porting code taken from HCS12HCS12XCodeWarrior_OAF). Interrupt been implemented with handler task support. Syncronization has been implmented via semaphore and queue concept. As of now i have created three interrupts. 1. RTI interrupt for Timer tick generation (RTI- Real Time iInterrupt) 2. Timer over flow interrupt for my use. There is no semaphore and queue have been used inside this routine so portYIELD function is not used within the ISR. 3. Timer input capture interrupt, used queue concept. It has a handler task to receive the queue and calling some function.

Actually my code is getting crash within few seconds after my activation of timer input capture interrupt(generated square wave using function generator with frequency about 1Hz to 2Khz). i follow the procedure given in freerTOs manual for implementing ISR and handler function. Perhaps i disable the handler funcion to stop receiving the queue data to know portYIELD would be the reason for crash. But still the problem exist.

I have posted my code below.

define portYIELD() __asm( "swi" );

/* ISR routine */ _interrupt VectorNumberVtim1ch4 void MLTimer1Ch4ISR (void)


portBASE_TYPE pxHigherPriorityTaskWoken;
ML_Timer_ISRHandlerParam p_ISRarameter;
if( TIM1_TIOS_IOS4 == (Bool)0)
    parameter.timer = TIMER_1;
    parameter.channel = CHANNEL_4;
    parameter.timer_count = TIM1_TC4;
    parameter.overflow= timer1_Overflow[4];
    timer1_Overflow[4] = 0;
  /* Future use - Code for Output Compare */

TIM1_TFLG1|= 0x10;

xQueueSendToBackFromISR (ML_TIMER_CAPTURE_HANDLE, &parameter, &pxHigherPriorityTaskWoken);
/* Blocked task, waiting for this Queue has priority higher than the interrupted task */
if(pxHigherPriorityTaskWoken == pdTRUE) 


/* ISR hnadler task 3*/

static void ISRHandleQueueFunction (void pvParameters) { BaseTypet returnflag; SLISRHandleConfig taskparameter; / Accessing task configuration through task parameters / taskparameter = (SLISRHandleConfig *)pvParameters; for(;;) { / Queue data receive from interrupt service routine */ returnflag = xQueueReceive(taskparameter->handlename, &taskparameter;portMAX_DELAY);

/* Task calling */

} }

_interrupt VectorNumberVswi void vPortYield (void) //void vPortYield (void) { portSAVECONTEXT(); vTaskSwitchContext(); portRESTORECONTEXT(); }

/* RTI interrupt for Tiemr tick generation */ _interrupt VectorNumberVrti void TimerTick_ISR (void)

#if configUSEPREEMPTION == 1 { /* A context switch might happen so save the context. */ portSAVECONTEXT(); PORTB_PB2=1; /* Increment the tick ... */ if( xTaskIncrementTick() != pdFALSE ) { vTaskSwitchContext(); }

	CRGFLG_RTIF = (Bool)1;								   

	/* Restore the context of a task - which may be a different task
	to that interrupted. */
	CRGFLG_RTIF = (Bool)1;


Note:I have not used interrupt nesting in my project. configMAXSYSCALLINTERRUPT_PRIORITY is not avilable in my project.

my code is getting crash within few seconds after calling xQueueSendToBackFromISR

Posted by rtel on February 27, 2015

Sorry, I am confused. Which architecture are you running this on? You mentioned an HSC12, which is a rather old port (although also a simple port so should be ok). If so, did you start with the demo in the FreeRTOS download and follow the instructions for that demo to create interrupts, etc.? There should be no need for you to be doing things like defining your own yield macros, they are already defined by the port layer.

Have you done things like turn on stack overflow checking, defining configASSERT(), etc.?


my code is getting crash within few seconds after calling xQueueSendToBackFromISR

Posted by paulmurugan on February 27, 2015


I am using MC9S12XHY256 freescale microcontroller (HCS12X architecture). So the demo project is not fit for this HCS12X architecture. I have taken the micro controller porting code from the below link.


If the timer input capture interrupt is disabled (which has xQueueSendToBackFromISR function call), all the periodic tasks are running without any issues. Perhaps if i enable timer interrupt then the code is getting crash after a period of time.

Kindly let me know what could be cause of the issue. You can refer the code i have shared in my previous post.


my code is getting crash within few seconds after calling xQueueSendToBackFromISR

Posted by eldar123 on February 16, 2017

Hi, Did you find any solution to this? I'm trying to find a bug in some old software which looks very much like what you are describing. I am using MCS9S12XEQ512 running FreeRTOS 8.1.2 and the "CW/OAF" HCS12X port version. The task context switching works fine as long as there is no other IRQs. Once I enable other (timer) interrupts which don't even call any FreeRTOS functions, the application crashes after a while at random places with smashed stack. Something seems to go wrong with the portSAVECONTEXT / vTaskSwitchContext / portRESTORECONTEXT when there are more pending interrupts waiting at the same time as a context switch (i.e. jumping to another ISR after context switch in vPortTickInterrupt). We are not using nested interrupts.


my code is getting crash within few seconds after calling xQueueSendToBackFromISR

Posted by eldar123 on February 22, 2017

Hi, In my case, the solution was to add the "D/E/G/P/R PAGE Register is used" in CW/Compiler/Code Generation (HC12 Compiler options : "-CpDPAGE -CpGPAGE -CpEPAGE -CpPPAGE -CpRPAGE") for all other interrupts. I didn't find it documented anywhere, but the compiler will then add the assembly instructions to save/restore the mentioned registers when entring/exiting any ISR. Also I am using the portYIELD (swi) only, also from ISR's (ISRs are using stack). Many of the ISR are using xQueueSendToBackFromISR and other FreeRTOS calls. After this change, no more crashes have been recorded. Regards

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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists