#include "mbed.h"


#include"mbed.h"

Serial pc(SERIAL_TX,SERIAL_RX);//USART2  tx, rx
Serial device(PA_11, PA_12); // PC机usb转TTL CP2102   USART6 tx, rx
DigitalOut led(LED1);

void xxIRQ()
{
pc.putc(device.getc());    
}

void xxxIRQ()
{
device.putc(pc.getc());    
}

int main()
{
  int i=1;
  pc.attach(&xxIRQ,SerialBase::RxIrq); 
  device.attach(&xxxIRQ,SerialBase::RxIrq); 
  while(1)
  {
    //pc.attach(&xxIRQ,SerialBase::RxIrq); 
    led=0;wait(0.1);led=1;wait(0.1);wait(1);
    pc.printf("This demo work runs since %d seconds.\n", i++);
    
    if(pc.readable()) 
      {
       device.putc(pc.getc()); // 从虚拟串口接收数据,并发给PC
      }
    if(device.readable()) 
      {
       pc.putc(device.getc()); // 从PC物理串口接收数据,并发给虚拟串口
      }
  }
}