Demonstration program for STM Studio monitor and debug tool.

Dependencies:   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 STM Studio.
00002  * Copyright (c) 2016, v01: WH, Initial version
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022 #include "mbed.h"
00023 
00024 //#define D_DEBUG 0  //disable debug with STMstudio
00025 #define D_DEBUG 1  //enable debug with STMstudio
00026 
00027 #if defined(TARGET_LPC1768)
00028 // SPI for LPC1768
00029 #define D_MOSI                 p5
00030 #define D_MISO                 p6
00031 #define D_SCLK                 p7
00032 #define D_CS                   p8
00033 
00034 //I2C for LPC1768
00035 #define D_SCL                  p10
00036 #define D_SDA                  p9
00037 
00038 // Serial for LPC1768
00039 #define D_TX                   USBTX
00040 #define D_RX                   USBRX
00041 
00042 // LEDs for LPC1768
00043 #define D_LED_ON               1
00044 #define D_LED_OFF              0
00045 
00046 #define D_LED1                 LED1
00047 #define D_LED2                 LED2
00048 #define D_LED3                 LED3
00049 #define D_LED4                 LED4
00050 
00051 #define D_BTN1                 p20
00052 #endif
00053 
00054 #if defined(TARGET_NUCLEO_F103RB)
00055 // Serial for ST32F103
00056 #define D_TX                   SERIAL_TX
00057 #define D_RX                   SERIAL_RX
00058 
00059 // SPI for ST32F103
00060 #define D_MOSI                 PA_7
00061 #define D_MISO                 PA_6
00062 #define D_SCLK                 PA_5 /*LED1 Green*/
00063 #define D_CS                   PB_6
00064 
00065 //I2C for ST32F103
00066 #define D_SCL                  PB_8
00067 #define D_SDA                  PB_9
00068 
00069 //LEDs
00070 #define D_LED_ON               1
00071 #define D_LED_OFF              0
00072  
00073 #define D_LED1                 LED1 /*PA_5 Green*/
00074 #define D_LED2                 LED2
00075 #define D_LED3                 LED3
00076 #define D_LED4                 LED3
00077 
00078 #define D_BTN1                 PC_13
00079 #endif
00080 
00081 //SPI Bus
00082 //SPI spi(D_MOSI, D_MISO, D_SCLK); //MOSI, MISO, SCK
00083 
00084 //I2C Bus
00085 //I2C i2c(D_SDA, D_SCL);       //SDA, SCL
00086 
00087 //Serial Bus
00088 Serial pc(D_TX,D_RX);
00089 
00090 //DigitalOut
00091 DigitalOut myled1(D_LED1); /*Blue*/
00092 //DigitalOut myled2(D_LED2);  /*Green*/
00093 //DigitalOut myled3(D_LED3);  /*Red*/
00094 //DigitalOut myled3(D_LED4);  /*Red*/
00095 
00096 DigitalIn myBtn1(D_BTN1);
00097 
00098 int i;
00099 char c;
00100 float s;
00101 bool b1;
00102 volatile int b2 = 1;
00103 float wt = 0.7f;
00104 int main() {
00105 
00106 #if defined(TARGET_LPC1768)
00107   pc.printf("\r\nHello World from LPC1768\r\n");
00108 #endif  
00109 #if defined(TARGET_KL25Z)
00110   pc.printf("\r\nHello World from KL25Z\r\n");
00111 #endif  
00112 #if defined(TARGET_LPC812)
00113   pc.printf("\r\nHello World from LPC812\r\n");
00114 #endif
00115 #if defined(TARGET_LPC1549)
00116   pc.printf("Hello World from LPC1549\n\r");    
00117 #endif  
00118 #if defined(TARGET_NUCLEO_F401RE)
00119   pc.printf("Hello World from ST32F401RE\n\r");    
00120 #endif  
00121 #if defined(TARGET_NUCLEO_F103RB)
00122   pc.printf("Hello World from ST32F103RB\n\r");    
00123 #endif  
00124     
00125 #if(D_DEBUG == 1) 
00126   pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);      
00127 
00128 //The STM Studio tool can import .elf or .axf files which contain a memory map of all variables used in your code.
00129 //However, the mbed online compiler does not generate these files, so instead use the following printf to
00130 //figure out where the vars that you want to monitor (or manipulate) are located and manually paste their addresses into STMstudio
00131   pc.printf("i is at 0x%08X\r\n", &i);
00132   pc.printf("c is at 0x%08X\r\n", &c);
00133   pc.printf("s is at 0x%08X\r\n", &s);
00134   pc.printf("b1 is at 0x%08X\r\n", &b1);
00135   pc.printf("b2 is at 0x%08X\r\n", &b2);
00136 #endif
00137              
00138   while(1) {
00139     myled1 = D_LED_ON;  // LED is ON
00140     wait(0.1);          // 100 ms
00141     myled1 = D_LED_OFF; // LED is OFF
00142     wait(0.1);          // 100 ms        
00143     myled1 = D_LED_ON;  // LED is ON
00144     wait(0.1);          // 100 ms
00145     myled1 = D_LED_OFF; // LED is OFF        
00146 //    wait(0.7);          // 700 ms
00147     wait(wt);          // variable ms
00148         
00149     i++;
00150     c++;
00151     s = 100.0f * sin((float)c * 3.1415f / 128.0f);
00152     b1 = myBtn1;
00153     if (b1 && (b2 == 1)) {
00154       pc.putc('1');
00155       wt = 0.7f;
00156     }
00157     else {
00158       pc.putc('0');
00159       wt = 0.3f;      
00160     }
00161   }
00162 
00163   pc.printf("\nBye World!\n");
00164 }