i.MX8MP: Cannot print float values from SDK M7 examples

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

i.MX8MP: Cannot print float values from SDK M7 examples

跳至解决方案
923 次查看
vin_imd
Contributor II

Hello all,

I am using custom board based on i.MX8MP EVK. I am using the SDK created from NXP MCUXpresso SDK builder for i.MX8MPEVK. I am not using the MCUXpresso  IDE as it is not supported for i.MX8MP platform so building the examples on Ubuntu 20.04 using gcc-arm toolchain. Looking at the examples for M7 co-processor (ecspi polling), I'm unable to print floating point values. The floating point values are stored correctly and in the flags.cmake I see that the below flags are defined.

-mfloat-abi=hard 
-mfpu=fpv5-sp-d16 

The statement - PRINTF("Execution timer: %s\n\rTime: %u ticks %2.5f milliseconds\n\rDONE\n\r", "1 day", 86400, 86.4); doesn't print 86.4, just a blank space. If I check the hex value at the address of a float variable, the value is correct which means only PRINTF has issue printing the float value.

float test = 86.6;
uint32_t *ptr = (int32_t *)&test;
PRINTF("float in hex - %x\r\n", *ptr);
outputs - 0x42ad3333 which is correct for 86.6
 

Does any one know how to get the custom PRINTF function of the SDK to print floating point values? Is it the problem with the C library being used for M7 co-processor examples build?

 

Thanks.

0 项奖励
1 解答
915 次查看
b36401
NXP Employee
NXP Employee

Here is attachment.

在原帖中查看解决方案

2 回复数
916 次查看
b36401
NXP Employee
NXP Employee

Please note that %x option in printf means integer in hex. So in this case the code gets the bytes of the variable and looks at them as an integer variable.
You need to write a routine that parses a float and divides in into integer and fractional parts of a number.
You can refer to example I attached.

0 项奖励
916 次查看
b36401
NXP Employee
NXP Employee

Here is attachment.