In my current project I use uVision 5.38 and the compiler default V6 compiler. As a controller I have a LPC1788 that crashes to the HardFault_Handler on the 3rd (or 4th) assembly instruction.
At the start of the project I have the following instructions from startup_LPC177x_8x.s
LDR R0, =SystemInit BLX R0
In SystemInit I have the following instructions
PUSH {r7,lr} MOVW r1,#0xC1A0 MOVT r1,#0x400F MOVS r0,#0x21
However if I press F11 once I am on the "PUSH {r7, lr}" instruction the next instruction is at address 0x00000188, in other words HardFault_Handler. Where the cpu get's "stuck" on the B instruction (to the same location).
If I try the blinky demo (for the LPC1788) the SystemInit looks like this
PUSH {r4-r8,lr} MOVW r5,#0xC0C4 MOVT r5,#0x400F MOVS r0,#0x21
This code does not trigger a HardFault_Handler.
Any suggestions on how to fix this?
My SP and other registers are set as follows:
My Memory settings are as follows:
And finally from my .map file
Heap_Mem 0x10001980 Data 4194304 startup_lpc177x_8x.o(HEAP) HEAP 0x10001980 Section 4194304 startup_lpc177x_8x.o(HEAP) Stack_Mem 0x10401980 Data 512 startup_lpc177x_8x.o(STACK) STACK 0x10401980 Section 512 startup_lpc177x_8x.o(STACK) __initial_sp 0x10401b80 Data 0 startup_lpc177x_8x.o(STACK) FPCCR 0xe000ef34 Number 0 irq_armv7m.o ABSOLUTE
So the stack pointer seems OK?
I don't think so. Your stack should be located somewhere inside one of the IRAM areas.
Ok, but how do I set/correct the SP?
As far as I know this is set automatically and (in 99% of the cases) this is set automatically.
Your heap size of 4194304 ist too much. You don't have that much RAM. So, there is no space for stack
Yes, you are correct. Reducing/checking the stack and heap sizes fixed this part.
Thanks for the help.