1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Zephyr > debug > double型をprintk()で出力する: sprintf("%f")を使う [CONFIG_NEWLIB_LIBC_FLOAT_PRINTF] | double型使用時の注意点 > loggingサブシステムはdouble型変数をサポートしない

Last updated at Posted at 2020-02-05
動作環境 
Ubuntu 18.04 LTS
ボード: STM32L476 Nucleo_64 (以下、STM32L476)
Zephyr 2.1.0-rc1
放射温度計センサー: MLX90632 (CLICK-IRThermo)
ロジック確認: Analog Discovery 2 (AD2)

状況

  • double型の値をprintk()したい
  • printk("%f")は機能しない
    • "%f"という文字が表示される
  • そうだsprintf("%f")で文字列にしてからprintk("%s")しよう
  • sprintf("%f")が機能しない

教えておじいさん〜。教えておじいさん〜。

SlackのZephyrプロジェクトで聞いたら4分で回答が来ました。
ありがとうございます。

対応 > CONFIG_NEWLIB_LIBC_FLOAT_PRINTF

sprintf("%s")でdouble型を渡すにはprj.confに以下を追加する。

CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
	char szbuf[20];
	sprintf(szbuf, "%f", (float)res);
	printk("2020-02-05: %s\n", szbuf);

以下のようにMLX90632の係数を表示できた。

2020-02-05: 23734.050781

CONFIG_NEWLIB_LIBC_FLOAT_PRINTFの注意点

Slackで別の人に注意点を教えていただいた。

(意訳)

printsとdoubleには注意が必要。loggingサブシステムはdouble型変数をサポートしない。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?