cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault Exception using STemWin & STM32F446ZE

Luke Lee
Associate
Posted on August 30, 2017 at 05:28

Hi all,

      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

        HFSR

             - 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[20];

unsigned int Timer = 0;

void DRAW_SCENE()

{

sprintf(_strtmp, '%5d:', (char const *)Timer);

GUI_DispStringAt(_strtmp, 80, 155);

Timer++;

}

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,

Luke
1 REPLY 1
Posted on August 30, 2017 at 05:51

The branch does look odd, I'd probably disassemble the whole image and find where that instruction is, and also double check the parameters passed to the linker (.ICF file?) and the .MAP file generated by the linker.

Check you have an adequate stack, and you are not trashing that.

Pretty sure (char const *) makes no sense in this context.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..