Inherit from Serial and use software buffers for TX and RX. This allows the UART peripherals to operate in a IRQ driven mode. Overrides most (but not all) stdio functions as Serial did

Dependencies:   Buffer

Dependents:   buffered_serial_test BLE_Police_HRM evena_BLE_Police_HRM df-2014-workshop-rfid-case-generator-k64f ... more

Example

 #include "mbed.h"
 #include "BufferedSerial.h"

 BufferedSerial pc(USBTX, USBRX);

 int main()
 {
     pc.baud(115200);
   
     while(1)
     {
         Timer s;
       
         s.start();
         pc.printf("Hello World - buff\n");
         int buffered_time = s.read_us();
         wait(0.1f); // give time for the buffer to empty
       
         s.reset();
         printf("Hello World - poll\n");
         int polled_time = s.read_us();
         s.stop();
         wait(0.1f); // give time for the buffer to empty
       
         pc.printf("printf buffered took %d us\n", buffered_time);
         pc.printf("printf polled took %d us\n", polled_time);
         wait(0.5f);
     }
 }

Revisions of BufferedSerial.cpp

Revision Date Message Actions
13:c17c532bc4f8 2019-02-20 Eliminate warnings with Mbed 2 version 131 and Mbed OS 5.2.0 and newer. Added error messages to help if incompatible versions are identified (best effort) File  Diff  Annotate
11:779304f9c5d2 2015-07-26 Force use of RawSerial File  Diff  Annotate
10:9ee15ae3d1a3 2015-01-07 updates to the constructor to enable expansion of the internal ring buffers and printf() buffer sizes File  Diff  Annotate
8:506247a040bc 2015-01-04 increased buffer sizes more File  Diff  Annotate
7:6fa214b41d73 2015-01-02 made updates to enable the ability to expand the internal buffer. Additionally, used the definition to set the size of the ring buffers in the constructor initializer list. Increased the default buffer size to 512. Additional clean ups (param cks) File  Diff  Annotate
6:8287e83943f0 2014-09-09 added #define to change the base Serial class to RawSerial if desired File  Diff  Annotate
4:2ba4d2e1f05d 2013-12-30 Disable TX IRQ when nothing is left in the buffer (FRDM support). Tested example program with KL46Z, KL25Z and LPC11U24. LPC1768 doesn't work. Need to investigate. File  Diff  Annotate
3:6b76fcf27545 2013-06-12 Updates to block only tx irq when fifo needs a kick. Updated comments and documentation File  Diff  Annotate
2:7e8a450a9101 2013-05-24 Override virtual member write. Better management of prime to avoid contentious writes under heavy traffic. updated puts to add \n per stdlib puts definition File  Diff  Annotate
1:57a11fb5d529 2013-05-23 Added prime (private member).Only want to pull from the buffer and write in one spot. prime stops irq's and call the member txIrq to put the oldest buffered byte in the transmitter. IRQ will pull the rest out once enabled again. File  Diff  Annotate
0:a977d0a3d81e 2013-05-23 TX and RX peripheral functions are IRQ driven. Most stdlib functions are overridden for transmit. Not so much for reading. getc is implemented but not the more formatted scanf. File  Diff  Annotate