cannot take semaphore

fadillrezha wrote on Saturday, 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( s_xSemaphore, 100_tick)==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 ISR_handler is still generated and xSemaphoreGivefromISR is still executed. However, the infinite loop on ISR_routine 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.


rtel wrote on Saturday, February 15, 2014:

What value does xSemaphoreGiveFromISR() return?

Do you have your interrupt priorities set correctly:


fadillrezha wrote on Monday, 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!!