Buffered Serial Port Driver for RTOS

Dependents:   nucleo_cannonball PiballNeoController

Buffered Serial Port Driver for RTOS

  • ISR driven, ring buffered IO operation
  • IO operations are idle waiting, don't waste time in RTOS :D
  • Can use external buffers
  • Based on mbed RawSerial

Example

SerialDriver Example

#include "SerialDriver.h"

SerialDriver pc(USBTX, USBRX);

int main()
{
    // setup serial port
    pc.baud(9600);
    
    // print some text
    pc.puts("This is just a string.\r\n");
    pc.printf("But this is a %s with integer %i and float %f.\r\n", "formatted text", 123, 0.456f);
    
    // now lets behave like a null modem 
    while(1)
       pc.putc(pc.getc());
}

Look at the API Documentation for more Examples.

Dependencies

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Import librarymbed-rtos

Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

If you find a bug, please help me to fix it. Send me a message. You can help me a lot: Write a demo program that causes the bug reproducible.

Examples/Example_Nullmodem.cpp

Committer:
BlazeX
Date:
2015-10-29
Revision:
8:903a4162a0d1
Parent:
1:1464146bd7fb

File content as of revision 8:903a4162a0d1:

/// @file Example_Nullmodem.cpp
/// @brief USB null modem
/// 
/// - Uses SerialDriver with USBTX and USBRX.
/// - Send back every received byte.
/// 
/// - LED1 indicates waiting for @ref SerialDriver::getc
/// - LED2 indicates waiting for @ref SerialDriver::putc
/// - LED4 indicates a parallel thread running

#if 0

#include "SerialDriver.h"

SerialDriver pc(USBTX, USBRX);
DigitalOut led1(LED1), led2(LED2), led4(LED4);

// This thread is emulating a null modem
void nullmodem(void const * argument)
{
    pc.baud(9600);
    
    int c;
    while(1)
    {
        led1= 1;
        c= pc.getc();
        led1= 0;
        
        led2= 1;
        pc.putc(c);
        led2= 0;
    }
}

int main()
{
    // Start the null modem
    Thread nullmodemTask(&nullmodem);
    
    // Do something else now  
    while(1)
    {
        Thread::wait(20);
        led4= !led4;
    }
}

#endif