LPC1769 malloc hard fault

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1769 malloc hard fault

1,222 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cpraba on Mon Jul 01 18:04:03 MST 2013
Hi,

I am using LPC1769 and RedLib. I am trying to do malloc in the GPIO ISR. Malloc returns fine upto 1K memory. Beyond that Its generating Hard fault(Precise Error). I noticed that malloc API is trying to access a invalid memory location.

My system doesn't have any operating system. I am using the default .ld file generated by the LPC XPresso IDE. Is there any known issues with malloc()? Any hint for debugging...

Thanks,
0 Kudos
5 Replies

987 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Sun Jul 07 00:53:43 MST 2013
[FONT=Tahoma][SIZE=2]Your hard fault is being caused because the code is attempting to read a word (32 bits) from a non word aligned address [Alignment fault] held in register r4.

Register r4 is loaded from an address in r3, and r3 appears to be the (fixed) address of a program variable in on-chip static ram.

I would guess that the variable is the next free malloc block or something like that.

It appears to be either corrupt [can happen if you write outside the area returned by a previous malloc] or not properly initialised. Is there a library init function that you failed to call?

Perhaps you could add a data write breakpoint for 0x10001ABC (the address from r3) as soon as you start debugging (presumably at the start of main) and see if the contents start out and remain reasonable -- a 4 byte multiple in static ram space (0x10000000 for  a maximum of 64KB -- IIRC for LPC1768/9).

Cheers, Mike

[/SIZE][/FONT]
0 Kudos

987 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cpraba on Sat Jul 06 21:58:55 MST 2013
I am attaching the screenshot of the LPCXpresso before hard fault and after hard fault which reflects the assembly code under execution and Register status. I moved my malloc into the processor context and still i m seeing the crash. The crash is seen inside malloc API. Any thought would be highly appreciated. [ATTACH]1083[/ATTACH]

[ATTACH]1084[/ATTACH]
0 Kudos

987 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Jul 03 00:27:53 MST 2013
As whitecoe already suggested seeing at least your map file (and axf) would be useful, but preferably an example project would be better:

http://support.code-red-tech.com/CodeRedWiki/ImportExport

And if you can't provide a project, it would be useful if you could actually step through in the debugger to the point just before the hard fault - and tell us exactly where you in. If it is inside C library code, then you won't be able see source code, but you will be able to see the function name, and the assembler code.

You should be able to do this by using the hard fault support in the debugger:

http://support.code-red-tech.com/CodeRedWiki/DebugHardFault

Regards,
CodeRedSupport
0 Kudos

987 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cpraba on Tue Jul 02 22:34:07 MST 2013
I am able to do malloc upto 1k. It means, I am not getting crash in the first instance of malloc. I am using LPC1769, so i am having 32k bank RAM. I noticed the heap consumption before crash is close to 1.2k and stack pointer has also reached not more than 1k. I am using the default .ld file generated by LPC XPresso.

I also found out the fault happened is "PresiceErr" fault and the MMAR register contents contain an invalid memory. I am not sure why malloc API is trying to read the invalid memory. Any inputs would be highly appreciated.
0 Kudos

987 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Tue Jul 02 01:27:14 MST 2013
Malloc'ing inside an ISR seems slightly strange. But that aside - does your malloc ever work, or does it fault the first time that it is called?

And how are you then actually free'ing your memory again? Are you sure that you simply aren't running out of memory?

Maybe you can post a test project, or at least the map file generated by the linker?

PS - debugging hard faults is covered in Code Red's FAQs...
http://support.code-red-tech.com/CodeRedWiki/DebugHardFault

HTH!
0 Kudos