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

Reasons why semaphore stops to work

Posted by kyle-shneider on June 2, 2017

I use semaphore technology in uart (rs485) packet parser in stm32l151 mc project. xSemaphoreGiveFromISR from uart '"recieve line idle" interrupt starts parser. After forming an answer packet task waits for "transmit end" interrupt with xSemaphoreGiveFromISR that gives the same (!) semaphore. After that task returns in recieve mode and waits for recieve semaphore. Problem: after few hours of work I detect semaphore fail. The task just freezes. I see xSemaphoreGiveFromISR execution, but xSemaphoreTake doesn't execute. Besides uart parser task there're another tasks working (they have mutex hold inside). I've tested programm work without them - no semaphore fail. What problem can it be? I've checked unallocated memory for FreeRTOS - about 600 words (or bytes). No stackoverflow, no mallocfail. May be there some memory leak? May I should separate semaphores for recieve and trancieve? Help me detect an error.


Reasons why semaphore stops to work

Posted by rtel on June 2, 2017

When you say, maybe there is a memory leak, where are you allocating and freeing memory? FreeRTOS will not be allocating and freeing unless you are creating and deleting objects (dynamically, rather than statically) at run time.

Normally problems such as your are due to invalid interrupt priorities. Do you have configASSERT() defined - best to use a recent version of FreeRTOS too as recent versions perform more assert checks.


Reasons why semaphore stops to work

Posted by kyle-shneider on June 5, 2017

Thanks for answer! What do you mean by "invalid interrupt priorities"? For uart and dma (didn't mention that I use dma transfer) I have priority 3. How configASSERT will help to find reason why semaphores stop to work?


Reasons why semaphore stops to work

Posted by rtel on June 5, 2017

http://www.freertos.org/FAQHelp.html http://www.freertos.org/RTOS-Cortex-M3-M4.html


Reasons why semaphore stops to work

Posted by kyle-shneider on June 7, 2017

Thanks, it were wrong priority settings. UART works stable now. But another problem appeared: now low priority tasks (lower than uart parser task) freeze after some time. There are no more interrupts beside dma and uart.


Reasons why semaphore stops to work

Posted by richard_damon on June 7, 2017

The biggest reason I have seen for low priority tasks not running is that a higher priority task starves them by not blocking. EVERY task (except the Idle task, and possible other Idle Priority tasks) should block on sometthing if not actively doing useful work. Polling loops and the like do not belong in an application running under a RTOS. If you need such a loop, it really must be in an Idle priority task, and either enable time-slicing or put a Yield in the loop.

Does the uart parser task block on a queue/semaphore waiting for more characters? or is it in a busy loop checking for data.

Remember, unlike some general purpose OSes, lower priority doesn't mean give a lower share of CPU time, but they are put at the back of the line to get the CPU, and higher priority tasks get to 'cut' the line. The running task is always of the highest priority that has a ready task.


Reasons why semaphore stops to work

Posted by kyle-shneider on June 7, 2017

No, I block all tasks with vTaskDelay or Semaphore/Mutex take.


Reasons why semaphore stops to work

Posted by richard_damon on June 8, 2017

A semaphore or muutex won't block if the resource is available, so you could still starve a lower priority task, if your loop is just taking semaphores/mutexes.


[ 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