cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F767 LWIP + MQTT

sne_123
Associate III

Hello Everyone,

I am using LWIP and Mqtt drivers on stm32f767. I am able to successfully connect to MQTT broker and able to publish data also. But after publishing some 45 json strings , the device gives me "out of memory error " and "mem_malloc: could not allocate 64 bytes" . I am not understanding why this is happening. The string length which I am posting is approx 580 bytes. The configuration inside the drivers is as follows:-

#define MEM_LIBC_MALLOC         0 

#define MEMP_MEM_MALLOC         1 

#define MEM_SIZE            64000

#define MEMP_OVERFLOW_CHECK       2 

#define MEMP_SANITY_CHECK        1 

#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1

#define MEMP_NUM_PBUF         16 

#define MEMP_NUM_SYS_TIMEOUT      13

#define PBUF_POOL_SIZE         256

#define TCP_MSS            536

#define TCP_SND_BUF          (2 * TCP_MSS)

#define PBUF_POOL_BUFSIZE       1600 

#define LWIP_NETIF_LINK_CALLBACK    1 

#define MQTT_OUTPUT_RINGBUF_SIZE   1024  

and the error log is as follows:-

inside example_do_connect

mqtt_client_connect: Connecting to host: 34.56.200.45 at port:1883

tcp_enqueue_flags: queueing 78946:78947 (0x2)

tcp_output_segment: 78946:78946

JSON string is {"UID": "abc2345", "PV01": "0.00", "PV02": "0.00", "PV03": "0.00", "PV04": "0.00", "PV05": "1.00", "PV06": "1.00", "PV07": "1.00", "PV08": "1.00", "PV09": "0.00", "PV10": "0.00", "PV11": "0.00", "PV12": "0.00", "PV13": "0.00", "PV14": "0.00", "PV15": "0.00", "PV16": "0.00", "PV17": "230.25", "PV18": "230.13", "PV19": "230.32", "PV20": "230.28", "PV21": "0.00", "PV22": "0.00", "PV23": "0.00", "PV24": "0.00", "PV25": "50.06", "PV26": "0.00", "PV27": "0.00", "PV28": "0.00", "PV29": "0.00", "PV30": "0.00", "PV31": "0.00", "PV32": "0.00", "datetime": "2021-04-04 10:16:48"}

mqtt_publish: Publish with payload length 576 to topic "aeplIN/abc2345/data"

mqtt_output_send: tcp_sndbuf: 1072 bytes, ringbuf_linear_available: 672, get 0, put 672

tcp_write(pcb=2000535c, data=20013494, len=672, apiflags=1)

seglen = 536, optlen = 0,mss_local = 536tcp_write: queueing 78947:79483

seglen = 136, optlen = 0,mss_local = 536tcp_write: queueing 79483:79619

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

mem_malloc: could not allocate 1692 bytes

mem_malloc: could not allocate 1692 bytes

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

tcp_output_segment: 78946:78946

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output_segment: 78946:78946

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

tcp_output_segment: 78946:78946

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

tcp_output_segment: 78946:78946

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

tcp_output_segment: 78946:78946

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

mem_malloc: could not allocate 1692 bytes

tcp_output: nothing to send (00000000)

tcp_output_segment: 78946:78946

mem_malloc: could not allocate 1692 bytes

mqtt_tcp_err_cb: TCP error callback: error -13, arg: 200133a4

mqtt_connection_cb entered

status is 256

mqtt_connection_cb: Disconnected, reason: 256

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: sending ACK for 451580163

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

tcp_output: nothing to send (00000000)

************************************************************************************

inside example_do_connect

mqtt_client_connect: Connecting to host: 34.56.200.45 at port:18973

tcp_enqueue_flags: queueing 82074:82075 (0x2)

tcp_output_segment: 82074:82074

JSON string is {"UID": "abc2345", "PV01": "0.00", "PV02": "0.00", "PV03": "0.00", "PV04": "0.00", "PV05": "1.00", "PV06": "1.00", "PV07": "1.00", "PV08": "1.00", "PV09": "0.00", "PV10": "0.00", "PV11": "0.00", "PV12": "0.00", "PV13": "0.00", "PV14": "0.00", "PV15": "0.00", "PV16": "0.00", "PV17": "227.79", "PV18": "227.67", "PV19": "227.84", "PV20": "227.80", "PV21": "0.00", "PV22": "0.00", "PV23": "0.00", "PV24": "0.00", "PV25": "50.05", "PV26": "0.00", "PV27": "0.00", "PV28": "0.00", "PV29": "0.00", "PV30": "0.00", "PV31": "0.00", "PV32": "0.00", "datetime": "2021-04-04 10:17:34"}

mqtt_publish: Publish with payload length 576 to topic "aeplIN/abc2345/data"

mqtt_output_send: tcp_sndbuf: 1072 bytes, ringbuf_linear_available: 672, get 0, put 672

tcp_write(pcb=2000535c, data=2001398c, len=672, apiflags=1)

seglen = 536, optlen = 0,mss_local = 536mem_malloc: could not allocate 64 bytes

tcp_create_segment: no memory.

mqtt_output_send: Send failed with err -1 ("Out of memory error.")

Can someone please help me solve this issue.. Requesting for some help

6 REPLIES 6

<deleted>

@Vangelis Fortounas​  why did you delete? :(

hello

I think something else consumes memory by "not freeing buffers" inside a TCP/UDP callback.

These clues are not enough to understand the possible reason of memory leak. maybe an HTTPD callback?

Thank you but I am not using HTTPd...I guess buffers are freed inside the drivers.. do I manually need to free the buffers?

sne_123
Associate III

@Vangelis Fortounas​  Hello SIr.. I guess clearing buffers won't help, i need to reinitialize lwip stack so that all the b uffers are cleared properly.. is this correct way to go?? If yes the what will be the steps to deinitialize lwip and the reinitialize it again??

sne_123
Associate III

Is there any way to clear all buffers of LWIP?