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


cannot take semaphore

Posted by fadillrezha on February 15, 2014

Hi all,

I am a new user of FreeRTOS and currently I am facing a problem related to semaphore. I tried to do some research but I cannot seem to find a similar case like mine.

I am using STM32f407 with STM32 standard peripheral drivers and Keil as development environment. I set an interrupt which can be detected well by my interrupt handler. My code works fine at first, but after some random duration time has passed, suddenly my ISR routine doesn't work anymore. Interrupt is still detected by ISR handler and semaphore is given using xSemaphoreGiveFromISR(), but the interrupt routine cannot be executed because (I think) it cannot take semaphore.

void ISR_handler(){


// code to clear interrupt pending bit here

/* Frame received */
/* Give the semaphore to LwIP task (ISR routine) */
xSemaphoreGiveFromISR(s_xSemaphore, &xHigherPriorityTaskWoken);  

} }

void ISR_routine( void * pvParameters ){ struct pbuf *p;

for( ;; ){ if (xSemaphoreTake( sxSemaphore, 100tick)==pdTRUE){

    /* Interrupt Routine start */
    p = low_level_input( s_pxNetIf );  
    if (p != NULL){
          if (ERR_OK != s_pxNetIf->input( p, s_pxNetIf)){
    /* Interrupt Routine end */
} //if 

} //for }

The semaphore that I use is counting semaphore. After the error occur, I have checked that ISRhandler is still generated and xSemaphoreGivefromISR is still executed. However, the infinite loop on ISRroutine is not executed. I have checked the stack size of my ISR routine task and stack overflow is far from happening.

I have debugged this problem for a couple of days now, but I cannot seem to come to a conclusion. Please advise or give me suggestion to find out the general reason that a semaphore cannot be taken by xSemaphoreTake.


cannot take semaphore

Posted by rtel on February 15, 2014

What value does xSemaphoreGiveFromISR() return?

Do you have your interrupt priorities set correctly: http://www.freertos.org/RTOS-Cortex-M3-M4.html


cannot take semaphore

Posted by fadillrezha on February 17, 2014

You are right! That link you posted was really useful. Internet priority was the problem because the STM32 driver library does not follow the default configuration. Had I known that link before I wouldn't spend so much time to debug this.

Thanks for your help!!

[ 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