3 years, 3 months ago.

how can i change or better configure STDIO output to other UART output source in Mbed ?

i find 3 defines #define STDIO_UART_TX #define STDIO_UART_RX and #define STDIO_UART in peripheralnames.h. and i make adaption to these 3 defines to the right pins from the UART which i expect to print out the STDIO. but just i experted that does not work. i actaully think i must give some UART input and output physical address to stdin and stdout like for example stdin = & uart_in; stdout=&uart_out or call some function that provide the service to me. that should be in my opinion the right way. but i didn´t find some. do anyone know how i can achieve that in mbed environment? thanks a lot!

1 Answer

3 years, 3 months ago.

Hi Rui,

So the easiest way to do this using mbed is to use the Serial API here

here you can declare the object and supply it with your desired pins to output to. There are also lots of other functions you can use with it. If you want to use it with the USB over serial see below. If not put in your own 'tx' and 'rx'.

One of the Serial connections goes via the mbed USB port, allowing you to easily communicate with your host PC.

Hello World!

Import program

00001 #include "mbed.h"
00003 Serial pc(USBTX, USBRX); // tx, rx
00005 int main() {
00006     pc.printf("Hello World!\n");
00007     while(1) {
00008         pc.putc(pc.getc() + 1);
00009     }
00010 }

Let me know if this helps :)


Andrea, team mbed

Accepted Answer

hello Andrea! thanks for your answer. but i think you might misunderstand my question. what i meant is to find a solution to affect the output canal of stdio library function printf() not some redefined public class function. what you suggested may be an alternative solution to replace the stdio library printf() function call allover the project and define a Serial class instance. it must have a simple solution not more as to change some defines or some assignment to achieve this goal. please reconsider this! and give me a feedback whether this is possible or not? thanks.

posted by Rui Yin 26 Oct 2016