FreeRTOS Queue + STM32F303 + IAR

serj86 wrote on Saturday, August 01, 2015:

Hi !

I use FreeRTOS 7.6.0 generated by CubeMX 4.9.0 with STM32F303 MCU (ARM CM4F) + IAR 6.50 Compiler.

I send sensor L3DG20_Data struct to queue in timer callback function and try to read it in L3GD20_Thread.
After receive from queue, in gyro_raw_data struct L3GD20_AXIS_Z variable is always 0. iar debugger watch
Another two variables in struct transmitted correctly.
What can be wrong there?


typedef struct {
i16_t L3GD20_AXIS_X;
i16_t L3GD20_AXIS_Y;
i16_t L3GD20_AXIS_Z;
} AxesRaw_t;

osMessageQId GyroRawDataQueueHandle;
osTimerId GyroTimerHandle;

void CallbackGyroTimer(void const * argument);
static void L3GD20_Thread(void const * argument);

osTimerDef(GyroTimer, CallbackGyroTimer);
GyroTimerHandle = osTimerCreate(osTimer(GyroTimer), osTimerPeriodic, NULL);

osMessageQDef(GyroRawDataQueue, 16, AxesRaw_t);
GyroRawDataQueueHandle = osMessageCreate(osMessageQ(GyroRawDataQueue), NULL);

static void L3GD20_Thread(void const * argument) {
AxesRaw_t gyro_raw_data;
for(;:wink: {

if( GyroRawDataQueueHandle != 0 ) {
xQueueReceive( GyroRawDataQueueHandle, &( gyro_raw_data ), ( portTickType ) 10 );


void CallbackGyroTimer(void const * argument) {
AxesRaw_t L3DG20_Data;

L3GD20_GetAngRateRaw(&hspi1, &L3DG20_Data);
xQueueSendToBack(GyroRawDataQueueHandle, ( void * ) &L3DG20_Data, ( portTickType ) 0);

rtel wrote on Saturday, August 01, 2015:

You are declaring an AxedRaw_t structure on the stack, filling it with data, then using xQueueSendToBack() to copy the structure into the queue - that should be fine provided the queue was created so each space in the queue can hold an AxesRaw_t structure. However you are creating the queue using a call to GyroRawDataQueueHandle(), and I have no idea what that is doing as it is not a FreeRTOS function. Can you try using xQueueCreate(), so I can see how the queue is being created, as then if you still have a problem I will be able to advise if the queue is being created correctly for how it is being used.


serj86 wrote on Saturday, August 01, 2015:

Thank you for reply.

In fact, it’s CubeMX bug. osMessageCreate() always give a 4bytes queue:
stm forum
If I use xQueueCreate() instead osMessageCreate() (API generated by CubeMX) all data transmitted correctly.