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
Diff: SWO.h
- Revision:
- 1:bae4cff278f6
- Parent:
- 0:0fd55660fc26
- Child:
- 2:ef928f61a770
--- 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