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


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

 BufferedSerial pc(USBTX, USBRX);

 int main()
         Timer s;
         pc.printf("Hello World - buff\n");
         int buffered_time = s.read_us();
         wait(0.1f); // give time for the buffer to empty
         printf("Hello World - poll\n");
         int polled_time = s.read_us();
         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);


RevisionDateWhoCommit message
14:7e5e866edd3d 2019-02-20 sam_grove Discard random text file and update version check help message. default tip
13:c17c532bc4f8 2019-02-20 sam_grove 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)
12:a0d37088b405 2016-03-07 sam_grove Update Buffer to MyBuffer
11:779304f9c5d2 2015-07-26 sam_grove Force use of RawSerial
10:9ee15ae3d1a3 2015-01-07 ansond updates to the constructor to enable expansion of the internal ring buffers and printf() buffer sizes
9:2cb30392ade6 2015-01-04 ansond updates to buffer ring sizes now 2x the buffer size
8:506247a040bc 2015-01-04 ansond increased buffer sizes more
7:6fa214b41d73 2015-01-02 ansond 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)
6:8287e83943f0 2014-09-09 ansond added #define to change the base Serial class to RawSerial if desired
5:4d6a311fc8bf 2014-03-24 sam_grove Updated example in documentation. Tested with mbed.bld 81 and works with LPC1768, LPC11U24, KL25Z, KL46Z, KL05Z
4:2ba4d2e1f05d 2013-12-30 sam_grove 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.
3:6b76fcf27545 2013-06-12 sam_grove Updates to block only tx irq when fifo needs a kick. Updated comments and documentation
2:7e8a450a9101 2013-05-24 sam_grove Override virtual member write. Better management of prime to avoid contentious writes under heavy traffic. updated puts to add \n per stdlib puts definition
1:57a11fb5d529 2013-05-23 sam_grove 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.
0:a977d0a3d81e 2013-05-23 sam_grove 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.