This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Hard Fault in rt_sem_wait

Hi,

I have a an application crashing due to a hard fault. When I inspect the PC it tells me that the function being executed is the RTX function rt_sem_wait. The signature of this function is:

extern OS_RESULT rt_sem_wait (OS_ID semaphore, U16 timeout);

I am assuming that the only source of error which could result in a hard fault is the semaphore being invalid in some way, i.e. not a semaphore or corrupted (?).

The problem we are facing is a suspected heap corruption and our thinking is that the corruption happens to be hitting a semaphore somewhere. This semaphore then gets passed to rt_sem_wait and the hard fault is generated.

If anyone can offer any gems / general advice on any aspect of this problem I would be very appreciative - the heap corruption is proving very hard to find and our only definite feedback is a repeatable hard fault inside this function (and always this function).

TIA

Andy

  • Hi Again,

    Further investigation is showing that when os_sem_wait is called and the service call is made, the stack contains the correct values, i.e. the arguments to the function : a semaphore and a timeout value.

    When rt_sem_wait gets executed, the timeout value is correct, but the semaphore value is no longer valid - its has changed from a semaphore to 0x00000001 (always).

    Bsaically what I have is

    thread_main ()
    { OS_SEM sem os_sem_init (sem)

    while (1) { os_sem_wait (sem, 3)

    // do stuff }
    }

    When the value of the semaphore is altered (on the stack) the rest of the stack contents look OK.

    Any thoughts?

    Regards

    Andy