Serial Wire Output (SWO) viewer for tracing purposes. Tested on F401 and ST-LINK Utility as well as for F103 and Segger J-Link SWO viewer.

Dependents:   WiFi_Scanner mbed_nucleo_swo DISCO-F429ZI_LCDTS_demo_richard TEST_SM_SPEED

Revision:
3:e5af2e131b95
Parent:
2:ef928f61a770
Child:
4:53de8ef789f3
--- a/SWO.h	Sun Dec 21 15:09:10 2014 +0000
+++ b/SWO.h	Tue Dec 23 21:05:52 2014 +0000
@@ -1,5 +1,6 @@
 /* mbed SWO Library
  *  Copyright (c) 2014, v01: WH. Ported from Segger example
+ *                      v02: WH. Added Class with Stream support
  *
  * Simple implementation for tracing via Serial Wire Output(SWO) for Cortex-M processors.
  * It can be used with Host PC software such as ST-LINK Utility or Segger J-Link SWO viewer.
@@ -28,6 +29,81 @@
 #ifndef MBED_SWO_H
 #define MBED_SWO_H
 
+//
+// This is the Class implementation
+//
+
+/**
+ * @code
+ * #include "mbed.h"
+ * #include "SWO.h"
+ *
+ * DigitalOut myled(LED1); 
+ *
+ * Serial pc(SERIAL_TX, SERIAL_RX);
+ *
+ * SWO_Channel SWO();
+ *
+ * int main() {
+ *   pc.printf("Hello World\n\r"); 
+ *
+ *   SWO.printf("\r\nHello World from SWO\r\n");
+ *   SWO.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
+ * 
+ *   while(1) {
+ *     myled = 1; // LED is ON
+ *     wait(0.2); // 200 ms
+ *     myled = 0; // LED is OFF
+ *     wait(1.0); // 1 sec
+ *   
+ *     SWO.putc('#');    
+ *   }
+ * }
+ * @endcode
+ */
+
+/** An SWO interface for debugging that supports Stream
+ *
+ * @brief Currently works on nucleo ST-LINK using ST-Link Utility and other devices that support SWD/SWO using Segger SWO viewer 
+ *
+ */
+class SWO_Channel : public Stream {
+
+public:
+  /** Create an SWO interface for debugging that supports Stream
+   *
+   */
+  SWO_Channel();
+
+#if DOXYGEN_ONLY
+  /** Write a character to the display
+    *
+    * @param c The character to write to the display
+    */
+  int putc(int c);
+
+  /** Write a formatted string to the display
+    *
+    * @param format A printf-style format string, followed by the
+    *               variables to use in formatting the string.
+    */
+  int printf(const char* format, ...);   
+#endif
+
+protected:
+  // Stream implementation functions
+  virtual int _putc(int value);
+  virtual int _getc();
+
+private:
+
+};
+
+
+//
+//This is the classic implementation
+//
+
 /**
  * @code
  * #include "mbed.h"