LoginSignup
0
0

More than 1 year has passed since last update.

Mbedで自作のprintfが使いたい(STM32L010)

Last updated at Posted at 2022-05-02

x @Kurogaraさんの記事を非営利、研究調査で引用して移植しました。

目的
さらに容量に余裕がある場合
ちょつと違うがぞくに言うsprintfを使うというやつ
そもそも、標準シリアルを使えというのは、なし

o_con379.jpg

参考



#include "mbed.h"

//Serial pc(USBTX, USBRX); // tx, rx
//Serial pc(SERIAL_TX, SERIAL_RX); //767
RawSerial pc(PA_2, PA_3); //010

int ns_printf(char* fmt, ...) {
      char buff[256];
      va_list args;
      va_start(args, fmt);
      int return_status = vsnprintf(buff, sizeof(buff), fmt, args);
      va_end(args);
      char *s = buff;
      while (*s) pc.putc(*s++);
      return return_status;
}


int main() {

    char *ss1; //文字のポインター
    int ii; //ループカウンター

    //無限ループ
    while(1) {


        ss1="Hello World !\r\n";
        ii=0; //ループカウンター
        while(ss1[ii]!=0){
            
            //一文字出力
            pc.putc(ss1[ii]);ii++;
                        
        } //while

        ns_printf("%d\n\r",1234);

        //1秒の待ち
        wait_ms(1000);
        
    } //while
} //main

//容量削減
void error(const char* format, ...){}




0
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
0
0