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.
Examples/Example_Nullmodem.cpp@0:cd0d79be0c1a, 2015-01-14 (annotated)
- Committer:
- BlazeX
- Date:
- Wed Jan 14 16:30:14 2015 +0000
- Revision:
- 0:cd0d79be0c1a
- Child:
- 1:1464146bd7fb
Release :)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| BlazeX | 0:cd0d79be0c1a | 1 | /// @file Example_Nullmodem.cpp |
| BlazeX | 0:cd0d79be0c1a | 2 | /// @brief USB null modem |
| BlazeX | 0:cd0d79be0c1a | 3 | /// |
| BlazeX | 0:cd0d79be0c1a | 4 | /// - Uses SerialDriver with USBTX and USBRX. |
| BlazeX | 0:cd0d79be0c1a | 5 | /// - Send back every received byte. |
| BlazeX | 0:cd0d79be0c1a | 6 | /// |
| BlazeX | 0:cd0d79be0c1a | 7 | /// - LED1 indicates waiting for @ref SerialDriver::getc |
| BlazeX | 0:cd0d79be0c1a | 8 | /// - LED2 indicates waiting for @ref SerialDriver::putc |
| BlazeX | 0:cd0d79be0c1a | 9 | /// - LED4 indicates a parallel thread running |
| BlazeX | 0:cd0d79be0c1a | 10 | |
| BlazeX | 0:cd0d79be0c1a | 11 | #if 0 |
| BlazeX | 0:cd0d79be0c1a | 12 | |
| BlazeX | 0:cd0d79be0c1a | 13 | #include "mbed.h" |
| BlazeX | 0:cd0d79be0c1a | 14 | #include "SerialDriver.h" |
| BlazeX | 0:cd0d79be0c1a | 15 | |
| BlazeX | 0:cd0d79be0c1a | 16 | SerialDriver pc(USBTX, USBRX); |
| BlazeX | 0:cd0d79be0c1a | 17 | DigitalOut led1(LED1), led2(LED2), led4(LED4); |
| BlazeX | 0:cd0d79be0c1a | 18 | |
| BlazeX | 0:cd0d79be0c1a | 19 | // This thread is emulating a null modem |
| BlazeX | 0:cd0d79be0c1a | 20 | void nullmodem(void const * argument) |
| BlazeX | 0:cd0d79be0c1a | 21 | { |
| BlazeX | 0:cd0d79be0c1a | 22 | pc.baud(9600); |
| BlazeX | 0:cd0d79be0c1a | 23 | |
| BlazeX | 0:cd0d79be0c1a | 24 | int c; |
| BlazeX | 0:cd0d79be0c1a | 25 | while(1) |
| BlazeX | 0:cd0d79be0c1a | 26 | { |
| BlazeX | 0:cd0d79be0c1a | 27 | led1= 1; |
| BlazeX | 0:cd0d79be0c1a | 28 | c= pc.getc(); |
| BlazeX | 0:cd0d79be0c1a | 29 | led1= 0; |
| BlazeX | 0:cd0d79be0c1a | 30 | |
| BlazeX | 0:cd0d79be0c1a | 31 | led2= 1; |
| BlazeX | 0:cd0d79be0c1a | 32 | pc.putc(c); |
| BlazeX | 0:cd0d79be0c1a | 33 | led2= 0; |
| BlazeX | 0:cd0d79be0c1a | 34 | } |
| BlazeX | 0:cd0d79be0c1a | 35 | } |
| BlazeX | 0:cd0d79be0c1a | 36 | |
| BlazeX | 0:cd0d79be0c1a | 37 | int main() |
| BlazeX | 0:cd0d79be0c1a | 38 | { |
| BlazeX | 0:cd0d79be0c1a | 39 | // Start the null modem |
| BlazeX | 0:cd0d79be0c1a | 40 | Thread nullmodemTask(&nullmodem); |
| BlazeX | 0:cd0d79be0c1a | 41 | |
| BlazeX | 0:cd0d79be0c1a | 42 | // Do something else now |
| BlazeX | 0:cd0d79be0c1a | 43 | while(1) |
| BlazeX | 0:cd0d79be0c1a | 44 | { |
| BlazeX | 0:cd0d79be0c1a | 45 | Thread::wait(20); |
| BlazeX | 0:cd0d79be0c1a | 46 | led4= !led4; |
| BlazeX | 0:cd0d79be0c1a | 47 | } |
| BlazeX | 0:cd0d79be0c1a | 48 | } |
| BlazeX | 0:cd0d79be0c1a | 49 | |
| BlazeX | 0:cd0d79be0c1a | 50 | #endif |
