Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

FreeRTOS+LWIP client stops running (task seems to die)

Posted by slam7211 on July 26, 2017

Basic details first, I am running FreeRTOS version 8.2.0 on a FRDM K64f board. I am using LWIP for an ethernet stack. I know there is FreeRTOS+TCP, but I don't see an implementation for my MCU, and I had a demo I could work with that used LWIP/ The device recieves new data via an interrupt every 1ms. The data is put into a circular queue in the interrupt. I have one (manually created) task that runs in non interrupt time. It essentially reads the queue, if there is data, send it to a server via ethernet Shown Below

:::c
static void tcpecho_thread(void *arg)
{
    for(;;)
    {
        err_t err;
        struct netbuf *Buf = NULL;
        struct netconn *xNetConn = NULL;
        LWIP_UNUSED_ARG(arg);
        netif_set_up(&fsl_netif0);
        xNetConn = netconn_new ( NETCONN_TCP );
        int rc2 = netconn_connect ( xNetConn, &fsl_netif0_gw, 7 );
        while(1)
        {
            if(QueueTop!=QueueBottom)
            {
                Buf = netbuf_new();
                if(QueueTop>QueueBottom)
                {
                    if(QueueTop>QueueBottom)
                    {
                        char * testBuffer = pvPortMalloc(QueueTop-QueueBottom);
                        netbuf_alloc(Buf, QueueTop-QueueBottom);
                        memcpy(testBuffer,&Queue[QueueBottom],QueueTop-QueueBottom);
                        Buf->p->payload = testBuffer;
                        Buf->p->len = QueueTop-QueueBottom;
                        err = netconn_write(xNetConn, Buf->p->payload, Buf->p->len, NETCONN_COPY);
                        netbuf_delete(Buf);
                        vPortFree(testBuffer);
                    }else if (QueueTop<QueueBottom)
                    {
                        char * testBuffer = pvPortMalloc(QUEUESIZEMAX-QueueBottom);
                        netbuf_alloc(Buf, QUEUESIZEMAX-QueueBottom);
                        memcpy(testBuffer,&Queue[QueueBottom],QUEUESIZEMAX-QueueBottom);
                        Buf->p->payload = testBuffer;
                        Buf->p->len = QUEUESIZEMAX-QueueBottom;
                        err = netconn_write(xNetConn, Buf->p->payload, Buf->p->len, NETCONN_COPY);
                        netbuf_delete(Buf);
                        vPortFree(testBuffer);
                    }if(err==ERR_OK)
                    {
                        QueueRemove(Buf->p->len);
                    }
                }
                if (rc2 != ERR_OK || err != ERR_OK )
                {
                    PRINTF("ERROR DELETE CONNECTION");
                    netconn_delete ( xNetConn );
                }
            }
        }
    }
}

After running sucessfully for a minute or so, it just stops working. When I pause the debug session to see what is going on it seems to be stuck in an infinite loop in the backgroud, as if the RTOS is preempting the task somehow. The task is initiated with a priority of three with the following code in my main function:

 :::c
    sys_thread_new("tcpecho_thread", tcpecho_thread, NULL, TCPECHO_STACKSIZE, TCPECHO_PRIORITY);
    OSA_Start();

Any Ideas why? Also, if I should be using FreeRTOS+TCP, is there a basic configuration for my MCU somewhere? What edits would I need to make to the FreeRTOS+TCP code to get it to work?


FreeRTOS+LWIP client stops running (task seems to die)

Posted by rtel on July 26, 2017

It is very hard for us to support moderately complex third party software, such as lwIP, especially as lwIP has its own support mechanisms. In general terms, from your brief description, it sounds like the system is still running but something in your lwIP code is either deadlocked, blocked, or interrupts have stopped. From my experience most issues come from the Ethernet driver, as that is the bit that is different from MCU to MCU, and therefore the least tested. Using something like FreeRTOS+Trace might help you see what is going on.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS