sprintf causing hardfault

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sprintf causing hardfault

1,140 Views
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 Kudos
2 Replies

909 Views
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 Kudos

909 Views
Edrianocarlos
Contributor IV

Thank you.

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

now everything is working. 

0 Kudos