I am getting hardfault exception in my code. And when i watched my registers CFSR and HFSR their values are like
CFSR = 0x00001000
- IBUSERR = 1
- STKERR = 0
- FORCED = 1
The hard fault occurs at "GUI_DispStringAt(_strtmp, 80, 155);" of the following code which periodically update LCD display.
The hard fault occurs at a specific timer count.
unsigned char _strtmp;
unsigned int Timer = 0;
sprintf(_strtmp, "%5d:", (char const *)Timer);
GUI_DispStringAt(_strtmp, 80, 155);
I am using STM32F446ZE microcontroller. And for coding and compiling I am using IAR Embedded Workbench with versino 7.50.
I trace into the assembly code which hard fault happened: "BL 0x81a933c".
What has confused me is that code works well before hard fault, but I just use 0x8000000 – 0x80ffff in my memory placement.
Until a period of time has passed, the code "BL 0x81a933c" don't go into 0x81a933c but branch into 0x3a9dd118, that's why hard fault occurs (IBUSERR = 1).
Other observations are:
1) I try to adjust the allocated size for STemWin GUI (#define GUI_NUMBYTES (1024) * 110 //x KByte，static U32 extMem[GUI_NUMBYTES / 4];), the time period till hard fault occurs is the same for 20K/40K/80K, but is shorter for 110K
2) the code just has one 100Hz timer to get sensor data, the main loop just runs STemWin part, algorithm part and key part, the unit test for STemWin is ok, the unit test for algorithm part is also ok, but the combination of STemWin & algorithm occurs hard fault.
So what's the possible problem happens?!
Thanks & Regards,