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
3 comments:
Basically, pc.read() looks at the number of bytes in the RX FIFO - which is always == 0
It looks like the RX interrupts are disabled/blocked.
example code files attached
Are you are using the version of BufferedSerial that is part of Mbed OS and not this library? If so, its probably best to report the issue on github (https://github.com/armmbed/mbed-os) where the development of the latest version of this library takes place. If I've misunderstood what you are doing, please publish an example program that demonstrates the failure with this library.
ricardodlr
#
26 Nov 2021
This post is awaiting moderation
Hey Sam, I am trying to use .readable() with an .attach interrupt following the instructions in this URL: https://forums.mbed.com/t/interrupt-driven-serial-required-in-os6/10041/4. However when I run the program and it enters the interrupt it never stops printing to the console. Also it doesn't do what's inside the pc.readable(). Do you think is some kind of problem with the library? Here's my code for a Nucleo F446RE:
#include "mbed.h"
#include "BufSerial.h"
BufSerial pc(USBTX, USBRX);
void onSerialRxNucleo() {
while(pc.readable()){
pc.putc('e');}
pc.printf("Interrupt\n");
}
int main()
{
pc.baud(9600);
pc.format(8,SerialBase::None,1);
//Serial interrupts when data is received in Rx
pc.attach(&onSerialRxNucleo,RawSerial::RxIrq);
while (1) {
/*Timer s;
s.start();
pc.printf("Hello World - buff\n");
int buffered_time = s.read_us();
ThisThread::sleep_for(100ms); // give time for the buffer to empty
s.reset();
printf("Hello World - poll\n");
int polled_time = s.read_us();
s.stop();
ThisThread::sleep_for(100ms); // 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);
ThisThread::sleep_for(500ms);*/
}
}
And what I get from printing in the console is:
uIrtr
eprttuepnttuIpnr
uIrtr
eIrtt
epnttuIpnrtuIrnr
eIrtt
eprttuepnrtuIrnr
uIrtr
eprttuepnttuIpnr
uIrtr
eIrtt
epnttuepnrtuIrnr
eIrtr
eprttuepnrtuIpnr
uIrtr
Basically, pc.read() looks at the number of bytes in the RX FIFO - which is always == 0 It looks like the RX interrupts are disabled/blocked. example code files attached