基于此,在网上找了好久,终于弄明白,应该是这类微控制器不支持sprintf %f,因为这个操作太耗时,耗资源,不值得,很多微控制器都无法满足它的要求,故arm-gcc没有提供该支持或者支持得很不好,不过它也给出了凑合的解决办法,比较简单,模拟效果实现的。实现代码参考如下: www.2cto.com
When using GCC compiler, due to internal standard C library architecture, it is strongly not recommended to use the "%f" mode in the wm_sprintf function in order to convert a float variable to a string. This leads to an ARM exception (product reset).
[cpp]
float float_num;
uint8_t str_temp[128];
sprintf(str_temp,"%d.%03d",(uint32_t)float_num,(uint32_t)((float_num * 1000) - (uint32_t)(float_num) * 1000));//(实现三位小数转换)