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

Committer:
wim
Date:
Sat Dec 20 22:30:12 2014 +0000
Revision:
1:bae4cff278f6
Parent:
0:0fd55660fc26
Child:
2:ef928f61a770
SWO lib first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 1:bae4cff278f6 1 /* mbed SWO Library
wim 1:bae4cff278f6 2 * Copyright (c) 2014, v01: WH. Ported from Segger example
wim 1:bae4cff278f6 3 *
wim 1:bae4cff278f6 4 * Simple implementation for tracing via Single Wire Output(SWO) for Cortex-M processors.
wim 1:bae4cff278f6 5 * It can be used with Host PC software such as ST-LINK Utility or Segger J-Link SWO viewer.
wim 1:bae4cff278f6 6 * This sample implementation ensures that output via SWO is enabled in order to guarantee
wim 1:bae4cff278f6 7 * that the application does not hang.
wim 1:bae4cff278f6 8 *
wim 1:bae4cff278f6 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
wim 1:bae4cff278f6 10 * of this software and associated documentation files (the "Software"), to deal
wim 1:bae4cff278f6 11 * in the Software without restriction, including without limitation the rights
wim 1:bae4cff278f6 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 1:bae4cff278f6 13 * copies of the Software, and to permit persons to whom the Software is
wim 1:bae4cff278f6 14 * furnished to do so, subject to the following conditions:
wim 1:bae4cff278f6 15 *
wim 1:bae4cff278f6 16 * The above copyright notice and this permission notice shall be included in
wim 1:bae4cff278f6 17 * all copies or substantial portions of the Software.
wim 1:bae4cff278f6 18 *
wim 1:bae4cff278f6 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 1:bae4cff278f6 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 1:bae4cff278f6 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 1:bae4cff278f6 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 1:bae4cff278f6 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 1:bae4cff278f6 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 1:bae4cff278f6 25 * THE SOFTWARE.
wim 1:bae4cff278f6 26 */
wim 1:bae4cff278f6 27
wim 1:bae4cff278f6 28 #ifndef MBED_SWO_H
wim 1:bae4cff278f6 29 #define MBED_SWO_H
wim 0:0fd55660fc26 30
wim 1:bae4cff278f6 31 /**
wim 1:bae4cff278f6 32 * @code
wim 1:bae4cff278f6 33 * #include "mbed.h"
wim 1:bae4cff278f6 34 * #include "SWO.h"
wim 1:bae4cff278f6 35 *
wim 1:bae4cff278f6 36 * DigitalOut myled(LED1);
wim 1:bae4cff278f6 37 *
wim 1:bae4cff278f6 38 * Serial pc(SERIAL_TX, SERIAL_RX);
wim 1:bae4cff278f6 39 *
wim 1:bae4cff278f6 40 * int main() {
wim 1:bae4cff278f6 41 * pc.printf("Hello World\n\r");
wim 1:bae4cff278f6 42 *
wim 1:bae4cff278f6 43 * SWO_PrintString("\r\nHello World from SWO\r\n");
wim 1:bae4cff278f6 44 * char message[64];
wim 1:bae4cff278f6 45 * sprintf(message, "CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
wim 1:bae4cff278f6 46 * SWO_PrintString(message);
wim 1:bae4cff278f6 47 *
wim 1:bae4cff278f6 48 * while(1) {
wim 1:bae4cff278f6 49 * myled = 1; // LED is ON
wim 1:bae4cff278f6 50 * wait(0.2); // 200 ms
wim 1:bae4cff278f6 51 * myled = 0; // LED is OFF
wim 1:bae4cff278f6 52 * wait(1.0); // 1 sec
wim 1:bae4cff278f6 53 *
wim 1:bae4cff278f6 54 * SWO_PrintString("#");
wim 1:bae4cff278f6 55 * }
wim 1:bae4cff278f6 56 * }
wim 1:bae4cff278f6 57 * @endcode
wim 1:bae4cff278f6 58 */
wim 1:bae4cff278f6 59
wim 1:bae4cff278f6 60 // Prototypes
wim 1:bae4cff278f6 61
wim 1:bae4cff278f6 62 /**
wim 1:bae4cff278f6 63 * @brief
wim 1:bae4cff278f6 64 * Checks if SWO is set up. If it is not, return,
wim 1:bae4cff278f6 65 * to avoid program hangs if no debugger is connected.
wim 1:bae4cff278f6 66 * If it is set up, print a character to the ITM_STIM register
wim 1:bae4cff278f6 67 * in order to provide data for SWO.
wim 1:bae4cff278f6 68 * @param c The Character to be printed.
wim 1:bae4cff278f6 69 * @notes Additional checks for device specific registers can be added.
wim 0:0fd55660fc26 70 */
wim 0:0fd55660fc26 71 void SWO_PrintChar (char c);
wim 1:bae4cff278f6 72
wim 1:bae4cff278f6 73
wim 1:bae4cff278f6 74 /**
wim 1:bae4cff278f6 75 *
wim 1:bae4cff278f6 76 * SWO_PrintString()
wim 1:bae4cff278f6 77 *
wim 1:bae4cff278f6 78 * @brief Print a string via SWO.
wim 1:bae4cff278f6 79 * @param *s The string to be printed.
wim 1:bae4cff278f6 80 */
wim 0:0fd55660fc26 81 void SWO_PrintString(const char *s);
wim 0:0fd55660fc26 82
wim 0:0fd55660fc26 83 #endif