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.

malloc issues starting with demo code as a base

Other Parts Discussed in Thread: TMS570LS20216

So we just got some TMS570 dev sticks (with the TMS570LS20216 MCU) and we're trying to run some benchmark code.

I'm starting with the demo software that came with it, and have just modified it. However, the code fails because I can't malloc. To simplify, I added the following line as the first line of main (in sys_main.c)

    testmalloc = malloc(8*sizeof(char));

However, when I actually try to run it I end up in the undefined interrupt loop and when I look at the debugger I see several assembly lines that map to _undefined.

Here's the disassembly in the debugger for main:

0x00024398:   E92D4008 STMFD           R13!, {R3, R14}
0x0002439C:   E3A00008 MOV             R0, #8
0x000243A0:   EBFFF25C BL              _undefined
0x000243A4:   E59FC150 LDR             R12, _undefined
0x000243A8:   E58C0000 STR             R0, [R12]
0x000243AC:   EBFFEA27 BL              _undefined
0x000243B0:   E3A00004 MOV             R0, #4
0x000243B4:   EBFFD701 BL              _undefined
0x000243B8:   EBFFEA24 BL              _undefined
0x000243BC:   EF000004 SWI             #4
0x000243C0:   EBFFEDDF BL              _undefined
0x000243C4:   E59F0138 LDR             R0, _undefined
0x000243C8:   E59F2130 LDR             R2, _undefined
0x000243CC:   E3A01008 MOV             R1, #8

 

Any ideas on what I'm doing wrong? Do I need to use a specific malloc call that I don't know about? Is there something in the demo project that sets a configuration that doesn't work for this?

I'm pretty lost right now, so any help would be appreciated.

  • Hi Jeanette,

    Please check your linker command file(*.cmd) whether .sysmem  is declared or not. The .sysmem memory is used for dynamic memory allocation.

    The compiler only throws a warning when it is not declared and continues with the execution,  resulting in an undesired behaviour.

    Regards

    Hari

  • Jeanette,

     

    The malloc function allocates memory in a section named sysmem.

    This section is not defined in the default linker command file in the demo code you are using.

    Here is an extract from sys_link.cmd linker command file.

    /*----------------------------------------------------------------------------*/
    /* sys_link.cmd                                                               */
    /*                                                                            */
    /* (c) Texas Instruments 2009, All rights reserved.                           */
    /*                                                                            */

    /* USER CODE BEGIN (0) */
    /* USER CODE END */


    /*----------------------------------------------------------------------------*/
    /* Linker Settings                                                            */

    -l rtsv7R4_T_be_v3D16_eabi.lib

    --retain="*(.intvecs)"

    -heap 0x1000


    /* USER CODE BEGIN (1) */

    /* USER CODE END */

    /*----------------------------------------------------------------------------*/
    /* Memory Map                                                                 */

    MEMORY
    {
        VECTORS (X)  : origin=0x00000000 length=0x00000020
        FLASH0  (RX) : origin=0x00000020 length=0x001FFFE0
    /*    FLASH1  (RX) : origin=0x00080000 length=0x00080000
        FLASH2  (RX) : origin=0x00100000 length=0x00080000
        FLASH3  (RX) : origin=0x00180000 length=0x00080000
        STACKS  (RW) : origin=0x00000000 length=0x00001300*/
        RAM     (RW) : origin=0x08000000 length=0x00006D00

    /* USER CODE BEGIN (2) */
    /* USER CODE END */
    }

    /* USER CODE BEGIN (3) */
    /* USER CODE END */

     
    /*----------------------------------------------------------------------------*/
    /* Section Configuration                                                      */

    SECTIONS
    {
        .intvecs : {} > VECTORS
        .text    : {} > FLASH0 /*FLASH0 | FLASH1 | FLASH2 | FLASH3*/
        .const   : {} > FLASH0 /*> FLASH0 /*| FLASH1 | FLASH2 | FLASH3*/
        .cinit   : {} > FLASH0 /*> FLASH0 /*| FLASH1 | FLASH2 | FLASH3*/
        .pinit   : {} > FLASH0 /*> FLASH0 /*| FLASH1 | FLASH2 | FLASH3*/
        .bss     : {} > RAM /*FLASH0 /*RAM*/
        .data    : {} > RAM /*FLASH0 /*RAM*/
        .sysmem  : {} > RAM /*FLASH0 /*RAM*/

    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    }

    /* USER CODE BEGIN (5) */
    /* USER CODE END */


    /*----------------------------------------------------------------------------*/
    /* Misc                                                                       */

    /* USER CODE BEGIN (6) */
    /* USER CODE END */


    /*----------------------------------------------------------------------------*/


    Please add the read lines to specify the linker to map this section in RAM. By default, the linker did it in Flash. That explains the error you are getting.


    Now, depending on how much memory you want to allocate, another directive can be used in the linker command file.

    -heap [size]

    By default, if -heap is not used, the heap default size is0x800. If you need more heap, 0x1000 for example, add this statement:

    -heap 0x1000

     

    Please have a try and let me know your result.

     

    Best Regards

     

    Jean-Marc Mifsud

  • Thanks - my problem was definitely my linker command file - I had figured out how to use the IDE to change the heap, but not adjust the .sysmem

    This now works for me. Much appreciated!