xQueueSend fails to send when any one of other task unrelated to queue running

sasikalaswathi wrote on Friday, October 18, 2019:

Created the queue of size 100,
Send_task1 writes to one of the GPIO pin to high
From send_task 2 to send_task 5, sends the data to queue
Receive_task receives the data from the queue.

Sender code:
xStatus = xQueueSend(Global_Queue,&buffer1,1);
if(xStatus==pdPASS)
{
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_7,0);
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_11,1);
}
When I am running the above project, handles always in send_task1 whenever i am suspending the project.
and the E11 pin is not in high state (Expects the high state when sending to queue was successful) while checking in the scope. This behaviour was same in other sneder tasks also.

Then I changed the code as follows:
xStatus = xQueueSend(Global_Queue,&buffer1,1);
if(xStatus==pdPASS)
{
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_7,0);
}
else if (xStatus==pdFAIL)
{
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_11,1);
}
Then i checked any failures occurs while sending data to queue in functions send_task2 to send_task5. Now the E11 pin is in high state. Here I don’t know why the failures occur during sending data to queue?

This problem is not occurred whenever send_task1 is not included in the project and E11 pin goes to high state after sending successfully to the queue.
Attached the code for reference.

richard_damon wrote on Friday, October 18, 2019:

A couple of comments.

First, I am not sure if HAL_GPIO_WritePin is properly thread safe, and you are changing bits in the same GPIO port in different threads.

Second, did you check the return value on creating all the tasks, especially the receive task. If that failed then the queue will rapidly fill and then all sends will fail.

sasikalaswathi wrote on Friday, October 18, 2019:

Hi Richard, Thanks for the quick reply.

  1. First, I am not sure if HALGPIOWritePin is properly thread safe, and you are changing bits in the same GPIO port in different threads.

When i used the different GPIO pins in each task(avoiding the same pin’s across each task), that case also only send_task1 (writing pin to high), send_task2 and receive task work. While checking the breakpoints of the other sender tasks like send_task3,4 and 5, will try to send to the queue, but sending failed.

I tested sample output via printf, I get the putput like this
GPIO -After send_task1 execution
GPIO
GPIO
GPIO
GPIO
GPIO
S8 - After send_task2 execution
R1- After receive_task executes
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
S8
R1
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO. this values repeats.

  1. Second, did you check the return value on creating all the tasks, especially the receive task. If that failed then the queue will rapidly fill and then all sends will fail.

I checked the return values of all tasks. All are created successfully.