sprintf with float specifier causing crashes, this is with MK61FN1M0VMJ12 using KDS

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

sprintf with float specifier causing crashes, this is with MK61FN1M0VMJ12 using KDS

2,054 次查看
williamcarlisle
Contributor II

Every time my program runs into a sprintf with a float specifier, the whole system crashes. This is after porting from Codewarrior to KDS, with Codewarrior I had no problems whatsoever using floats with sprintf.

I have searched around and found multiple people with the same problem(or similar), the resolutions for their problem did not work for me.

I have tried:

  • Adding "Use float with nano printf(-u _printf_float)"
  • Made sure that MQX_INCLUDE_FLOATING_POINT_IO = 1
  • Made sure that PSP_HAS_FPU = 1
  • Increasing stack sizes

There has also been mention of increasing heap size, but looking at the linker file, there is not anything for the heap. With that said, I do not believe it uses the heap. If the program uses the heap, I am not sure where to increase that. I would welcome suggestions on where to find that.

Like I said, this program worked just fine until porting from Codewarrior to KDS, so I'm not sure what could be different between the two. Same company, same chip, seems like it would be a nearly seamless transition.

Links I have already used to try and solve this:

Thanks much!

0 项奖励
回复
5 回复数

1,806 次查看
bobpaddock
Senior Contributor III

Did the stack pointer change alignment between the old and new setup?

To prevent obscure problems with printf like library code, when printing 64-bit numbers (and FP?), the stack needs to be aligned to an eight byte boundary.

See "Eight-byte Stack Alignment" - http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/14269.html

Alas ARM redid their documentation breaking all links, all searches and made everything hard to find.

This is close:

https://developer.arm.com/documentation/ihi0046/c/

Just as good hygiene make sure ARM stack pointers are aligned to eight bye boundaries.  It will save frustration in the future.

1,816 次查看
williamcarlisle
Contributor II

I also get this output from the console when there is a crash resulting from this:

BusFault: An imprecise (asynchronous) data access error has occurred.
HardFault: A fault has been escalated to a hard fault.

0 项奖励
回复

2,050 次查看
williamcarlisle
Contributor II

Version used:

KDS 3.2

MQX 4.2

0 项奖励
回复

1,800 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi  William:

 

I would suggest you create a bare metal project (without MQX RTOS), and check whether this issue still exists. So we can narrow down this issue.

 

Regards

Daniel

0 项奖励
回复

1,798 次查看
danielchen
NXP TechSupport
NXP TechSupport

also try the solution you mentioned in the bare metal project

  • Adding "Use float with nano printf(-u _printf_float)"
  • Made sure that MQX_INCLUDE_FLOATING_POINT_IO = 1
  • Made sure that PSP_HAS_FPU = 1
  • Increasing stack sizes
0 项奖励
回复