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, committed 2014-12-23
- Comitter:
- wim
- Date:
- Tue Dec 23 21:05:52 2014 +0000
- Parent:
- 2:ef928f61a770
- Child:
- 4:53de8ef789f3
- Commit message:
- Added Class SWO_Channel that supports Stream putc() and printf().
Changed in this revision
| SWO.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SWO.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SWO.cpp Sun Dec 21 15:09:10 2014 +0000
+++ b/SWO.cpp Tue Dec 23 21:05:52 2014 +0000
@@ -1,5 +1,6 @@
/* mbed SWO Library
* Copyright (c) 2014, v01: WH. Ported from Segger example (www.segger.com)
+ * 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.
@@ -27,11 +28,47 @@
#include "mbed.h"
#include "SWO.h"
+//
+// This the Class implementation
+//
+
+/** Create and 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
+ */
+SWO_Channel::SWO_Channel () {
+ //May want to add initialisation stuff here
+}
+
+/** Write a single character (Stream implementation)
+ *
+ * @param value character to be displayed
+ * @return value
+ */
+int SWO_Channel::_putc(int value) {
+
+ //Use CMSIS_core_DebugFunctions. See core_cm3.h
+ ITM_SendChar(value);
+
+ return value;
+}
+
+/** Get a single character (Stream implementation)
+ * @return -1 Not supported
+ */
+int SWO_Channel::_getc() {
+ return -1;
+}
+
+
+//
+//This is the classic implementation
+//
+
/**
* Defines for Cortex-M debug unit
*/
-#define ITM_STIM_U32(n) (*(volatile unsigned int*)(0xE0000000+4*n)) // Stimulus Port n Register word access
-#define ITM_STIM_U8(n) (*(volatile char*)(0xE0000000+4*n)) // Stimulus Port n Register byte access
+#define ITM_STIM_U32(n) (*(volatile unsigned int*) (0xE0000000+4*n)) // Stimulus Port n Register word access
+#define ITM_STIM_U8(n) (*(volatile unsigned char*)(0xE0000000+4*n)) // Stimulus Port n Register byte access
//#define ITM_STIM_U32_0 (*(volatile unsigned int*)0xE0000000) // Stimulus Port 0 Register word access
//#define ITM_STIM_U8_0 (*(volatile char*)0xE0000000) // Stimulus Port 0 Register byte access
#define ITM_ENA (*(volatile unsigned int*)0xE0000E00) // Trace Enable Ports Register
@@ -171,4 +208,7 @@
while (*s) {
SWO_PrintChar(*s++);
}
-}
\ No newline at end of file
+}
+
+
+
--- 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"
SWO viewer