sprintf causing hardfault

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

sprintf causing hardfault

2,006件の閲覧回数
Edrianocarlos
Contributor IV

Hi,

I am trying to use sprintf with.

K64 freedom board.

REDLIB nohost.

every time i try to use sprintf i see a hard fault.

I did not find a place to change the heap, do i have to change it? increase?

I get no error when compiling the project and everything else is working so far.

(void)sprintf(distance,"%s\r\n",_distance); 

0 件の賞賛
返信
2 返答(返信)

1,775件の閲覧回数
lpcxpresso_supp
NXP Employee
NXP Employee

What version of MCUXpresso IDE are you using?

I've just tried a simple sprintf example on K64 (based on http://www.cplusplus.com/reference/cstdio/sprintf/?kw=sprintf) with the current MCUXpresso IDE v10.2, and all seems to be OK.

It might be worth stepping through your code at the instruction level to try to work out what is triggering the hard fault.

In particular how are "distance" and "_distance" defined in your example? I suspect you might be passing the buffer rather than a pointer to the buffer into your sprintf call

If you are still having problems, can you use the Quickstart Panel 's "Export project to archive" option" and post an example project that replicates the problem?

Regards,

MCUXpresso IDE Support

0 件の賞賛
返信

1,775件の閲覧回数
Edrianocarlos
Contributor IV

Thank you.

Yes it was my mistake, my buffer was too short.

now everything is working. 

0 件の賞賛
返信