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

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Sat Dec 20 22:30:12 2014 +0000
Parent:
0:0fd55660fc26
Child:
2:ef928f61a770
Commit message:
SWO lib first release

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	Fri Mar 28 19:32:13 2014 +0000
+++ b/SWO.cpp	Sat Dec 20 22:30:12 2014 +0000
@@ -1,67 +1,86 @@
+/* mbed SWO Library
+ *  Copyright (c) 2014, v01: WH. Ported from Segger example
+ *
+ * Simple implementation for tracing via Single 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.
+ * This sample implementation ensures that output via SWO is enabled in order to guarantee
+ * that the application does not hang.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
 
 #include "SWO.h"
 
-
-/*********************************************************************
-*
-* Defines for Cortex-M debug unit
-*/
+/**
+ *
+ * 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+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
 #define ITM_TCR         (*(volatile unsigned int*)0xE0000E80)        // Trace control register
 
-
+/**
+ *
+ * SWO_PrintChar()
+ *
+ * @brief 
+ *   Checks if SWO is set up. If it is not, return,
+ *    to avoid program hangs if no debugger is connected.
+ *   If it is set up, print a character to the ITM_STIM register
+ *    in order to provide data for SWO.
+ * @param c The Character to be printed.
+ * @notes   Additional checks for device specific registers can be added.
+ */
+void SWO_PrintChar(char c) {
 
-/*********************************************************************
-*
-* SWO_PrintChar()
-*
-* @brief 
-*   Checks if SWO is set up. If it is not, return,
-*    to avoid program hangs if no debugger is connected.
-*   If it is set up, print a character to the ITM_STIM register
-*    in order to provide data for SWO.
-* @param c The Character to be printed.
-* @notes   Additional checks for device specific registers can be added.
-*/
-void SWO_PrintChar(char c) {
-  //
   // Check if ITM_TCR.ITMENA is set
-  //
   if ((ITM_TCR & 1) == 0) {
     return;
   }
-  //
+
   // Check if stimulus port is enabled
-  //
   if ((ITM_ENA & 1) == 0) {
     return;
   }
-  //
-  // Wait until STIMx is ready,
-  // then send data
-  //
-//  while ((ITM_STIM_U8(0) & 1) == 0);
-//  ITM_STIM_U8(0) = c;
 
-  while ((ITM_STIM_U32(0) & 1) == 0);
-  ITM_STIM_U32(0) = c;
+  // Wait until STIMx FIFO is ready, then send data
+  while ((ITM_STIM_U8(0) & 1) == 0);
+  ITM_STIM_U8(0) = c;
+
+//  while ((ITM_STIM_U32(0) & 1) == 0);
+//  ITM_STIM_U32(0) = c;
 }
 
-/*********************************************************************
-*
-* SWO_PrintString()
-*
-* @brief Print a string via SWO.
-* @param *s The string to be printed.
-*
-*/
+/**
+ *
+ * SWO_PrintString()
+ *
+ * @brief Print a string via SWO.
+ * @param *s The string to be printed.
+ *
+ */
 void SWO_PrintString(const char *s) {
-  //
-  // Print out character per character
-  //
+
+  // Print out characters until \0
   while (*s) {
     SWO_PrintChar(*s++);
   }
--- a/SWO.h	Fri Mar 28 19:32:13 2014 +0000
+++ b/SWO.h	Sat Dec 20 22:30:12 2014 +0000
@@ -1,18 +1,83 @@
-/*----------------------------------------------------------------------
-File    : SWO.h
-Purpose : Simple implementation for output via SWO for Cortex-M processors.
-          It can be used with any IDE. This sample implementation ensures that
-          output via SWO is enabled in order to guarantee that the application 
-          does not hang.
-        
-*/
-#ifndef _SWO_H
-#define _SWO_H
+/* mbed SWO Library
+ *  Copyright (c) 2014, v01: WH. Ported from Segger example
+ *
+ * Simple implementation for tracing via Single 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.
+ * This sample implementation ensures that output via SWO is enabled in order to guarantee
+ * that the application does not hang.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+ 
+#ifndef MBED_SWO_H
+#define MBED_SWO_H
 
-/** Prototypes
+/**
+ * @code
+ * #include "mbed.h"
+ * #include "SWO.h"
+ *
+ * DigitalOut myled(LED1); 
+ *
+ * Serial pc(SERIAL_TX, SERIAL_RX);
+ *
+ * int main() {
+ *   pc.printf("Hello World\n\r"); 
+ *
+ *   SWO_PrintString("\r\nHello World from SWO\r\n");
+ *   char message[64];
+ *   sprintf(message, "CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
+ *   SWO_PrintString(message);      
+ * 
+ *   while(1) {
+ *     myled = 1; // LED is ON
+ *     wait(0.2); // 200 ms
+ *     myled = 0; // LED is OFF
+ *     wait(1.0); // 1 sec
+ *   
+ *     SWO_PrintString("#");    
+ *   }
+ * }
+ * @endcode
+ */
+
+// Prototypes
+
+/**
+* @brief 
+*   Checks if SWO is set up. If it is not, return,
+*    to avoid program hangs if no debugger is connected.
+*   If it is set up, print a character to the ITM_STIM register
+*    in order to provide data for SWO.
+* @param c The Character to be printed.
+* @notes   Additional checks for device specific registers can be added.
 */
 void SWO_PrintChar  (char c);
+
+
+/**
+*
+* SWO_PrintString()
+*
+* @brief Print a string via SWO.
+* @param *s The string to be printed.
+*/
 void SWO_PrintString(const char *s);
 
-
 #endif
\ No newline at end of file