Wim Huiskamp
/
mbed_nucleo_swo
Test for SWO viewer library.
See here for more information.
Revision 3:3d2422feccb5, committed 2017-08-24
- Comitter:
- wim
- Date:
- Thu Aug 24 18:16:36 2017 +0000
- Parent:
- 2:9c50385f83c5
- Commit message:
- Added stream claim demo for stdout, proposed by Pavel Sorejs. Added example of SWO in a function other than main.
Changed in this revision
diff -r 9c50385f83c5 -r 3d2422feccb5 SWO.lib --- a/SWO.lib Sun Apr 03 12:39:24 2016 +0000 +++ b/SWO.lib Thu Aug 24 18:16:36 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/wim/code/SWO/#e5af2e131b95 +http://developer.mbed.org/users/wim/code/SWO/#53de8ef789f3
diff -r 9c50385f83c5 -r 3d2422feccb5 flip.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flip.cpp Thu Aug 24 18:16:36 2017 +0000 @@ -0,0 +1,43 @@ +/* mbed SWO Library + * Copyright (c) 2017, v01: WH. External declared swo + * + * 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. + * 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 "mbed.h" +#include "flip.h" +#include "SWO.h" + +extern SWO_Channel swo; + +/** +* flip() +* +* @brief invert value and print a string via SWO. +* @param int value The value to be printed. +*/ +int flip(int value) { + swo.printf(" value=%d\n\r", value); + return -value; +} \ No newline at end of file
diff -r 9c50385f83c5 -r 3d2422feccb5 flip.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flip.h Thu Aug 24 18:16:36 2017 +0000 @@ -0,0 +1,39 @@ +/* mbed SWO Library + * Copyright (c) 2017, v01: WH. External declared swo + * + * 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. + * 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_FLIP_H +#define MBED_FLIP_H + +/** +* flip() +* +* @brief invert value and print a string via SWO. +* @param int value The value to be printed. +*/ +int flip(int value); + +#endif \ No newline at end of file
diff -r 9c50385f83c5 -r 3d2422feccb5 main.cpp --- a/main.cpp Sun Apr 03 12:39:24 2016 +0000 +++ b/main.cpp Thu Aug 24 18:16:36 2017 +0000 @@ -1,5 +1,7 @@ /* mbed Test program for debug and monitoring of ST nucleo boards with SWO. * Copyright (c) 2015, v01: WH, Initial version + * 2016, v02: WH, Stream support, Added F446 + * 2017, v03: WH,PS. Added Stream claim for stdout, proposed by Pavel Sorejs * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,28 +23,42 @@ */ #include "mbed.h" +#include "flip.h" #include "SWO.h" //Single Wire Output(SWO) Test //Hook up to Host PC software ST-LINK Utility or Segger J-Link SWO viewer // #define D_SWO 1 //Enable SWO output -#define D_STREAM 1 //Select Stream or Classic implementation - -#if(D_STREAM == 1) //Stream implementation -DigitalOut myled(LED1); +DigitalOut myled(LED1); //PA_1 + +//Note: +// SWO is on pin PB_3 +// SWDIO is on pin PA_13 +// SWCLK is on pin PA_14 +// +//I2C i2c(PB_9, PB_8); //I2C, OK +//DigitalIn in(PB_3); //SWO, using pin breaks SWO viewer +//DigitalIn in(PA_10); //RX UART1, OK +//DigitalIn in(PA_13); //SWDIO, using pin breaks SWO viewer +//DigitalIn in(PA_14); //SWCLK, using pin breaks SWO viewer Serial pc(SERIAL_TX, SERIAL_RX); -SWO_Channel SWO; +SWO_Channel swo("channel"); + +int i; int main() { #if defined(TARGET_NUCLEO_F103RB) pc.printf("Hello World from ST32F103RB\n\r"); #endif +#if defined(TARGET_NUCLEO_F401RE) + pc.printf("Hello World from ST32F401RE\n\r"); +#endif #if defined(TARGET_NUCLEO_F446RE) pc.printf("Hello World from ST32F446RE\n\r"); #endif @@ -51,10 +67,19 @@ pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); #if (D_SWO == 1) -//Stream - SWO.printf("\r\nHello World from SWO\r\n"); - SWO.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); -#endif + swo.printf("\r\nHello World from SWO\r\n"); + swo.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); + + printf("Message on stdout\r\n"); + + if (swo.claim() == true) { + pc.printf("SWO has claimed stdout\r\n"); + printf("Message on stdout redirected to SWO\r\n"); + } + else { + pc.printf("SWO failed to claim stdout\r\n"); + } +#endif while(1) { myled = 1; // LED is ON @@ -62,51 +87,13 @@ myled = 0; // LED is OFF wait(1.0); // 1 sec - pc.putc('*'); + pc.putc('*'); #if (D_SWO == 1) - //Stream - SWO.putc('#'); + swo.putc('#'); + flip(i); + i = (i+1) & 0xFF; #endif } } -#else -//Classic implementation - -DigitalOut myled(LED1); - -Serial pc(SERIAL_TX, SERIAL_RX); - -SWO_Channel SWO; - -int main() { - pc.printf("Hello World\n\r"); -// pc.printf("\r\nMy Program - build " MBED_BUILD_TIMESTAMP "\r\n"); - pc.printf("\r\nMy Program - (partial) build " __DATE__ " " __TIME__ "\r\n"); - pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); - -#if (D_SWO == 1) -//Classic - 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); -#endif - - while(1) { - myled = 1; // LED is ON - wait(0.2); // 200 ms - myled = 0; // LED is OFF - wait(1.0); // 1 sec - -#if (D_SWO == 1) -//Classic -// SWO_PrintString("#"); - SWO_PrintChar('+'); -#endif - - } -} -#endif -