cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS queue overflow, configASSERT in MQTT implementation. LwIP-MQTT-STM32H7

ngrigoriadis
Associate III

Hello,

I hope everyone are doing well!

I have implemented MQTT protocol in an STM32H7 microcontroller that is attached on a display. For that reason I have use the subscribe method in order to receive payloads from 6 different topics, which two of them has large bytes because they have JSON form. During its normal operation, it appears the exact data on the screen and it is working correctly, it stops working (ping returns "can't reach destination" and also MQTT stops working) by giving me an 

 

configASSERT( pxQueue->uxItemSize == 0);

 

 in the function xQueueSemaphoreTake as the figure showing below:

bug.png

I am not able to understand what is the problem, before that due to the reason that the two payloads was so large the xQueue was being overwritten and this configASSERT was appearing again, but the problem was that 

 

uxLength and uxMessagesWaiting

 

had a big number that was not normal. This problem I was able to solve it by increasing TCPIP_STACK_SIZE in lwipopts.h. Although this problem now I can't figured it out how to solve and I ensure to you that I have tried a lot of things that didn't work. I really need help and I would appreciate if you give me a hint. 

Let me declare some things below that might needed for you:

This is my lwipopts.h file :

lwipopts.h.png

and this is my MPU_Config function:

mpu.png

4 REPLIES 4
DK.7
Senior

Have you found a solution?
I'm asking because I have a similar project on STM32F767ZI, and I'm also working with large JSON sizes. However, unlike your project, I'm sending them by mqtt.
But after about one hour everything stops working!

ngrigoriadis
Associate III

Hello @DK.7,

I have successfully used the ETH peripheral on STM32H7 microcontroller and worked with MQTT broker handling large json strings in subscription mode and also I have managed to make it work without any hardfault and it is still working. I can help you with the project! 

I would be very grateful! Can we meet in a voice chat? For example, on Discord or whatever is convenient for you? In Discord, I can enable screen sharing...

ngrigoriadis
Associate III

@DK.7 First and foremost, the LWIP_RAM_HEAP_POINTER must be set like this: 0x30004000. After that it has to be set also to the MPU configuration right above the MPU region size 16KB. Secondly, in order to handle large json data either for publishing them or receiving them you need to increase the size of payload handling in the file "mqtt_opts.h". In there you will find the parameter MQTT_VAR_HEADER_BUFFER_LEN, this parameter is for incoming payloads that they are working with the subscription. I have increased that variable to 2KB (2048B) and also this parameter MQTT_OUTPUT_RINGBUF_SIZE   is used for controlling the payload length that you need to publish. You can update this variable also accordingly to your project. It is crucial to increase the TCPIP_THREAD_STACKSIZE in the "lwipopts.h" file because this stack is used in the incoming payload functions that lwip has. If you receive large payloads it might be corrupted so you have to increase that variable too. Now the important part is to make the project work independent  without any corruption or a hardfault error. For this action you have to increase the stack  which is the INTERFACE_THREAD_STACK_SIZE both to lwip.c file and also to the ethernetif.c file. I have noticed that after a while in my project a hardfault was being generated and the responsible for that operation was a low value into this stack that had been generated automatically from cubeMX.