This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/EK-TM4C1294XL: Problem getting a pbuf?

Part Number: EK-TM4C1294XL

Tool/software: Code Composer Studio

I have the following code

#include <stdint.h>
#include <stdbool.h>
#include <string.h>

#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/flash.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/timer.h"
#include "drivers/pinout.h"

#include "lwip/udp.h"
#include "utils/locator.h"
#include "utils/lwiplib.h"
#include "utils/uartstdio.h"
#include "utils/ustdlib.h" 


void main() {
  struct pbuf *pdat;

  do {
    pdat = pbuf_alloc( PBUF_TRANSPORT, 100, PBUF_RAM);
  } while (pdat==NULL);

.. further code .. }

The program never leaves the loop. I.e. I do not get a pbuf allocated!

What am I missing?

  • What is in the Memory options section of the lwipopts.h file used by the project?

    Looking at the ent_lwip project from TivaWare 2.2.0.295 shows the following in lwipopts.h which allocates 64K of memory for lwip, in the ram_heap static array:

    //*****************************************************************************
    //
    // ---------- Memory options ----------
    //
    //*****************************************************************************
    //#define MEM_LIBC_MALLOC                 0
    #define MEM_ALIGNMENT                     4
    #define MEM_SIZE                          (64 * 1024)
    //#define MEMP_OVERFLOW_CHECK             0
    //#define MEMP_SANITY_CHECK               0
    //#define MEM_USE_POOLS                   0
    //#define MEMP_USE_CUSTOM_POOLS           0

  • Hi Chester,

      Thanks. Perhaps the poster can also check the stack size. 

  • In lwipopts.h I have the same lines as Chester Gillon shows. (64k)

    I have version 2.1.4.178, however. And 2.2.0.295. Not quite sure, which one is in use.

    As far as I can see, that file has NOT been included! (unless by some of the others)

    As to the question from Charles Tsai:

    Stack size (Arm Linker - Basic) says 512.

    Same place Heap is set to 0!?

    A try setting the heap to 2.048 or 100.000, or raising the stack to 5.120 does not help.

    (European 1.000 indicator) :-)

  • Ja Hv said:
    The program never leaves the loop. I.e. I do not get a pbuf allocated!

    The code fragment shows pbuf_alloc being called before lwIPInit has been used to initialise the lwIP library.

    In the code below two calls to pbuf_alloc were added to the main of the ent_lwip example, where pbuf_alloc was called before and after the lwIP library had been initialised:

        struct pbuf *volatile pdat;
        pdat = pbuf_alloc( PBUF_TRANSPORT, 100, PBUF_RAM);
    
        //
        // Initialize the lwIP library, using DHCP.
        //
        lwIPInit(g_ui32SysClock, pui8MACArray, 0, 0, 0, IPADDR_USE_DHCP);
    
        pdat = pbuf_alloc( PBUF_TRANSPORT, 100, PBUF_RAM);
    

    The pbuf_alloc call prior to lwIPInit returned NULL. Whereas the pbuf_alloc call after lwIPInit returned a non-NULL pbuf (i.e. the allocation was successful).

  • Yes!

    I had that lwIPInit statement in my setup, but setup was commented out. I am using static IP, but otherwise...

    Now I get a buffer.

    On to the next hurdle.