chalamel wrote on Sunday, November 26, 2017:
Hello. I am experiencing an issue using FreeRTOS with LwIP that I am having a hard time understanding. For what is worth, I am not an experienced C developer, nor FreeRTOS user, so I apologize if I am doing something obviously incorrect. I am developing my application on a MicroBlaze processor on an Xilinx Artix7 device.
The application receives data via two interfaces: UART and Ethernet, but only one is in use at any time (if UART is in use, the threads used by LwIP are not started and vice versa). For the latter I am using TCP/IP LwIP with DMA. Messages that arrive to the unit are of varying size, and for that reason I am using dynamically allocated memory as the size of these messages are not known before-hand. In the thread that receives data, I allocate memory to buffer a complete message once the size is known using pvPortMalloc. The message is stored using this memory, and a pointer to the memory sent to the thread that processes the message via a queue. Once processing is complete, the memory is freed using vPortFree. This seems to work perfectly fine for the UART, but this procedure results in an assertion error after only a few packets (somewhere around 40 bytes in total) have been handled this way in the thread that receives data from a socket via LwIP.
I am using heap4 and the actual assertion error is on line 236, which states:
configASSERT( ( ( ( sizet ) pxNewBlockLink ) & portBYTEALIGNMENTMASK ) == 0 );
I have plenty of RAM (several MBs), so the error does not seem related to lack of memory. I also checked this and there’s plenty of heap-space remaining.
The code leading up to this is equal for both the UART- and LwIP receiving threads, and follows this format:
…–After receiving a complete message–…
u8 msgBuffer = (u8)pvPortMalloc((LENGTH)*sizeof(u8));
xQueueSendToBack(ctrlQueue, &msgBuffer,(TickType_t) 10);
u8 msg = 0;
if(xQueueReceive(ctrlQueue, &msg, portMAXDELAY ) == pdTRUE)
With the queue being created like so:
ctrlQueue = xQueueCreate(5, sizeof(u8));
I would be grateful if anyone could shine some light on this, or maybe there is a smoother way of passing varying-size packets of data between two threads. Thanks.