Test for SWO viewer library.

Dependencies:   SWO mbed

See here for more information.

Committer:
wim
Date:
Tue Dec 23 21:06:11 2014 +0000
Revision:
1:3308ab077592
Parent:
0:de9d7358fcd0
Child:
2:9c50385f83c5
Added Class SWO_Channel that supports Stream putc() and printf().

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:de9d7358fcd0 1
wim 0:de9d7358fcd0 2 #include "mbed.h"
wim 0:de9d7358fcd0 3 #include "SWO.h"
wim 0:de9d7358fcd0 4
wim 0:de9d7358fcd0 5 //Single Wire Output(SWO) Test
wim 0:de9d7358fcd0 6 //Hook up to Host PC software ST-LINK Utility or Segger J-Link SWO viewer
wim 0:de9d7358fcd0 7 //
wim 1:3308ab077592 8 #define D_SWO 1 //Enable SWO output
wim 1:3308ab077592 9 #define D_STREAM 1 //Select Stream or Classic implementation
wim 1:3308ab077592 10
wim 1:3308ab077592 11
wim 1:3308ab077592 12 #if(D_STREAM == 1)
wim 1:3308ab077592 13 //Stream implementation
wim 0:de9d7358fcd0 14
wim 0:de9d7358fcd0 15 DigitalOut myled(LED1);
wim 0:de9d7358fcd0 16
wim 0:de9d7358fcd0 17 Serial pc(SERIAL_TX, SERIAL_RX);
wim 0:de9d7358fcd0 18
wim 1:3308ab077592 19 SWO_Channel SWO;
wim 1:3308ab077592 20
wim 0:de9d7358fcd0 21 int main() {
wim 0:de9d7358fcd0 22 pc.printf("Hello World\n\r");
wim 0:de9d7358fcd0 23 // pc.printf("\r\nMy Program - build " MBED_BUILD_TIMESTAMP "\r\n");
wim 0:de9d7358fcd0 24 pc.printf("\r\nMy Program - (partial) build " __DATE__ " " __TIME__ "\r\n");
wim 0:de9d7358fcd0 25 pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
wim 0:de9d7358fcd0 26
wim 0:de9d7358fcd0 27 #if (D_SWO == 1)
wim 1:3308ab077592 28 //Stream
wim 1:3308ab077592 29 SWO.printf("\r\nHello World from SWO\r\n");
wim 1:3308ab077592 30 SWO.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
wim 1:3308ab077592 31 #endif
wim 1:3308ab077592 32
wim 0:de9d7358fcd0 33 while(1) {
wim 0:de9d7358fcd0 34 myled = 1; // LED is ON
wim 0:de9d7358fcd0 35 wait(0.2); // 200 ms
wim 0:de9d7358fcd0 36 myled = 0; // LED is OFF
wim 0:de9d7358fcd0 37 wait(1.0); // 1 sec
wim 0:de9d7358fcd0 38
wim 0:de9d7358fcd0 39 #if (D_SWO == 1)
wim 1:3308ab077592 40 //Stream
wim 1:3308ab077592 41 SWO.putc('#');
wim 1:3308ab077592 42 #endif
wim 1:3308ab077592 43
wim 1:3308ab077592 44 }
wim 1:3308ab077592 45 }
wim 1:3308ab077592 46
wim 1:3308ab077592 47 #else
wim 1:3308ab077592 48 //Classic implementation
wim 1:3308ab077592 49
wim 1:3308ab077592 50 DigitalOut myled(LED1);
wim 1:3308ab077592 51
wim 1:3308ab077592 52 Serial pc(SERIAL_TX, SERIAL_RX);
wim 1:3308ab077592 53
wim 1:3308ab077592 54 SWO_Channel SWO;
wim 1:3308ab077592 55
wim 1:3308ab077592 56 int main() {
wim 1:3308ab077592 57 pc.printf("Hello World\n\r");
wim 1:3308ab077592 58 // pc.printf("\r\nMy Program - build " MBED_BUILD_TIMESTAMP "\r\n");
wim 1:3308ab077592 59 pc.printf("\r\nMy Program - (partial) build " __DATE__ " " __TIME__ "\r\n");
wim 1:3308ab077592 60 pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
wim 1:3308ab077592 61
wim 1:3308ab077592 62 #if (D_SWO == 1)
wim 1:3308ab077592 63 //Classic
wim 1:3308ab077592 64 SWO_PrintString("\r\nHello World from SWO\r\n");
wim 1:3308ab077592 65 char message[64];
wim 1:3308ab077592 66 sprintf(message, "CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
wim 1:3308ab077592 67 SWO_PrintString(message);
wim 1:3308ab077592 68 #endif
wim 1:3308ab077592 69
wim 1:3308ab077592 70 while(1) {
wim 1:3308ab077592 71 myled = 1; // LED is ON
wim 1:3308ab077592 72 wait(0.2); // 200 ms
wim 1:3308ab077592 73 myled = 0; // LED is OFF
wim 1:3308ab077592 74 wait(1.0); // 1 sec
wim 1:3308ab077592 75
wim 1:3308ab077592 76 #if (D_SWO == 1)
wim 1:3308ab077592 77 //Classic
wim 0:de9d7358fcd0 78 // SWO_PrintString("#");
wim 0:de9d7358fcd0 79 SWO_PrintChar('+');
wim 0:de9d7358fcd0 80 #endif
wim 0:de9d7358fcd0 81
wim 0:de9d7358fcd0 82 }
wim 0:de9d7358fcd0 83 }
wim 1:3308ab077592 84 #endif
wim 0:de9d7358fcd0 85