Queue problem with esp32 and platformio arduino framework

Hi forum… I am working with esp32 and platformio using freertos OS.

I have already worked with queues but now I am getting a crash of the system calling
this

 if (xQueueReceive(report_queue_from_uart_to_wifi,(void *) &report_struct_receive, 0) == pdPASS)

Here all the code…

Definition of the struct

typedef struct report_t
{
    uint16_t machine_id;
    uint16_t report_id;
    tm init_time;
    tm end_time;
    uint16_t duration;
} report_t;

where tm is defined in file time.h in the folowing way …

struct tm
{
  int	tm_sec;
  int	tm_min;
  int	tm_hour;
  int	tm_mday;
  int	tm_mon;
  int	tm_year;
  int	tm_wday;
  int	tm_yday;
  int	tm_isdst;
#ifdef __TM_GMTOFF
  long	__TM_GMTOFF;
#endif
#ifdef __TM_ZONE
  const char *__TM_ZONE;
#endif
};

Creation of the struct variable

report_t report_struct;
UBaseType_t queue_lenght = 10;         /*optimal value to be defined*/

Creation of the queue

/**
 * @brief  Function to create the queue for exchanging data between Wifi and uart task
 * @param  None
 * @retval None
 */
void Create_queue_for_exchange_reports_between_uart_and_wifi(void)
{
  report_queue_from_uart_to_wifi = xQueueCreate(queue_lenght, sizeof(report_t));
}
/**

Sending the struct to the queue it is crashing the fw too

    if (xQueueSend(report_queue_from_uart_to_wifi, (void *)&report_struct, 0) == pdPASS)
      {
        /*to do cleaning the structure*/
      }

The problem is also in receiving.

   if (xQueueReceive(report_queue_from_uart_to_wifi, (void *)&report_struct_receive, 0) == pdPASS)
      {

where the struct is defined in this way

report_t report_struct_receive;

What is wrong ?

Thanks a lot for your help

Stack size of the tasks too small ? Seems that the structs are local (stack) variables and require a certain amount (sizeof) of of the stack.
Did you enable stack checking and did you also defined configASSERT helping to catch programming and/or configuration issues.
Oh … and you should really also check the return code/values of the create functions.
If the queue creation failed you’d use an invalid queue handle which is a license to crash.
For example this kind of bug would be catched by having configASSERT defined.

1 Like

Hi i Have tried to increase the stack size of the tasks,… Nothing changed… Are we sure that the definition of the structure is correct ?

How did you create the queue? Did you ensure that your queue variable is != NULL when you execute the receive call?

1 Like
/*machine status topic transmitted only if modbus message is arrived*/
    if (xQueueReceive(state_queue_from_uart_to_wifi, &machine_status_value_from_queue, 0) == pdPASS)
    {
      machine_state_message(machine_status_value_from_queue);
      Serial.println("Transmitted machine status");

      delay(10);
    }
    /*report topic transmitted only if modbus message is arrived*/
    if (xQueueReceive(report_queue_from_uart_to_wifi, (void *)&report_struct_receive, 0) == pdPASS)
    {
      send_report_message(report_struct_receive.machine_id, report_struct_receive.report_id, report_struct_receive.init_time,
                          report_struct_receive.end_time, report_struct_receive.duration);

      Serial.println("Transmitted report topic");

      delay(10);
    }

The first case is working but i am passing an array … the second case is where I get the issue passing the struct

the creation is here

/**
 * @brief  Function to create the queue for exchanging data between Wifi and uart task
 * @param  None
 * @retval None
 */
void Create_queue_for_exchange_reports_between_uart_and_wifi(void)
{
  report_queue_from_uart_to_wifi = xQueueCreate(queue_lenght, sizeof(report_t));
}

What A stupid
It was missing the call in the main.cpp

Create_queue_for_exchange_reports_between_uart_and_wifi();