"panic: Unable to Pend on ThreadX Semaphore" shown in STDIO console

When debugging my code on the Connect ME, I get the following message, and the firmware stops running.

“panic: Unable to Pend on ThreadX Semaphore, in file tfKernelPendCountSem, line number 0”

Has anyone else seen this message, and if so, how did they fix it?

I’m using a binary semaphore (tx_semaphore_get with TX_NO_WAIT/tx_semphore_put) as a simple way to lock variables. Is there another mechanism I should use? Mutexes, perhaps?

I had done some analysis on different crashes and the symptoms they cause. From what I saw the message you display can be caused by one of the following:

ARM7 processor:
Global buffer overflow

ARM9 processor:
stack buffer underflow
malloced buffer underflow
global buffer underflow

In most cases you have some code that is writing where it should not be writing and as a result you have trashed something vital.

After some further debugging, this seems to be happening in calls to sendto. I’ll investigate some more to make sure I’m not overflowing a buffer or something.

I had one other thought. Do you have any large buffers placed on the stack as opposed to malloced? If your stack size is small relative to variables you place on the stack, you can cause weird crashes that are hard to find. Sometimes you can get around them by changing any buffers you have from stack variables to malloced variables (I did this to myself just this morning). Remember to clear out such malloced variables before use.