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.

memory space - are my calculations correct?

Other Parts Discussed in Thread: CC3100

I seem to be bumping against the memory limit for the TM4C, but it doesn't seem like I should be.

If I do:

extern char xmlBuffer[12000];

and I fill it up and print to console, it stops.

If I do:

_u8 *xmlResponse = (_u8*) malloc (1200);

it also stops printing to the UART.

It handles up to around  _u8 *xmlResponse = (_u8*) malloc (1000);

Am I missing something?  I would think there would be more memory available.

  • Hello Kristian,

    Which TM4C device is this: TM4C123 or TM4C129?

    Regards

    Amit

  • Apologies.  TM4C123 Tiva Launchpad

  • Hello Kirstian,

    Might want to look in the map file how much SRAM is being used and if Stack can be increased to see there is not an overwrite. Secondly place the variable as a global instead of a function scope.

    Regards

    Amit

  • It's always a good idea to look at the map file in those cases. But AFAIK, malloc() takes memory from the heap, not from the stack.

    Generally, considering the facts that you MCU has no separate OS, no MMU (virtual memory), nor a HD for swapping, the malloc() function is actually pretty worthless. In fact, you can't leave memory management to an OS (with malloc/free etc.), but rather have to do it yourself - a static memory layout is a property of basically all MCU applications. Like the file IO functions, they are provided with your clib for compatibility/portability, but with limited functionality.

  • Ok, sounds like malloc() is not the way to go.  Good to know.

    I do have the char array statically allocated as a global, but I still can't exceed around 1000 chars.

    I noticed in startup_rvmdk.s that my heap size is zero.  Will increasing the heap size give me access to more memory?

    ;******************************************************************************
    ;
    ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
    ;
    ;******************************************************************************
    Stack EQU 0x00004000

    ;******************************************************************************
    ;
    ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
    ;
    ;******************************************************************************
    Heap EQU 0x00000000

  • Hi,

    Your stack size could be too high, depends on your application. If not using printf/sprintf, start with 1-2K, then you may modify.

    Heap use means malloc or a non-conform use of RAM. Use local variables as much as you can. Check the memory map as said before by other posters.

    Petrei

  • Looks like it could be the printf using UART.  I did some test just viewing memory and not printing and I am storing plenty of chars in memory.

    Pointer to char size[TEST_SIZE];
    char *sizeptr = size;
    Start Address        TEST_SIZE         STORED
    20004190              (1200)                   1199
    20003E70             (2000)                    1999
    20003A88             (3000)                    2999
    20001F00            (10000)                   10047
    2000463F (end address)
    Possible start limit address (max char stored, not sure about this, but when I go lower than 20000001 I get error during runtime.
    20000001 - 17,982
  • Hi,

    Your RAM area starts at 0x20000000 and has 32KB.

    Seems you used non-conventional accessing, starting from top - could you better post some code snippet instead? All memory allocations are managed by the linker.

    Petrei

  • If it is 32kb, divided by 8 bit char, then max is 4k chars.  I can get up to 2500 characters or so in the array.  That could make sense.

    My code is:

    char xmlBuffer[MAX_XML_RESPONSE];

    Everything in the array looks ok until I get to around MAX_XML_RESPONSE 3000.

    I am running a wifi project with the CC3100.  I fill the array like this:

    sl_Recv(SockID, xmlBuffer, MAX_XML_RESPONSE, 0);

    _u8 *tempXML = xmlBuffer;
    //view XML response
    for(i = 0;i < MAX_XML_RESPONSE;i++){
    tempXML++;
    }

  • Nevermind the 4k chars comment.  I was calculating Kb not KB.

  • Posting a more complete code example would be really helpful. It's still not clear (to me) where your array is located (heap or stack).

    The location depends on your declaration, see the following code example:

    static char  arrayOnHeap[SIZE];    // is located on the heap
    const char  arrayInFlash[SIZE];     // is located in Flash (code)
    void someFunction (void) { char arrayOnStack[SIZE]; // is located on stack (bad idea for large arrays !) . . . }

  • I am not using const because I need to change the contents at runtime.  I am not allocating on the stack.  I am using static char arrayOnHeap[SIZE].  Here are some screenshots from my current project and some testing.  The allocation works in a test project, in my project without other code, but does not work where I need it.  Here is the code from the file where the allocation does not work.

    #include "app_data.h"
    #include "connect.h"
    #include "stocks.h"
    #include "mml.h"
    #include "parsexml.h"
    #include "servers.h"
    
    static struct Data{
        UINT32 		DestinationIP;
    } wikiData;
    
    #define MAX_WIKI_BUFFER	10000
    static char wikiBuffer[MAX_WIKI_BUFFER];
    
    void getWikipedia(void)
    {
    		int32_t 	SockID;
    		int i;
    		int count = 0;
    		pal_Memset(&wikiData, 0, sizeof(wikiData));
        SlSockAddrIn_t  Addr;
    		_i16 AddrSize = 0;
    	  _u8 *xmlResponse = (_u8*) malloc (MAX_WIKI_BUFFER * sizeof(_u8));
    
    	/******************************************/
    	/****  Connect and Receive Response  ******/
    	/******************************************/
        sl_NetAppDnsGetHostByName((_i8 *)WIKI_SERVER, pal_Strlen(WIKI_SERVER), &wikiData.DestinationIP, SL_AF_INET);	
    		Addr.sin_family = SL_AF_INET;
        Addr.sin_port = sl_Htons(80);
        /* Change the DestinationIP endianity, to big endian */
        Addr.sin_addr.s_addr = sl_Htonl(wikiData.DestinationIP);
        AddrSize = sizeof(SlSockAddrIn_t);
    	  SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
    		sl_Connect(SockID, ( SlSockAddr_t *)&Addr, AddrSize);		
    		//char *wiki_str = (char*) malloc( strlen(WIKI_GET));
    		//sprintf(wiki_str, "%s", WIKI_GET);
    		sl_Send(SockID, WIKI_GET, pal_Strlen(WIKI_GET), 0);
    		//sl_Recv(SockID, xmlResponse, MAX_XML_RESPONSE, 0);
    		sl_Recv(SockID, xmlBuffer, MAX_WIKI_BUFFER, 0);
    		
    		_u8 *tempXML = xmlBuffer;
     //view XML response		
    		for(i = 0;i < MAX_WIKI_BUFFER;i++){
    			UARTprintf("%c",*tempXML);
    			tempXML++;			
    		}
    		
    		while(1){}
    }

  • Noticed I left my malloc in the previous code.  Here is the code that does still does not work.  I am running to a breakpoint before I print.

    #include "app_data.h"
    #include "connect.h"
    #include "stocks.h"
    #include "mml.h"
    #include "parsexml.h"
    #include "servers.h"
    
    static struct Data{
        UINT32 		DestinationIP;
    } wikiData;
    
    #define MAX_WIKI_BUFFER	10000
    static char wikiBuffer[MAX_WIKI_BUFFER];
    
    void getWikipedia(void)
    {
    		int32_t 	SockID;
    		int i;
    		int count = 0;
    		pal_Memset(&wikiData, 0, sizeof(wikiData));
        SlSockAddrIn_t  Addr;
    		_i16 AddrSize = 0;
    	  //_u8 *xmlResponse = (_u8*) malloc (MAX_WIKI_BUFFER * sizeof(_u8));
    
    	/******************************************/
    	/****  Connect and Receive Response  ******/
    	/******************************************/
        sl_NetAppDnsGetHostByName((_i8 *)WIKI_SERVER, pal_Strlen(WIKI_SERVER), &wikiData.DestinationIP, SL_AF_INET);	
    		Addr.sin_family = SL_AF_INET;
        Addr.sin_port = sl_Htons(80);
        /* Change the DestinationIP endianity, to big endian */
        Addr.sin_addr.s_addr = sl_Htonl(wikiData.DestinationIP);
        AddrSize = sizeof(SlSockAddrIn_t);
    	  SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
    		sl_Connect(SockID, ( SlSockAddr_t *)&Addr, AddrSize);		
    		//char *wiki_str = (char*) malloc( strlen(WIKI_GET));
    		//sprintf(wiki_str, "%s", WIKI_GET);
    		sl_Send(SockID, WIKI_GET, pal_Strlen(WIKI_GET), 0);
    		//sl_Recv(SockID, xmlResponse, MAX_XML_RESPONSE, 0);
    		sl_Recv(SockID, wikiBuffer, MAX_WIKI_BUFFER, 0);
    		
    		_u8 *tempXML = wikiBuffer;
     //view XML response		
    		for(i = 0;i < MAX_WIKI_BUFFER;i++){
    			UARTprintf("%c",*tempXML);
    			tempXML++;			
    		}
    		
    		while(1){}
    }