Wim Huiskamp / Mbed 2 deprecated mbed_nucleo_swo

Dependencies:   SWO mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Test program for debug and monitoring of ST nucleo boards with SWO.
00002  * Copyright (c) 2015, v01: WH, Initial version
00003  *               2016, v02: WH, Stream support, Added F446
00004  *               2017, v03: WH,PS. Added Stream claim for stdout, proposed by Pavel Sorejs 
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to deal
00008  * in the Software without restriction, including without limitation the rights
00009  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  * copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  * THE SOFTWARE.
00023  */
00024  
00025 #include "mbed.h"
00026 #include "flip.h"
00027 #include "SWO.h"
00028 
00029 //Single Wire Output(SWO) Test
00030 //Hook up to Host PC software ST-LINK Utility or Segger J-Link SWO viewer
00031 //
00032 #define D_SWO    1  //Enable SWO output
00033 
00034 //Stream implementation
00035 
00036 DigitalOut myled(LED1); //PA_1
00037 
00038 //Note:
00039 // SWO is on pin PB_3
00040 // SWDIO is on pin PA_13
00041 // SWCLK is on pin PA_14
00042 //
00043 //I2C i2c(PB_9, PB_8); //I2C, OK
00044 //DigitalIn in(PB_3);  //SWO, using pin breaks SWO viewer
00045 //DigitalIn in(PA_10); //RX UART1, OK
00046 //DigitalIn in(PA_13); //SWDIO, using pin breaks SWO viewer
00047 //DigitalIn in(PA_14); //SWCLK, using pin breaks SWO viewer
00048 
00049 Serial pc(SERIAL_TX, SERIAL_RX);
00050 
00051 SWO_Channel swo("channel");
00052 
00053 int i;
00054 
00055 int main() {
00056 #if defined(TARGET_NUCLEO_F103RB)
00057   pc.printf("Hello World from ST32F103RB\n\r");    
00058 #endif  
00059 #if defined(TARGET_NUCLEO_F401RE)
00060   pc.printf("Hello World from ST32F401RE\n\r");    
00061 #endif  
00062 #if defined(TARGET_NUCLEO_F446RE)
00063   pc.printf("Hello World from ST32F446RE\n\r");    
00064 #endif  
00065 //  pc.printf("\r\nMy Program - build " MBED_BUILD_TIMESTAMP "\r\n");
00066   pc.printf("\r\nMy Program - (partial) build " __DATE__ " " __TIME__ "\r\n");
00067   pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);  
00068 
00069 #if (D_SWO == 1)
00070   swo.printf("\r\nHello World from SWO\r\n");
00071   swo.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); 
00072 
00073   printf("Message on stdout\r\n");
00074     
00075   if (swo.claim() == true) {
00076     pc.printf("SWO has claimed stdout\r\n");
00077     printf("Message on stdout redirected to SWO\r\n");
00078   }
00079   else {
00080     pc.printf("SWO failed to claim stdout\r\n");
00081   }
00082 #endif
00083 
00084   while(1) {
00085     myled = 1; // LED is ON
00086     wait(0.2); // 200 ms
00087     myled = 0; // LED is OFF
00088     wait(1.0); // 1 sec
00089 
00090     pc.putc('*');
00091 
00092 #if (D_SWO == 1)
00093     swo.putc('#');
00094     flip(i);
00095     i = (i+1) & 0xFF;
00096 #endif  
00097   }
00098 }
00099