AnsweredAssumed Answered

Mutex never received

Question asked by lampe.julian on Nov 19, 2016
Latest reply on Nov 21, 2016 by Chris T
Hey guys,

I'm having some problems with mutexes. I'd like to take a mutex but could never obtain it. Not even directly at startup.

my function looks like this

01.USB_ERROR_LIST create_usb_write_request(USB_TOTAL_PACKET_T data)
02.{
03. 
04.if (mutex_send_queue != NULL)
05.    {
06.        BaseType_t mutex_received =  xSemaphoreTake(mutex_send_queue,  timeout);
07.        if (mutex_received == pdTRUE)
08.        {
09.            //Mutex received.... do stuff
10.            //return mutex
11.             xSemaphoreGive(mutex_send_queue);
12.        }
13.        else
14.        {
15.        usb_error = USB_ERROR_MUTEX_NOT_RECEIVED;
16.        }
17.else
18.{
19.usb_error = USB_ERROR_MUTEX_NULL;
20.}


The return value is always Mutex not received.

Now I've checked the usual suspects.
The Mutex is requested only in this function. I did set a breakpoint after
xSemaphoreTake() but this function always returns 0. I even tried to increase the timeout to 2s but no change.

It seams the is something wrong with my mutex.
The mutex is initialised in another thread with

01.void USB_init_task(void * pvParameters)
02.{
03.mutex_send_queue = xSemaphoreCreateBinary();
04. 
05.for (;;)
06.    {
07.       //all init done, we can go to sleep....
08.        vTaskSuspend(NULL);
09.    }
10.}


This is the correct way to initialise a mutex right?

Outcomes