Error when printing a float ( HardFault_Handler)

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Error when printing a float ( HardFault_Handler)

1,522件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kemes on Sat Apr 06 07:42:48 MST 2013
Hi to all
I am using LPC11U37/401 with LPCXpresso v5.1.2 [Build 2065] [2013-02-20] with newlib.
When I attempt to use sprintf with a float I obtain an HardFault Handler.  here is the code:

float   Temp= 0;
char actTemp[128];

    sprintf(actTemp,"%4.2f",Temp[0]);

no change if I use newlib in nohost or semihost.  How can I solve ?
(All ok if I attemp to print a decimal, that is sprintf(actTemp,"%d",value); )
Thanks
0 件の賞賛
返信
5 返答(返信)

1,256件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Sun Apr 07 08:40:16 MST 2013
The heap starts from the end of your data (ram) area and the stack starts from the end of ram. Therefore, they grow towards each other. There is no stack checking on a Cortex-M3 so the stack and the heap can overwrite each other. So, if you allocate a lot of heap (e.g malloc) and use a lot of stack (large number of local variables or very deep nesting of function calls) you can end up in this situation.

Your stack is in the SP register, the current extent of your heap is in __end_of_heap (if you are using redlib).

One other possibility is that you are overwriting memory yourself. For example, writing beyond the end of an array or a block that you have malloc()'d
0 件の賞賛
返信

1,256件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Sun Apr 07 08:30:49 MST 2013

Quote:
How can I detect if I have stack overflow ?

First, you can single-step into the offending printf() (probably need to step
through the assembler code...), and watch the stack.
For better visibility, you can modify the startup code to fill the stack
with a specific pattern. As a side info, Visual C used 0xDDDD.DDDD here ...

Or you can catch the error - probably the hardfault handler - and unwind/check
the stack and system registers there. There is a famous code from Joseph Yiu around
(definitive guide to cortex M3 ...)

Or, you can just increase the reserved stacksize and see if the problem goes away.

Choosing a less-consumptive lib, avoiding floats and/or writing a small
special purpose function yourself could also help.
0 件の賞賛
返信

1,256件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kemes on Sun Apr 07 00:06:05 MST 2013
Here are data:
   text       data        bss        dec        hex    filename
  63844       2220       1172      67236      106a4    RemoteTemp.axf

considering that LPC11U37/401  has 10K of ram, I should have about 7K of ram free.  How can I detect if I have stack overflow ?
thanks
0 件の賞賛
返信

1,256件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sat Apr 06 10:23:09 MST 2013
Stack overflow (or heap overflow) is a distinct possibility here with Newlib. The memory requirements for Redlib printf are generally much lower.

Check the details given by your build log and the map file - how much RAM do you actually have available after building your project?

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

Regards,
CodeRedSupport
0 件の賞賛
返信

1,256件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Sat Apr 06 09:31:26 MST 2013
A stack overflow ?
printf() and other clib function eat up your RAM, avoid it if possible.
0 件の賞賛
返信