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];


Then in the IRQ handler I’m doing this:




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];


And then:

for( ; ; )







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!