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

alloc ram causes hardfault

Hello,

I'm using a lpc1766 and made a very simple program to debug a hardfault exception.

After initiallisation the main routine is called where a array is allocated using the library function malloc().

When the malloc function is called a "bus fault" exception arises which ends up in a "hard fault" exception. In the hard fault exception handler I can read the exception registers using the debugger "fault reports" dialog.

When I double click on the topmost entry of the callstack it jumps to the following instruction:
0x00000280 4605 MOV r5,r0

Can somenone tell me why my code ends up in hardfault exception?

Below is the function in C and assembly.

void *alloc_ram(uint16 size)
{
  void *ram;

  __disable_irq();

  ram = malloc(size);

  __enable_irq();

  return(ram);
}


    32: {
    33:   void *ram;
    34:
0x00000274 B570      PUSH     {r4-r6,lr}
0x00000276 4604      MOV      r4,r0
    35:   __disable_irq();
    36:
0x00000278 B672      CPSID    I
    37:   ram = malloc(size);
    38:
0x0000027A 4620      MOV      r0,r4
0x0000027C F000F840  BL.W     malloc (0x00000300)
0x00000280 4605      MOV      r5,r0
    39:   __enable_irq();
    40: