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.

am2434 _sbrk() function code

Hi,

I'm using the AM2434-EVM.

Sometimes when I use malloc the code goes to _sbrk() function which I don't have - so I implemented it empty.

Where can I find the implementation ?

Thanks,

Eli

  • Hi Eli,

    The malloc is a standard C function defined in stdlib.h and included in the libc.a. The _sbrk is a lower level function may be used by the malloc. It should be included in the libc.a if needed. There is no need for you to implement the _sbrk.

    For example, I can add the malloc() call in the empty.c (empty project) by adding the following code section:

    ...

    #include <stdlib.h>

    ...

    void *buf_ptr=NULL;
    void empty_main(void *args)
    {
       /* Open drivers to open the UART driver for console */
       Drivers_open();
       Board_driversOpen();

       buf_ptr = malloc(1024);

       DebugP_log("All tests have passed!!\r\n");

       Board_driversClose();
       Drivers_close();
    }

    It builds, loads and run fine in both nortos and freertos empty examples.

    Best regards,

    Ming

  • Hi Ming,

    That's correct you are right the _sbrk() function should have been in the libc.a.

    I'm getting undefined reference to _sbrk().

    I put an empty _sbrk in my main.c  for the linker.

    In most cases  I use pvPortMalloc() for new.

    When I need the malloc (stl and etl cases) it goes to to _sbrk() and the malloc fails !

    I thought the libc is an open code and I'll just copy the implementation.

    It seems I cannot find the one exact for my cortex r5f - something goes wrong. 

    Thanks,

    Eli 

  • Hi Eli,

    Which MCU+ SDK version and CCS version are you using. Can you share your example which having this issue?

    I am using the MCU+ SDK for AM243x 09.00.00.35 and the CCS 12.4.0. the examples I used are: 

    empty_am243x-evm_r5fss0-0_nortos_ti-arm-clang and 

    empty_am243x-evm_r5fss0-0_freertos_ti-arm-clang

    Best regards,

    Ming

  • Hi Ming,

    I'm using the mcu_plus_sdk_am243x_08_06_00_43.

    When I compile and link with CLANG there's no problem.

    When I link with GCC the function _sbrk() is missing. (I know that the GCC is not yet supported by TI - it's experimental) 

    I think that if I copy the c code from the libc for CLANG - I would be able to use the example also with GCC.

    So I'm looking for the c code for the appropriate  _sbrk() function.

    Thanks,

    Eli.

  • Hi Eli,

    The MCU+ SDK for AM243x is using the TI CLANG 2.1.3. The malloc implementation for TI CLANG 2.1.3 is in 

    C:\ti\ccs1240\ccs\tools\compiler\ti-cgt-armllvm_2.1.3.LTS\lib\src\memory.c

    I do not see it actually uses _sbrk, so you may want to use the malloc implementation in the memory.c in GCC.

    Best regards,

    Ming