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_printf.cpp

Committer:
BlazeX
Date:
2015-01-15
Revision:
1:1464146bd7fb
Parent:
0:cd0d79be0c1a

File content as of revision 1:1464146bd7fb:

/// @file Example_printf.cpp
/// @brief Formatted output
/// 
/// - Uses SerialDriver with USBTX and USBRX.
/// - Has much too small buffers, but printf is blocking, so it does not matter
/// 
/// - The terminal will be flooded with text
/// - LED4 indicates parallel thread working
/// 

#if 0

#include "SerialDriver.h"

// only 4 byte of software ring buffer?
// No problem! SerialDriver uses idle blocking calls :D
SerialDriver pc(USBTX, USBRX, 4, 4);

// This thread is running in parallel
DigitalOut led4(LED4);
void parallel(void const * argument)
{
    while(1)
    {
        Thread::wait(20);
        led4= !led4;
    }
}

int main()
{
    // Start the other thread
    Thread parallelTask(&parallel);
    
    float f= 0.0f;    
    while(1)
    {
        // unformatted text
        pc.puts("Hi! this uses puts.\r\n");
        
        // formatted text
        pc.printf("And this is formatted. Here is the sin(%f)=%f.\r\n", f, sinf(f));
        f+= 0.25f;
    }
}

#endif