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




Loading

xSemaphoreTake() got stuck

Posted by zohargolan365 on March 22, 2016

HI all,

I have a problem with xSemaphoreTake() in FreeRTOS 8.2.0 (and 8.2.3) port for Freescale Kinetis (using Mcu on Eclipse component). The problem is that I have an interrupt with priority 8 which is giving a binary semaphore

/* ** =================================================================== ** Event : EInt1OnInterrupt (module Events) ** ** Component : EInt1 [ExtIntLDD] / /! ** @brief ** This event is called when an active signal edge/level has ** occurred. ** @param ** UserDataPtr - Pointer to RTOS device ** data structure pointer. / / ===================================================================/ void EInt1OnInterrupt(LDDTUserData *UserDataPtr) { / Write your code here ... */ uint32_t error;

portBASE_TYPE higherPriorityTaskWoken = pdFALSE;

// Set semaphore error = xSemaphoreGiveFromISR(MySemaphore, &higherPriorityTaskWoken);

// Activate the task immediately if priority is higher portENDSWITCHINGISR(higherPriorityTaskWoken);

}

Then I have a task with priority 8 which is taking the semaphore

for (;;) {

	if(xSemaphoreTake(MySemaphore, (TickType_t) 20) != pdTRUE)
	{
		ThreadSafePrintf("Missed an interrupt.\n");
	}
 	else
	{
 			function();
            vTaskDelay(5);
	}
}

The configMAXSYSCALLINTERRUPTPRIORITY is set to (configLIBRARYMAXSYSCALLINTERRUPTPRIORITY<<(8-configPRIOBITS)) where configLIBRARYMAXSYSCALLINTERRUPTPRIORITYis set to 5

This mechanism is working fine for long time (anywhere from 10 minutes to several hours) and then the function stops executing.

if I am printing the tasks state (using vTaskList), I see that the task is in running stste. The external interrupt is keep running correctly and when the semaphore is given, the result of the xSemaphoreGiveFromIsr is false.

The RTOS will get from this weird state only if I will run a higher priority task (priority 9) which has a vTaskDelay(1) in it. Once the vTaskDelay(1) is executed, the scheduler is switching back to the stuck task and execution proceed as normally.

Please advise as I am desperate Best regards, Z


xSemaphoreTake() got stuck

Posted by rtel on March 22, 2016

Is this using the port layer files from the FreeRTOS distribution which has the vPortValidateInterruptPriority() function? (see https://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c). If so, then defining configASSERT() will help catch interrupt priority issues. Do you have configASSERT() defined?


xSemaphoreTake() got stuck

Posted by zohargolan365 on March 22, 2016

Thank you for your response

Looks like this portion of the code in port.c is commented out

~~~~

if 0 /* NYI / && configCPUFAMILYISARMM4(configCPU_FAMILY) / ARM M4(F) core */
if( configASSERT_DEFINED == 1 )

/* * Used by the portASSERTIFINTERRUPTPRIORITYINVALID() macro to ensure * FreeRTOS API functions are not called from interrupts that have been assigned * a priority above configMAXSYSCALLINTERRUPT_PRIORITY. */

if ( configASSERT_DEFINED == 1 )
 static uint8_t ucMaxSysCallPriority = 0;
 static uint32_t ulMaxPRIGROUPValue = 0;
 static const volatile uint8_t * const pcInterruptPriorityRegisters = ( const volatile uint8_t * const ) portNVIC_IP_REGISTERS_OFFSET_16;
endif /* configASSERT_DEFINED */
void vPortValidateInterruptPriority( void )
{
uint32_t ulCurrentInterrupt;
uint8_t ucCurrentPriority;

    /* Obtain the number of the curre

~~~~

configAssert() is defined in FreeRTOSConfig.h

~~~~ /* Normal assert() semantics without relying on the provision of an assert.h header file. */

define configASSERT(x) if((x)==0) { taskDISABLE_INTERRUPTS(); for( ;; ); }

~~~~

What else can I try?

Thanks Z


xSemaphoreTake() got stuck

Posted by rtel on March 22, 2016

So the whole thing is taken out by a

#if 0

?

What happens if you put it back in, or try using the file I linked to in my previous post? Failing that perhaps you could ask the vendor why it is taken out?


xSemaphoreTake() got stuck

Posted by zohargolan365 on March 22, 2016

I guess there is a reason why it is taken out. I will try to put it back and clean the bad connections. Do you have other suggestion of how to debug the semaphore problem? I must get this thing resolved ASAP


xSemaphoreTake() got stuck

Posted by zohargolan365 on March 22, 2016

Hi,

OK, so I went back to the project with the FreeRTOS 8.2.3. In this project the vPortValidateInterruptPriority is defined and the configAssert is also defined. What do I need to do to get the information on the interrupts? the program is not getting stuck in the configAssert macro, so I guess it is not an interrupt issue. Am I correct?

Thank you, Z


xSemaphoreTake() got stuck

Posted by zohargolan365 on March 23, 2016

All,

Here is what I have to do in order to fix this problem. It sounds like a bug in the FreeRTOS to me. I had to create a bogus task with high priority. This task looks like

~~~~ void TaskBogusIdle(void* pdata) { while(1) { vTaskDelay(5000); } } ~~~~

Essentailly it does not do anything, but it makes sure the RTOS is not loosing the semaphore. I really would like to get some help from real time engineering on this issue, as I dont think this is the right way to go

Best regards Z


xSemaphoreTake() got stuck

Posted by rtel on March 23, 2016

No, this is definitely not the right way to do it. What's more, this is almost certainly just disguising the problem, as the problem should not exist in the first place.

First, to make sure we are talking about the same thing here and are actually able to support you - is the code you are using now the official 8.2.3 code, unmodified? If you think this is the case, please diff all the code in the FreeRTOS/Source directory between your project and the main V8.2.3 release to be sure.

Once verified that the code is indeed the same, please cut your application down to the absolute minimum that exhibits this behaviour so we can try and find out what is going on. Basically, just the skeleton of the tasks and interrupts that are needed to reproduce the issue. Then attached the skeleton code to your next post in a zip file.

Many years of experience of this type of support request shows it is normally (nearly always) a configuration error, but in V8.2.3 the asserts() would normally catch those, so if the asserts are not catching the problem then it is more interesting.

Please also attach your FreeRTOSConfig.h.


xSemaphoreTake() got stuck

Posted by davedoors on March 23, 2016

before doing that look at the first post again.

if I am printing the tasks state (using vTaskList), I see that the task is in running stste. The external interrupt is keep running correctly and when the semaphore is given, the result of the xSemaphoreGiveFromIsr is false.

Only the task that called vTaskList should show as running. No other task can be running otherwise vTaskList can not be called.

If the task is running but not taking the semaphore then it can only be in the function() function (referring to the code in your first post).

You call vTaskDelay(5) so will miss interrupts if they come in faster than every 5 ticks.


xSemaphoreTake() got stuck

Posted by zohargolan365 on March 23, 2016

Hi Dave,

Thank you for your post. First the vTaskDeleay(5) is a non problem as the interupt is longer (20ms). Second, I spent a wee to test and retest and tripple test. The function is finishing the execution. The RTOS still thinks its in running state, but the function exited already. Well, I will try the real time engineering suggestion Thanks, Z


xSemaphoreTake() got stuck

Posted by zohargolan365 on March 23, 2016

The code is a port for kinetis devices from MCUonEclipse component. Released on february 2016. I will try the diff to the source and see if I can find anything. I dont think I will have enough time to do that, as I have 2 projects that needs to be finished this month. I will update the post when I will have time.

Best regards, Z


[ 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