Quality RTOS & Embedded Software

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


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) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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