当前位置: 首页 > 工具软件 > mbed OS > 使用案例 >

MBED OS 6 无法打印浮点

徐涵亮
2023-12-01

修改方式: 在项目根目录创建mbed_app.json

{
    "target_overrides": {
        "*": {
             "target.printf_lib": "std"
        }
    }
}

target.printf_lib的值覆盖为std(即不使用minimal-printf,使用标准库)

或者

{
    "target_overrides": {
        "*": {
            "target.printf_lib": "minimal-printf",
            "platform.minimal-printf-enable-floating-point": true,
            "platform.minimal-printf-set-floating-point-max-decimals": 6,
            "platform.minimal-printf-enable-64-bit": false
        }
    }
}

启用minimal-printf对浮点数输出的功能。

原因就是MBED OS 6 默认使用minimal-printf

minimal-printf是为了减少资源占用,提供的替代printf的库。支持以下的格式化输出,其中浮点相关是默认disabled:

  • %d: signed integer [h, hh, (none), l, ll, z, j, t].
  • %i: signed integer [h, hh, (none), l, ll, z, j, t].
  • %u: unsigned integer [h, hh, (none), l, ll, z, j, t].
  • %x: unsigned integer [h, hh, (none), l, ll, z, j, t], printed as hexadecimal number (e.g., ff).
  • %X: unsigned integer [h, hh, (none), l, ll, z, j, t], printed as hexadecimal number (e.g., FF).
  • %f: floating point (disabled by default).
  • %F: floating point (disabled by default, treated as %f).
  • %g: floating point (disabled by default, treated as %f).
  • %G: floating point (disabled by default, treated as %f).
  • %c: character.
  • %s: string.
  • %p: pointer (e.g. 0x00123456).

 

 

 

 

 

 类似资料: