Hi,
I'm trying to understand a HardFault that I'm getting. This is my setup:
* Keil uVision V4.03q (Windows 7) * Landtiger development board with LPC1768 * 3.2" TFT LCD Model HY32D (compatible with SSD1289)
I want to use the emWin graphics libraries using the example "NXP_emWin514_MCB1700_Keil_CMSIS". I've adapted the LCDConf.c to match the board, so I modified _InitController(), which I guess it's ok because it works fine with other examples. The application hangs at GUI_Init() and after doing some debugging I found that its going to a HardFault. The Fault Reports window show INVSTATE in the "Usage Faults". Does anyone know what this means and what causes this so I can solve this? Thanks!
Ok, I've found out that the function GUI_ALLOC_AssignMemory(_aMemory, GUI_NUMBYTES); is generating the Hard Fault, any idea why? Thanks!
Insufficient Heap?
Allocated memory exceeds span of usable space? ie if you touch the far end it tries to read beyond the end of physical memory.
Important to look at the register states, stack and faulting instruction (disassembly view) to see what the processor threw a fault over. For a write it might be an instruction back due to the deferred write through a write buffer.
Ok, so the function call that causes the hard fault is:
#define GUI_NUMBYTES 1024 * 16 // x KByte static U32 _aMemory[GUI_NUMBYTES / 4];
GUI_ALLOC_AssignMemory(_aMemory, GUI_NUMBYTES);
I've implemented a handler for the Hard Fault interrupt and I see that the PC register is 0x00000000, so it starts executing instructions at this memory location until one of them causes the fault. Its DCD (Define Constant Data). Its located in memory location 0x0000001E, DCD 0xEFFF0000. The debugger also shows in the comment "? Undefined". Also, how can I check how much heap I can use? I'm new to this architecture so my assembly skills are limited. Thanks!
You only need bare assembly skills, just enough to determine which address the load/store is acting on.
Good chance you corrupting (zeroing) the stack here. Stack and Heap sizes described in startup.s
PC = 0 is an invalid condition, it is an EVEN address (that itself will fault), and would expect to be a vector table at this location.