查看: 4267|回复: 9

[求助] KDS的printf如何支持浮点输出?

[复制链接]
  • TA的每日心情
    慵懒
    2021-8-31 12:39
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    26

    主题

    149

    帖子

    1

    高级会员

    Rank: 4

    积分
    561
    最后登录
    2025-7-21
    发表于 2014-12-23 20:14:21 | 显示全部楼层 |阅读模式
    1. /* ###################################################################
    2. **     Filename    : main.c
    3. **     Project     : FRDM-KL46Z-ConsoleIO
    4. **     Processor   : MKL46Z256VLL4
    5. **     Version     : Driver 01.01
    6. **     Compiler    : GNU C Compiler
    7. **     Date/Time   : 2014-11-07, 06:26, # CodeGen: 0
    8. **     Abstract    :
    9. **         Main module.
    10. **         This module contains user's application code.
    11. **     Settings    :
    12. **     Contents    :
    13. **         No public methods
    14. **
    15. ** ###################################################################*/
    16. /*!
    17. ** @file main.c
    18. ** @version 01.01
    19. ** @brief
    20. **         Main module.
    21. **         This module contains user's application code.
    22. */         
    23. /*!
    24. **  @addtogroup main_module main module documentation
    25. **  @{
    26. */         
    27. /* MODULE main */


    28. /* Including needed modules to compile this module/procedure */
    29. #include "Cpu.h"
    30. #include "Events.h"
    31. #include "CsIO1.h"
    32. #include "IO1.h"
    33. #include "LED_GREEN.h"
    34. #include "BitIoLdd1.h"
    35. #include "LED_RED.h"
    36. #include "BitIoLdd2.h"
    37. #include "SW1.h"
    38. #include "SW1_Bit.h"
    39. #include "BitIoLdd3.h"
    40. #include "MMA8451.h"
    41. /* Including shared modules, which are used for whole project */
    42. #include "PE_Types.h"
    43. #include "PE_Error.h"
    44. #include "PE_Const.h"
    45. #include "IO_Map.h"
    46. /* User includes (#include below this line is not maintained by Processor Expert) */
    47. #include "PORT_PDD.h"

    48. /*lint -save  -e970 Disable MISRA rule (6.3) checking. */
    49. int main(void)
    50. /*lint -restore Enable MISRA rule (6.3) checking. */
    51. {
    52.   /* Write your local variable definition here */
    53.   int i = 0, count  = 10;
    54.   float j = 1.01,k = 0.99;
    55.   char a = 10;
    56.   /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
    57.   PE_low_level_init();
    58.   /*** End of Processor Expert internal initialization.                    ***/

    59.   /* Write your code here */
    60.   LED_GREEN_PutVal(1);
    61.   LED_RED_PutVal(1);
    62.   while(1)
    63.   {
    64. //          i = 500000;
    65. //          while(i--);
    66. //          LED_GREEN_PutVal(1);
    67. //          if(SW1_Bit_GetVal() == 0)
    68. //          {
    69. //                  LED_GREEN_PutVal(0);
    70. //                  printf("\rcount = %d ",count++);
    71. //                  while(0 == SW1_Bit_GetVal());
    72. //                  LED_GREEN_PutVal(1);
    73. //          }
    74. <font color="#ff0000">          printf("%d,%f,%f\n",i,j,k);</font>
    75.           LED_GREEN_NegVal();

    76.   }
    77.   /* For example: for(;;) { } */

    78.   /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
    79.   /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
    80.   #ifdef PEX_RTOS_START
    81.     PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
    82.   #endif
    83.   /*** End of RTOS startup code.  ***/
    84.   /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
    85.   for(;;){}
    86.   /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
    87. } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

    88. /* END main */
    89. /*!
    90. ** @}
    91. */
    92. /*
    93. ** ###################################################################
    94. **
    95. **     This file was created by Processor Expert 10.4 [05.10]
    96. **     for the Freescale Kinetis series of microcontrollers.
    97. **
    98. ** ###################################################################
    99. */
    复制代码
    以上是我FRDM—KL46Z板子的代码,但是printf("%d,%f,%f\n",i,j,k); %f打印出来的结果为空。
    请问如何设置prinf允许浮点输出啊?
    我知道答案 目前已有9人回答
    回复

    使用道具 举报

    该用户从未签到

    3

    主题

    143

    帖子

    0

    中级会员

    Rank: 3Rank: 3

    积分
    443
    最后登录
    2020-10-29
    发表于 2015-1-2 22:51:15 | 显示全部楼层

    (正解)

    本帖最后由 FSL_TICS_ZJJ 于 2015-1-4 11:32 编辑
    zhangshengping 发表于 2015-1-1 19:03
    我用的是KDS2.0.0但是同意不能打印浮点数据。
    只打印空。

    可以啊,如下图
    QQ图片20150102224126.jpg

    要点是:
    1、 -u _printf_float  这个你已经设置了
    2、修改ProcessorExpert.ld中的__heap_size = 0x1000;
         或者在 QQ图片20150102224736.png 中设置(0x1000是我随便填的,具体需要多大这个得看你的项目了)。因为printf要用标准库的malloc,而KDS工程默认给的heap大小是0。
    3、 QQ图片20150102224846.png 这里面 Enable semihosting一定要打开(不知道newlib有没有类似nohost这类的选型关闭semihosting功能,这个得FAE确认了)。因为KDS的printf会在这个选项关闭的时候因为上面heap的设置不同而导致异常,异常原因可能是kds的库是链接的semihost版本,这个现象我也发了贴,FAE还没有确认是否是bug,该如何解决。

    一个简单的工程,我的平台是frdm-k64f,你可以参考一下。
    ccc.rar (520.35 KB, 下载次数: 9)
    回复 支持 1 反对 0

    使用道具 举报

    该用户从未签到

    3

    主题

    143

    帖子

    0

    中级会员

    Rank: 3Rank: 3

    积分
    443
    最后登录
    2020-10-29
    发表于 2014-12-24 00:40:49 | 显示全部楼层
    link的时候添加 -u _printf_float 参数
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2021-8-31 12:39
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    26

    主题

    149

    帖子

    1

    高级会员

    Rank: 4

    积分
    561
    最后登录
    2025-7-21
     楼主| 发表于 2014-12-24 18:54:43 | 显示全部楼层
    bsdpgsql 发表于 2014-12-24 00:40
    link的时候添加 -u _printf_float 参数

    请问在哪里设置?
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2021-8-31 12:39
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    26

    主题

    149

    帖子

    1

    高级会员

    Rank: 4

    积分
    561
    最后登录
    2025-7-21
     楼主| 发表于 2014-12-24 20:09:19 | 显示全部楼层
    做了这样的设置后程序进入了中断,停止在中断里面
    是什么原因啊?

    Linker的设置

    Linker的设置

    停止在中断的情况

    停止在中断的情况
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    145

    主题

    4926

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    9267
    最后登录
    1970-1-1
    发表于 2014-12-25 17:34:11 | 显示全部楼层
    楼主你好!
    暂时KDS应该还不可以通过设置打印出浮点。
    你可以按照这个帖子的方法,调用相关的write.c read.c等试试看。
    帖子内容有些被弄成乱码了,
    你可以直接使用2楼的附件。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    3

    主题

    143

    帖子

    0

    中级会员

    Rank: 3Rank: 3

    积分
    443
    最后登录
    2020-10-29
    发表于 2014-12-28 11:33:23 来自手机 | 显示全部楼层
    本帖最后由 bsdpgsql 于 2014-12-28 11:34 编辑
    zhangshengping 发表于 2014-12-24 20:09
    做了这样的设置后程序进入了中断,停止在中断里面
    是什么原因啊?


    kds的newlib库有问题,它不是大家常用的gcc arm做的工具链,而用的一家uk的公司搞的链,据说怎么怎么优化,这家公司官网给的还是beta状态,调整heap大小也会导致printf报异常。
    你可以查看map文件,搜索printf,如果加上我说的那个参数编译后,你会发现libc_s.a/vprintf之类的带v标志的print,这就是newlib的浮点打印,kds2.0是可以链接浮点打印的,大概flash多20k左右,你的要是还有问题,只能是kds的问题了。
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2021-8-31 12:39
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    26

    主题

    149

    帖子

    1

    高级会员

    Rank: 4

    积分
    561
    最后登录
    2025-7-21
     楼主| 发表于 2015-1-1 19:03:33 | 显示全部楼层
    bsdpgsql 发表于 2014-12-28 11:33
    kds的newlib库有问题,它不是大家常用的gcc arm做的工具链,而用的一家uk的公司搞的链,据说怎么怎么优化 ...

    我用的是KDS2.0.0但是同意不能打印浮点数据。
    只打印空。
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2016-11-4 16:56
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]初来乍到

    8

    主题

    602

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    1842
    最后登录
    2020-8-25
    发表于 2015-7-13 20:24:12 | 显示全部楼层
    学习了。。。
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2018-7-23 21:04
  • 签到天数: 103 天

    连续签到: 1 天

    [LV.6]常住居民II

    228

    主题

    5379

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    16714
    最后登录
    1970-1-1
    发表于 2015-7-13 22:29:55 | 显示全部楼层
    学习了
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-28 01:44 , Processed in 0.113270 second(s), 32 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表