Create a UART to USB Serial bridge with the DipCortex

Dependencies:   USBDevice mbed

Fork of DipCortex-USB-CDC by Carl - SolderSplash Labs

Files at this revision

API Documentation at this revision

Comitter:
yihui
Date:
Wed Oct 30 02:01:50 2013 +0000
Child:
1:b9eededaba19
Commit message:
a USB to UART bridge

Changed in this revision

USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Wed Oct 30 02:01:50 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yihui/code/USBDevice/#01040319e35c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 30 02:01:50 2013 +0000
@@ -0,0 +1,37 @@
+/**
+ * USB to UART Bridge
+ */
+ 
+#include "mbed.h"
+#include "USBSerial.h"
+
+Serial uart(USBTX, USBRX);
+USBSerial pc;
+
+// Called by ISR
+void settingsChanged(int baud, int bits, int parity, int stop)
+{
+    const Serial::Parity parityTable[] = {Serial::None, Serial::Odd, Serial::Even, Serial::Forced0, Serial::Forced1};
+    
+    if (stop != 2) {
+        stop = 1;   // stop bit(s) = 1 or 1.5
+    }
+    
+    uart.baud(baud);
+    uart.format(bits, parityTable[parity], stop);
+}
+
+int main()
+{
+    pc.attach(settingsChanged);
+    
+    while (1) {
+        while (uart.readable()) {
+           pc.putc(uart.getc());
+        }
+        
+        while (pc.readable()) {
+            uart.putc(pc.getc());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Wed Oct 30 02:01:50 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/#f37f3b9c9f0b