Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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.
Diff: Examples/Example_Bridge.cpp
- Revision:
- 0:cd0d79be0c1a
- Child:
- 1:1464146bd7fb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Examples/Example_Bridge.cpp Wed Jan 14 16:30:14 2015 +0000
@@ -0,0 +1,62 @@
+/// @file Example_Bridge.cpp
+/// @brief Forwarding every byte from USB to uart and vice versa
+///
+/// - Uses SerialDriver with USBTX and USBRX.
+/// - Uses SerialDriver with p13 and p14.
+///
+/// - LED1 indicates forwarding pc to uart works
+/// - LED2 indicates forwarding uart to pc works
+/// - LED4 indicates a parallel thread running
+///
+/// - connect p13 with p14 to get a hardware null modem ;)
+
+#if 0
+
+#include "mbed.h"
+#include "SerialDriver.h"
+
+SerialDriver pc(USBTX, USBRX);
+SerialDriver uart(p13, p14);
+DigitalOut led1(LED1), led2(LED2), led4(LED4);
+
+// This thread forwards from pc to uart
+void forwardPc(void const * argument)
+{
+ // Sometimes You're the Hammer,
+ while(1)
+ {
+ uart.putc(pc.getc());
+ led1= !led1;
+ }
+}
+
+// This thread forwards from uart to pc
+void forwardUart(void const * argument)
+{
+ // Sometimes You're the Nail
+ while(1)
+ {
+ pc.putc(uart.getc());
+ led2= !led2;
+ }
+}
+
+int main()
+{
+ // setup serial ports
+ pc.baud(9600);
+ uart.baud(38400);
+
+ // Start the forwarding threads
+ Thread forwardPcThread(&forwardPc);
+ Thread forwardUartThread(&forwardUart);
+
+ // Do something else now
+ while(1)
+ {
+ Thread::wait(20);
+ led4= !led4;
+ }
+}
+
+#endif
