cancel
Showing results for 
Search instead for 
Did you mean: 

Problem after sending a few MQTT messages with FreeRTOS and LwIP on STM32F406VGTX

lealoureiro
Associate II

Hi Guys,

I would check if someone could help me here with a small projecting I'm trying to build.

I have project that sends MQTT (from LwIP) messages periodically using 3 CMSISv2 tasks (i send them with different time intervals, some with 1s and others with 5s).

The messages have approximately the following sizes: 9, 58 and 362 chars.

After sending some of them, all of them stop being sent :(

The piece of code where the code seems to occur is in the LwIP libraries, mqtt.c:

  r = mqtt_create_request(client->req_list, LWIP_ARRAYSIZE(client->req_list), pkt_id, cb, arg);
  if (r == NULL) {
    return ERR_MEM;
  }

I tried to disable the task that sends the biggest message and seems to work fine (didn't tested for more than 1/2 hours)

I also added a Mutex to make sure only one task at time is sending a message (not sure if it helps).

Some more info regarding the configuration configure in CubeMX:

Thread Stack Sizes: 2048

FreeRTOS Heap Size: 30760

LwIP MEM SIZE: 16360.

Not sure what other values could be relevant to try help solve the problem.

Thanks in advance,

Leandro

3 REPLIES 3

So does it fail with a memory error?

Do you have a resource leak when it comes to freeing memory, or double-freeing resources?

Check exit/failure paths.

Perhap wrap the heap allocation/release to monitor for issues there.

Track who is allocating the memory. Match the release of each.

Build something to walk the heap looking for orphans or fragmentation issues.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lealoureiro
Associate II

Yeaps, when the problem starts occurring the if condition evaluates to true.

I think I need to debug a bit more but LwIP code is very complex.

How can i know which version of the LwIP CubeMX uses? Is the latest?

lealoureiro
Associate II

I think i fixed the problem by increasing the priority of the thread task that sends the bigger message and increasing the RING size (MQTT_REQ_MAX_IN_FLIGHT) from 4 to 10.

At least after 2 hours still sending messages normally.