Test for SWO viewer library.
See here for more information.
main.cpp@2:9c50385f83c5, 2016-04-03 (annotated)
- Committer:
- wim
- Date:
- Sun Apr 03 12:39:24 2016 +0000
- Revision:
- 2:9c50385f83c5
- Parent:
- 1:3308ab077592
- Child:
- 3:3d2422feccb5
Added example for F446, updated mbed lib
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wim | 2:9c50385f83c5 | 1 | /* mbed Test program for debug and monitoring of ST nucleo boards with SWO. |
| wim | 2:9c50385f83c5 | 2 | * Copyright (c) 2015, v01: WH, Initial version |
| wim | 2:9c50385f83c5 | 3 | * |
| wim | 2:9c50385f83c5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| wim | 2:9c50385f83c5 | 5 | * of this software and associated documentation files (the "Software"), to deal |
| wim | 2:9c50385f83c5 | 6 | * in the Software without restriction, including without limitation the rights |
| wim | 2:9c50385f83c5 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| wim | 2:9c50385f83c5 | 8 | * copies of the Software, and to permit persons to whom the Software is |
| wim | 2:9c50385f83c5 | 9 | * furnished to do so, subject to the following conditions: |
| wim | 2:9c50385f83c5 | 10 | * |
| wim | 2:9c50385f83c5 | 11 | * The above copyright notice and this permission notice shall be included in |
| wim | 2:9c50385f83c5 | 12 | * all copies or substantial portions of the Software. |
| wim | 2:9c50385f83c5 | 13 | * |
| wim | 2:9c50385f83c5 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| wim | 2:9c50385f83c5 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| wim | 2:9c50385f83c5 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| wim | 2:9c50385f83c5 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| wim | 2:9c50385f83c5 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| wim | 2:9c50385f83c5 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| wim | 2:9c50385f83c5 | 20 | * THE SOFTWARE. |
| wim | 2:9c50385f83c5 | 21 | */ |
| wim | 2:9c50385f83c5 | 22 | |
| wim | 0:de9d7358fcd0 | 23 | #include "mbed.h" |
| wim | 0:de9d7358fcd0 | 24 | #include "SWO.h" |
| wim | 0:de9d7358fcd0 | 25 | |
| wim | 0:de9d7358fcd0 | 26 | //Single Wire Output(SWO) Test |
| wim | 0:de9d7358fcd0 | 27 | //Hook up to Host PC software ST-LINK Utility or Segger J-Link SWO viewer |
| wim | 0:de9d7358fcd0 | 28 | // |
| wim | 1:3308ab077592 | 29 | #define D_SWO 1 //Enable SWO output |
| wim | 1:3308ab077592 | 30 | #define D_STREAM 1 //Select Stream or Classic implementation |
| wim | 1:3308ab077592 | 31 | |
| wim | 1:3308ab077592 | 32 | |
| wim | 1:3308ab077592 | 33 | #if(D_STREAM == 1) |
| wim | 1:3308ab077592 | 34 | //Stream implementation |
| wim | 0:de9d7358fcd0 | 35 | |
| wim | 0:de9d7358fcd0 | 36 | DigitalOut myled(LED1); |
| wim | 0:de9d7358fcd0 | 37 | |
| wim | 0:de9d7358fcd0 | 38 | Serial pc(SERIAL_TX, SERIAL_RX); |
| wim | 0:de9d7358fcd0 | 39 | |
| wim | 1:3308ab077592 | 40 | SWO_Channel SWO; |
| wim | 1:3308ab077592 | 41 | |
| wim | 0:de9d7358fcd0 | 42 | int main() { |
| wim | 2:9c50385f83c5 | 43 | #if defined(TARGET_NUCLEO_F103RB) |
| wim | 2:9c50385f83c5 | 44 | pc.printf("Hello World from ST32F103RB\n\r"); |
| wim | 2:9c50385f83c5 | 45 | #endif |
| wim | 2:9c50385f83c5 | 46 | #if defined(TARGET_NUCLEO_F446RE) |
| wim | 2:9c50385f83c5 | 47 | pc.printf("Hello World from ST32F446RE\n\r"); |
| wim | 2:9c50385f83c5 | 48 | #endif |
| wim | 0:de9d7358fcd0 | 49 | // pc.printf("\r\nMy Program - build " MBED_BUILD_TIMESTAMP "\r\n"); |
| wim | 0:de9d7358fcd0 | 50 | pc.printf("\r\nMy Program - (partial) build " __DATE__ " " __TIME__ "\r\n"); |
| wim | 0:de9d7358fcd0 | 51 | pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
| wim | 0:de9d7358fcd0 | 52 | |
| wim | 0:de9d7358fcd0 | 53 | #if (D_SWO == 1) |
| wim | 1:3308ab077592 | 54 | //Stream |
| wim | 1:3308ab077592 | 55 | SWO.printf("\r\nHello World from SWO\r\n"); |
| wim | 1:3308ab077592 | 56 | SWO.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
| wim | 1:3308ab077592 | 57 | #endif |
| wim | 1:3308ab077592 | 58 | |
| wim | 0:de9d7358fcd0 | 59 | while(1) { |
| wim | 0:de9d7358fcd0 | 60 | myled = 1; // LED is ON |
| wim | 0:de9d7358fcd0 | 61 | wait(0.2); // 200 ms |
| wim | 0:de9d7358fcd0 | 62 | myled = 0; // LED is OFF |
| wim | 0:de9d7358fcd0 | 63 | wait(1.0); // 1 sec |
| wim | 2:9c50385f83c5 | 64 | |
| wim | 2:9c50385f83c5 | 65 | pc.putc('*'); |
| wim | 2:9c50385f83c5 | 66 | |
| wim | 0:de9d7358fcd0 | 67 | #if (D_SWO == 1) |
| wim | 1:3308ab077592 | 68 | //Stream |
| wim | 1:3308ab077592 | 69 | SWO.putc('#'); |
| wim | 2:9c50385f83c5 | 70 | #endif |
| wim | 1:3308ab077592 | 71 | } |
| wim | 1:3308ab077592 | 72 | } |
| wim | 1:3308ab077592 | 73 | |
| wim | 1:3308ab077592 | 74 | #else |
| wim | 1:3308ab077592 | 75 | //Classic implementation |
| wim | 1:3308ab077592 | 76 | |
| wim | 1:3308ab077592 | 77 | DigitalOut myled(LED1); |
| wim | 1:3308ab077592 | 78 | |
| wim | 1:3308ab077592 | 79 | Serial pc(SERIAL_TX, SERIAL_RX); |
| wim | 1:3308ab077592 | 80 | |
| wim | 1:3308ab077592 | 81 | SWO_Channel SWO; |
| wim | 1:3308ab077592 | 82 | |
| wim | 1:3308ab077592 | 83 | int main() { |
| wim | 1:3308ab077592 | 84 | pc.printf("Hello World\n\r"); |
| wim | 1:3308ab077592 | 85 | // pc.printf("\r\nMy Program - build " MBED_BUILD_TIMESTAMP "\r\n"); |
| wim | 1:3308ab077592 | 86 | pc.printf("\r\nMy Program - (partial) build " __DATE__ " " __TIME__ "\r\n"); |
| wim | 1:3308ab077592 | 87 | pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
| wim | 1:3308ab077592 | 88 | |
| wim | 1:3308ab077592 | 89 | #if (D_SWO == 1) |
| wim | 1:3308ab077592 | 90 | //Classic |
| wim | 1:3308ab077592 | 91 | SWO_PrintString("\r\nHello World from SWO\r\n"); |
| wim | 1:3308ab077592 | 92 | char message[64]; |
| wim | 1:3308ab077592 | 93 | sprintf(message, "CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
| wim | 1:3308ab077592 | 94 | SWO_PrintString(message); |
| wim | 1:3308ab077592 | 95 | #endif |
| wim | 1:3308ab077592 | 96 | |
| wim | 1:3308ab077592 | 97 | while(1) { |
| wim | 1:3308ab077592 | 98 | myled = 1; // LED is ON |
| wim | 1:3308ab077592 | 99 | wait(0.2); // 200 ms |
| wim | 1:3308ab077592 | 100 | myled = 0; // LED is OFF |
| wim | 1:3308ab077592 | 101 | wait(1.0); // 1 sec |
| wim | 1:3308ab077592 | 102 | |
| wim | 1:3308ab077592 | 103 | #if (D_SWO == 1) |
| wim | 1:3308ab077592 | 104 | //Classic |
| wim | 0:de9d7358fcd0 | 105 | // SWO_PrintString("#"); |
| wim | 0:de9d7358fcd0 | 106 | SWO_PrintChar('+'); |
| wim | 0:de9d7358fcd0 | 107 | #endif |
| wim | 0:de9d7358fcd0 | 108 | |
| wim | 0:de9d7358fcd0 | 109 | } |
| wim | 0:de9d7358fcd0 | 110 | } |
| wim | 1:3308ab077592 | 111 | #endif |
| wim | 0:de9d7358fcd0 | 112 |
SWO viewer