This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Function malloc() cause to trigger Reset Handler

I am working with cortex-m4 microcontroller from TI TM4C123GH6PM. I am trying to allocate the memory space by following c syntax

        char *target;
        int size=10;
        target=(char *)malloc(size*sizeof(char)); //allocating size for string
        if(target==0)red;
        else green;
        free(target);

The line where I am trying to assign the allocated space address to the char pointer cause Reset Handler to trigger at line
LDR R0, =SystemInit

Disassembly
0x0000090c BEAB 0xAB

commenting that line cause to glow red led, means rest of the lines are executing perfectly. Same with the calloc function. I don't have any idea about this error please help.

Parents
  • Have you specified any heap, so malloc() have somewhere to allocate memory?

    Another thing - what do you think sizeof(char) is? Do you see any situation where sizeof(char) might have a different value?

    By the way. Are you saying that

    red;
    


    is enough to turn on a red LED?

    and

    green;
    


    is enough to turn on a green LED?

    No function call needed?
    And no assign needed?
    Are "red" and "green" some "interesting" #define'd symbols?

Reply
  • Have you specified any heap, so malloc() have somewhere to allocate memory?

    Another thing - what do you think sizeof(char) is? Do you see any situation where sizeof(char) might have a different value?

    By the way. Are you saying that

    red;
    


    is enough to turn on a red LED?

    and

    green;
    


    is enough to turn on a green LED?

    No function call needed?
    And no assign needed?
    Are "red" and "green" some "interesting" #define'd symbols?

Children