Demonstration program for STM Studio monitor and debug tool.

Dependencies:   mbed

The ARM Cortex M series supports tracing capabilities through the Serial Wire Debug (SWD) en Serial Wire Output(SWO) port. A simple lib for tracing via SWO is available here. The STM Studio application provided for free by ST has significantly more features. STM Studio is a graphical user interface that allows real-time sampling and visualizing of user's variables while the application is running.

/media/uploads/wim/stm-studio.jpg

STM Studio is designed to run on PCs with Microsoft Windows operating systems. This tool works with STM32 microcontrollers through JTAG or SWD (serial wire debug) interface. The ST-LINK/v2-1 interface on the mbed nucleo boards can be used with STM Studio. The application code shown here provides an example.

More info is available here

Committer:
wim
Date:
Sat Mar 19 22:22:59 2016 +0000
Revision:
6:3d66c065c42a
Parent:
5:233f5aeeec5f
Test 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 1:fe3e63b1234b 1 /* mbed Test program for debug and monitoring of ST nucleo boards with STM Studio.
wim 0:f3cd9dffaf5e 2 * Copyright (c) 2016, v01: WH, Initial version
wim 0:f3cd9dffaf5e 3 *
wim 0:f3cd9dffaf5e 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
wim 0:f3cd9dffaf5e 5 * of this software and associated documentation files (the "Software"), to deal
wim 0:f3cd9dffaf5e 6 * in the Software without restriction, including without limitation the rights
wim 0:f3cd9dffaf5e 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 0:f3cd9dffaf5e 8 * copies of the Software, and to permit persons to whom the Software is
wim 0:f3cd9dffaf5e 9 * furnished to do so, subject to the following conditions:
wim 0:f3cd9dffaf5e 10 *
wim 0:f3cd9dffaf5e 11 * The above copyright notice and this permission notice shall be included in
wim 0:f3cd9dffaf5e 12 * all copies or substantial portions of the Software.
wim 0:f3cd9dffaf5e 13 *
wim 0:f3cd9dffaf5e 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 0:f3cd9dffaf5e 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 0:f3cd9dffaf5e 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 0:f3cd9dffaf5e 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 0:f3cd9dffaf5e 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 0:f3cd9dffaf5e 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 0:f3cd9dffaf5e 20 * THE SOFTWARE.
wim 0:f3cd9dffaf5e 21 */
wim 0:f3cd9dffaf5e 22 #include "mbed.h"
wim 0:f3cd9dffaf5e 23
wim 0:f3cd9dffaf5e 24 //#define D_DEBUG 0 //disable debug with STMstudio
wim 0:f3cd9dffaf5e 25 #define D_DEBUG 1 //enable debug with STMstudio
wim 0:f3cd9dffaf5e 26
wim 0:f3cd9dffaf5e 27 #if defined(TARGET_LPC1768)
wim 0:f3cd9dffaf5e 28 // SPI for LPC1768
wim 0:f3cd9dffaf5e 29 #define D_MOSI p5
wim 0:f3cd9dffaf5e 30 #define D_MISO p6
wim 0:f3cd9dffaf5e 31 #define D_SCLK p7
wim 0:f3cd9dffaf5e 32 #define D_CS p8
wim 0:f3cd9dffaf5e 33
wim 0:f3cd9dffaf5e 34 //I2C for LPC1768
wim 0:f3cd9dffaf5e 35 #define D_SCL p10
wim 0:f3cd9dffaf5e 36 #define D_SDA p9
wim 0:f3cd9dffaf5e 37
wim 0:f3cd9dffaf5e 38 // Serial for LPC1768
wim 0:f3cd9dffaf5e 39 #define D_TX USBTX
wim 0:f3cd9dffaf5e 40 #define D_RX USBRX
wim 0:f3cd9dffaf5e 41
wim 0:f3cd9dffaf5e 42 // LEDs for LPC1768
wim 0:f3cd9dffaf5e 43 #define D_LED_ON 1
wim 0:f3cd9dffaf5e 44 #define D_LED_OFF 0
wim 0:f3cd9dffaf5e 45
wim 0:f3cd9dffaf5e 46 #define D_LED1 LED1
wim 0:f3cd9dffaf5e 47 #define D_LED2 LED2
wim 0:f3cd9dffaf5e 48 #define D_LED3 LED3
wim 0:f3cd9dffaf5e 49 #define D_LED4 LED4
wim 0:f3cd9dffaf5e 50
wim 0:f3cd9dffaf5e 51 #define D_BTN1 p20
wim 0:f3cd9dffaf5e 52 #endif
wim 0:f3cd9dffaf5e 53
wim 0:f3cd9dffaf5e 54 #if defined(TARGET_NUCLEO_F103RB)
wim 0:f3cd9dffaf5e 55 // Serial for ST32F103
wim 0:f3cd9dffaf5e 56 #define D_TX SERIAL_TX
wim 0:f3cd9dffaf5e 57 #define D_RX SERIAL_RX
wim 0:f3cd9dffaf5e 58
wim 0:f3cd9dffaf5e 59 // SPI for ST32F103
wim 0:f3cd9dffaf5e 60 #define D_MOSI PA_7
wim 0:f3cd9dffaf5e 61 #define D_MISO PA_6
wim 0:f3cd9dffaf5e 62 #define D_SCLK PA_5 /*LED1 Green*/
wim 0:f3cd9dffaf5e 63 #define D_CS PB_6
wim 0:f3cd9dffaf5e 64
wim 0:f3cd9dffaf5e 65 //I2C for ST32F103
wim 0:f3cd9dffaf5e 66 #define D_SCL PB_8
wim 0:f3cd9dffaf5e 67 #define D_SDA PB_9
wim 0:f3cd9dffaf5e 68
wim 0:f3cd9dffaf5e 69 //LEDs
wim 0:f3cd9dffaf5e 70 #define D_LED_ON 1
wim 0:f3cd9dffaf5e 71 #define D_LED_OFF 0
wim 0:f3cd9dffaf5e 72
wim 0:f3cd9dffaf5e 73 #define D_LED1 LED1 /*PA_5 Green*/
wim 0:f3cd9dffaf5e 74 #define D_LED2 LED2
wim 0:f3cd9dffaf5e 75 #define D_LED3 LED3
wim 0:f3cd9dffaf5e 76 #define D_LED4 LED3
wim 0:f3cd9dffaf5e 77
wim 0:f3cd9dffaf5e 78 #define D_BTN1 PC_13
wim 0:f3cd9dffaf5e 79 #endif
wim 0:f3cd9dffaf5e 80
wim 0:f3cd9dffaf5e 81 //SPI Bus
wim 0:f3cd9dffaf5e 82 //SPI spi(D_MOSI, D_MISO, D_SCLK); //MOSI, MISO, SCK
wim 0:f3cd9dffaf5e 83
wim 0:f3cd9dffaf5e 84 //I2C Bus
wim 0:f3cd9dffaf5e 85 //I2C i2c(D_SDA, D_SCL); //SDA, SCL
wim 0:f3cd9dffaf5e 86
wim 0:f3cd9dffaf5e 87 //Serial Bus
wim 0:f3cd9dffaf5e 88 Serial pc(D_TX,D_RX);
wim 0:f3cd9dffaf5e 89
wim 0:f3cd9dffaf5e 90 //DigitalOut
wim 0:f3cd9dffaf5e 91 DigitalOut myled1(D_LED1); /*Blue*/
wim 0:f3cd9dffaf5e 92 //DigitalOut myled2(D_LED2); /*Green*/
wim 0:f3cd9dffaf5e 93 //DigitalOut myled3(D_LED3); /*Red*/
wim 0:f3cd9dffaf5e 94 //DigitalOut myled3(D_LED4); /*Red*/
wim 0:f3cd9dffaf5e 95
wim 0:f3cd9dffaf5e 96 DigitalIn myBtn1(D_BTN1);
wim 0:f3cd9dffaf5e 97
wim 0:f3cd9dffaf5e 98 int i;
wim 0:f3cd9dffaf5e 99 char c;
wim 0:f3cd9dffaf5e 100 float s;
wim 0:f3cd9dffaf5e 101 bool b1;
wim 0:f3cd9dffaf5e 102 volatile int b2 = 1;
wim 0:f3cd9dffaf5e 103 float wt = 0.7f;
wim 0:f3cd9dffaf5e 104 int main() {
wim 0:f3cd9dffaf5e 105
wim 0:f3cd9dffaf5e 106 #if defined(TARGET_LPC1768)
wim 0:f3cd9dffaf5e 107 pc.printf("\r\nHello World from LPC1768\r\n");
wim 0:f3cd9dffaf5e 108 #endif
wim 0:f3cd9dffaf5e 109 #if defined(TARGET_KL25Z)
wim 0:f3cd9dffaf5e 110 pc.printf("\r\nHello World from KL25Z\r\n");
wim 0:f3cd9dffaf5e 111 #endif
wim 0:f3cd9dffaf5e 112 #if defined(TARGET_LPC812)
wim 0:f3cd9dffaf5e 113 pc.printf("\r\nHello World from LPC812\r\n");
wim 0:f3cd9dffaf5e 114 #endif
wim 0:f3cd9dffaf5e 115 #if defined(TARGET_LPC1549)
wim 0:f3cd9dffaf5e 116 pc.printf("Hello World from LPC1549\n\r");
wim 0:f3cd9dffaf5e 117 #endif
wim 0:f3cd9dffaf5e 118 #if defined(TARGET_NUCLEO_F401RE)
wim 0:f3cd9dffaf5e 119 pc.printf("Hello World from ST32F401RE\n\r");
wim 0:f3cd9dffaf5e 120 #endif
wim 0:f3cd9dffaf5e 121 #if defined(TARGET_NUCLEO_F103RB)
wim 0:f3cd9dffaf5e 122 pc.printf("Hello World from ST32F103RB\n\r");
wim 0:f3cd9dffaf5e 123 #endif
wim 0:f3cd9dffaf5e 124
wim 0:f3cd9dffaf5e 125 #if(D_DEBUG == 1)
wim 0:f3cd9dffaf5e 126 pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
wim 0:f3cd9dffaf5e 127
wim 1:fe3e63b1234b 128 //The STM Studio tool can import .elf or .axf files which contain a memory map of all variables used in your code.
wim 0:f3cd9dffaf5e 129 //However, the mbed online compiler does not generate these files, so instead use the following printf to
wim 0:f3cd9dffaf5e 130 //figure out where the vars that you want to monitor (or manipulate) are located and manually paste their addresses into STMstudio
wim 0:f3cd9dffaf5e 131 pc.printf("i is at 0x%08X\r\n", &i);
wim 0:f3cd9dffaf5e 132 pc.printf("c is at 0x%08X\r\n", &c);
wim 0:f3cd9dffaf5e 133 pc.printf("s is at 0x%08X\r\n", &s);
wim 0:f3cd9dffaf5e 134 pc.printf("b1 is at 0x%08X\r\n", &b1);
wim 0:f3cd9dffaf5e 135 pc.printf("b2 is at 0x%08X\r\n", &b2);
wim 0:f3cd9dffaf5e 136 #endif
wim 5:233f5aeeec5f 137
wim 0:f3cd9dffaf5e 138 while(1) {
wim 0:f3cd9dffaf5e 139 myled1 = D_LED_ON; // LED is ON
wim 0:f3cd9dffaf5e 140 wait(0.1); // 100 ms
wim 0:f3cd9dffaf5e 141 myled1 = D_LED_OFF; // LED is OFF
wim 0:f3cd9dffaf5e 142 wait(0.1); // 100 ms
wim 0:f3cd9dffaf5e 143 myled1 = D_LED_ON; // LED is ON
wim 0:f3cd9dffaf5e 144 wait(0.1); // 100 ms
wim 0:f3cd9dffaf5e 145 myled1 = D_LED_OFF; // LED is OFF
wim 0:f3cd9dffaf5e 146 // wait(0.7); // 700 ms
wim 0:f3cd9dffaf5e 147 wait(wt); // variable ms
wim 0:f3cd9dffaf5e 148
wim 0:f3cd9dffaf5e 149 i++;
wim 0:f3cd9dffaf5e 150 c++;
wim 0:f3cd9dffaf5e 151 s = 100.0f * sin((float)c * 3.1415f / 128.0f);
wim 0:f3cd9dffaf5e 152 b1 = myBtn1;
wim 6:3d66c065c42a 153 if (b1 && (b2 == 1)) {
wim 0:f3cd9dffaf5e 154 pc.putc('1');
wim 0:f3cd9dffaf5e 155 wt = 0.7f;
wim 0:f3cd9dffaf5e 156 }
wim 0:f3cd9dffaf5e 157 else {
wim 0:f3cd9dffaf5e 158 pc.putc('0');
wim 0:f3cd9dffaf5e 159 wt = 0.3f;
wim 0:f3cd9dffaf5e 160 }
wim 0:f3cd9dffaf5e 161 }
wim 0:f3cd9dffaf5e 162
wim 0:f3cd9dffaf5e 163 pc.printf("\nBye World!\n");
wim 0:f3cd9dffaf5e 164 }