Queue only receiving first 32 bits of structure

Hi to all! I’m struggling with something and maybe some of you can help-

I’m trying to send a data structure to a Queue from an ISR and then reading it in a task to process it, but only some of the data is being received.

The data structure is this one;

struct DatosCANQ

{

CAN_RxHeaderTypeDef CAN_RxHeaderQ;

uint8_t CAN_RxBufQ[8];

};

The queue initialization:

osMessageQDef(CAN1Queue, 16, sizeof(struct DatosCANQ));

In the IT file I’m defining the data structure again, since “extern struct DatosCANQ” isn’t working properly for some reason

struct DatosCANQit

{

CAN_RxHeaderTypeDef CAN_RxHeaderQ;

uint8_t CAN_RxBufQ[8];

}CANRcv;

Then in the IRQ handler I’m doing this:

CAN_Status=HAL_CAN_GetRxMessage(&hcan1,CAN_RX_FIFO0,&CANRcv.CAN_RxHeaderQ,CANRcv.CAN_RxBufQ);

if(CAN_Status==HAL_OK)

{

xQueueSendFromISR(CAN1QueueHandle, (void *)&CANRcv, &xHigherPriorityTaskWoken);

}

The ISR is firing properly (checked)

Then in the reading task I define the structure (yet once more for the same issue)

struct DatosCANQt

{

CAN_RxHeaderTypeDef CAN_RxHeaderQ;

uint8_t CAN_RxBufQ[8];

}StrCAN;

And then:

for( ; ; )

{

xStatus=xQueueReceive(CAN1QueueHandle,&StrCAN,portMAX_DELAY);

if(xStatus==pdPASS)

{

memset(DirectCANBufMob1,0,sizeof(DirectCANBufMob1));

sprintf(DirectCANBufMob1,"%X,%02X%02X%02X%02X%02X%02X%02X%02X-",StrCAN.CAN_RxHeaderQ.StdId,StrCAN.CAN_RxBufQ[7],StrCAN.CAN_RxBufQ[6],StrCAN.CAN_RxBufQ[5],StrCAN.CAN_RxBufQ[4],StrCAN.CAN_RxBufQ[3],StrCAN.CAN_RxBufQ[2],StrCAN.CAN_RxBufQ[1],StrCAN.CAN_RxBufQ[0]);

xQueueGenericSend(UARTQueueHandle,(void *)&pcMessage1,10,queueSEND_TO_BACK);

}

}

The second Queue (UART) is tested and works properly and I’m receiving StrCAN.CAN_RxHeaderQ.StdId without problems, but the data bytes are always 0 even if I delete the sprintf and send some bytes to UART directly

I’ll appreciate any help.

Thanks in advance!

I’m not familiar with this function so don’t see how the FreeRTOS queue is being created or its handle stored. Does the third parameter set the size of each element in the queue? (You seem to be mixing two different APIs - CMSIS and the native FreeRTOS APIs.)

If you pause the debugger on this line and view the CANRcv variable, does it contain the expected data?

Step into this function in the debugger. When you are on this line https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/master/queue.c#L1284 view pxQueue variable to see what pxQueue->uxItemSize is set to - does it equal sizeof( DatosCANQ )?

First of all, your comment was life saving. Thanks a lot.
I was indeed mixing CMSIS and freeRTOS APIs. I’m working with STM32 and CubeMX and the initialization of the Queue was created by CubeMx. I looked at CMSIS documentation and osQueues are only for 32 bit data types (pointers or variables, but not structures).
Oddly it didn’t complain about the size of the structure.
The CANRcv variable does indeed contain the right data, but pxQueue->uxItemSize was set to 0x04, so it was never going to work properly.
I changed the Queue creation to:

CAN1QueueHandle2=xQueueCreate( 16,sizeof(struct DatosCANQ) );

And that was all I took to work properly. Send and Receive functions are the same as before.
Thanks a lot again!