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 3 years have passed since last update.

PlatformIOでコンソール出力が上手くいかなかった

Last updated at Posted at 2020-04-07

はじめに

電子工作でわちゃわちゃしてたらコンソール出力で少しハマったので,メモ程度に残しておきます.

環境

  • OS: Windows10
  • VSCode: 1.43
  • PlatformIO: Core 4.3.2a1
  • ST STM32: 6.0.0
  • 使用したマイコン: F303K8

※2020/4/7での状態

状況

上手くいかなかった最小構成は以下のソースコード.

input
#include "mbed.h"

Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx

int main() {

    int int_val = 1;
    float float_val = 1.0;
    double double_val = 1.0;

    while(1) {

        pc.printf("---\n");
        pc.printf("int value: %d \n", int_val);
        pc.printf("float value: %f \n", float_val);
        pc.printf("double value: %f \n", double_val);
        wait_ms(500);
    }
}

上記のソースコードをマイコンに書き込み実行すると,以下のような出力が得られた.

output
---
int value: 1
float value:
double value:

浮動小数点型が出力されなかった.

対策と結果

いろいろと調べた結果,質問掲示板のページでも似たようなことが質問されていた[1]
同記事を参考にして,ソースにasm(".global _printf_float");を挿入してみた.

input
#include "mbed.h"

Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx

asm(".global _printf_float");

int main() {

    int int_val = 1;
    float float_val = 1.0;
    double double_val = 1.0;

    while(1) {

        pc.printf("---\n");
        pc.printf("int value: %d \n", int_val);
        pc.printf("float value: %f \n", float_val);
        pc.printf("double value: %f \n", double_val);
        wait_ms(500);
    }
}

以下はビルドしてマイコンに書き込み,実行した結果.

output
---
int value: 1
float value: 1.000000
double value: 1.000000

期待通り出力された.

参考

  1. https://community.platformio.org/t/pio-doesnt-build-teensy-floating-point-support/3296/2
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?