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/MSP430F5359: failed to configure heap size larger than 32768 bytes

Part Number: MSP430F5359

Tool/software: Code Composer Studio

When I configured the Heap size of the device larger than 32768 Bytes, function malloc cannot work any more. I found a variable named memsize had overflow in file memory.c. Because its type is integer. 

 I am using CCS 7.3.0 Compiler version is 17.9.0.STS.

Is there any solution for this?

  • One possible solution is to change the data memory model build option to --data_model=large.  I do not know whether a MSP430F5359 can support large data memory model.

    Details ... The type of memsize (and other related variables in memory.c that maintain the size of things) is given by the type memsz_t.  That is the same as the type ptrdiff_t.  And ptrdiff_t, in turn, is determined by the data memory model  Under small and restricted, the size of ptrdiff_t is 2 bytes.  Under large model, the size of ptrdiff_t is 4 bytes.

    Thanks and regards,

    -George

  • George Mock said:
    I do not know whether a MSP430F5359 can support large data memory model.

    The MSP430F5359 has a CPUXV2 so it supports the large memory model. Looking at the memory map there is 64 KB of RAM from 0F0000h-0FFFFFh which could be used for a heap, leaving 2 KB of RAM from 001C00h-0023FFh which could be used for other variables / stack.

  • Thanks for reply. I choosed the large data model, and using RAM2 for dynamic memory allocation area which is origin = 0xF0000, length = 0xC000 around 50K and I can only configure 32K for heap. I thought it maybe because the type of memsize, memsz_t and ptrdiff_t. However I cannot modify them.

    Regards

    Vinson

  • VinsonShan said:
    I can only configure 32K for heap

    Exactly how do you determine this to be the case?  What do you see, and how do you see it?

    Thanks and regards,

    -George

  • In my project, I need a large dynamic List. First I calculated each node was 60 bytes so I configured 32000 bytes Heap and it worked. But after adding more detail in each node I need more Heap, so I configured 33000 bytes. During step debugging I found the problem is malloc cannot be executed. It traced to file memory.c. I found a variable named memsize is overflow. And it is integer. So I retry to configured heap 32768 bytes, malloc function worked well. and memsize is not overflow.

    Thanks and regards

    Vinson

  • -vmspx --data_model=restricted --near_data=none -Ooff --opt_for_speed=5 --use_hw_mpy=F5 --advice:power="all" --define=__MSP430F5359__ -g --printf_support=minimal --diag_warning=225 --diag_wrap=off --display_error_number --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 -z -m"testmalloc.map" --heap_size=33000 --stack_size=600 --cinit_hold_wdt=on -i"D:/ti/ccsv7/ccs_base/msp430/include" -i"D:/ti/ccsv7/ccs_base/msp430/lib/5xx_6xx_FRxx" -i"D:/ti/ccsv7/tools/compiler/ti-cgt-msp430_17.9.0.STS/lib" -i"D:/ti/ccsv7/tools/compiler/ti-cgt-msp430_17.9.0.STS/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="testmalloc_linkInfo.xml" --use_hw_mpy=F5 --rom_model

    here are the configuration above and test code bellow.

    #include <msp430.h>
    #include <stdlib.h>

    typedef struct
    {
        char test01;
        char test02;
        char test03;
        char test04;
        char test05;
        char test06;
    } NODE;
    /**
     * main.c
     */
    int main(void)
    {
     WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
     NODE *p = 0;
     int size = 0;
     size = sizeof(NODE);
     do
     {
         p = (NODE*)malloc(size);
     }
     while(p == 0);
        p->test01 = 0;
        p->test02 = 0;
        p->test03 = 0;
        p->test04 = 0;
        p->test05 = 0;
        p->test06 = 0;
     return 0;
    }

    you can see the heap size is 33000 and it cannot allocate memory for p.

    Thanks and regards

    Vinson

  • VinsonShan said:
    --data_model=restricted

    You need to change the data_model from restricted to large, which can be done from the CCS project properties under CCS Build -> MSP430 Compiler -> Processor Options.

    This is because the malloc() implementation in the RTS memory.c uses the signed type ptrdiff_t to store the packet size in the heap, where a negative size indicates a free packet. ptrdiff_t is 16-bits in the restricted data model, and 32-bits in the large data model.

    Therefore, when the heap size is larger than 32768 bytes when using the restricted data model when the heap is initialised it is considered that there is no free space.

  • problem solved thank you soooooo much!
  • However where can i find the defination of ptrdiff_t ? Because I can only find "typedef ptrdiff_t memsz_t;" in memory.c and cannot trace ptrdiff_t any more? And in specification of data_model it doesn't mention ptrdiff_t.

    Regards,
    Vinson
  • ptrdiff_t is a standard C type; it is defined in stddef.h. However, as its size can change based on the memory model, you should check the Compiler User's Guide for the specification of ptrdiff_t.
  • found that thank you!

    Regards

    Vinson

  • Please see this forum thread about a different, though related, issue with malloc.  It turns out the constant PTRDIFF_MAX from the header file stdint.h is wrong when building for large data model.  And that, in turn, causes problems in malloc.  I don't specifically know this problem affects this thread as well.  But it seems likely.

    Thanks and regards,

    -George