This is Follow up video of the previous Blog, In this How to use Trace features in STM32 MCU via SWV are explained using STLINKv2 Programmer and Debugger in STM32CubeIDE. Table of Contents Various Trace Features by SWV, Live Expressions and Using them SWV in STM32CubeIDE provide us with following Trace Features to be used in STM32MCU. Figure 14 SWV Features can only be used in Debug mode, so after creating your project as mentioned in below section, click on Debug Icon on the Menu bar of CubeIDE. Figure 15 If you are debugging your code for first time, debug configuration window will pop up, in which u must select your Debugger and made some Configurations. Main things to select in Debug Configuration window are. Debug Probe -> Select GDB server or OpenOCD. Enable the Serial wire Viewer(SWV) by checking on enable button and select the Core clock of SWV exactly as the Clock frequency that u have configured for your MCU system Clock, SWO clock as 2000 khz Under Misc. Section select the Enable Live Expressions Figure 16 Out of all SWV features I will be showing how to use marked SWV Trace Features from above pic of SWV Show View. SWV ITM Data Console So first Starting the SWV ITM Data Console which is used for printing printf() commands for printing Strings on the ITM terminal screen without using UART. For that We have to include the following code in your main.c file and include Header file Stdio.h in your main.c for printing the printf() commands on your ITM console. And now in your while loop of main.c file just write printf() commands like these. In the following Pic I have also blinked the led at PC13 pin. And then Debug the code by clicking on Debug Icon in Menu bar of CubeIDE. And after entering Debug Mode, click on Window -> Show View -> SWV -> SWV ITM Data console. Now as You open the SWV ITM Data Console, or any SWV window, u will find Following 2 icons in every view.  The first one is the SWV configuration Button, which is very important and configures our SWV. And another one is Start button for Starting the Trace. At first, we must do the SWV configurations, so click on first button. SWV Configuration window will pop out. Now For Using the ITM Data console, just click on the below marked check box for printing Printf() commands on the ITM port 0.and then click on ok.  Now start the trace by clicking on Red Button alongside the Configuration button. And now Resume the Code in Debug Mode only by clicking on the Resume button in menu bar of Cube IDE. Now as You click on Resume Button, U can see your printf() output strings on the ITM Data console. So that is how one can Print the strings using SWV + SWD in STM32 MCU via STLINKv2 without using UART for debugging the firmware. Click on Suspend button to stop the SWV. SWV Data Trace and SWV Data Trace Timeline Graph These two windows can be used to trace up to any Variables/Address locations of our code. Showing their value and other necessary details. For showing their use case, in our main.c I will be creating two variables by a&b. As shown in below pic. Now debug the code and open the SWV Data Trace and SWV Data Trace Timeline Graph windows. From those windows open the SWV configuration window as told in previous Section. And do the following changes, Enable the Comparator 0 and 1: one can data trace only up to 4 variables or address locations as you can see there are 4 Data Trace Comparators in our SWV Configuration window. In Var/Addr sections of Comparator 0&1 write the variables or address locations to be traced. And select ACCESS and GENERATE according to your variable being traced or address location being Traced. Below is the pic, showing my configurations: Click on okay and then start the Trace and Resume the Code in Debug Mode only as specified in Previous Section. Now you will see in SWV Data Trace view, all trace data of configured variables/address locations is being shown under History Section, showing various parameters like Value, Access, Program Counter value, Clock Cycles and Time for the Traced Event. As shown in Figure. Out of Configured Comparator, one can select for which comparator we want to see the history from the Watch section of Data trace, as shown in above Two pics. Data trace data can be of great value for monitoring Time critical variables and address locations and observing their behavior during Program execution. In SWV Data Trace Timeline Graph, one can see the plotting of value of the configured Comparators in the form of graph and Analyzing Variables that are dependent on each other or Time critical. The Graph is plotted as shown in Pic. There are various options available on TimeLine Graph window, you can experiment those features by your won. SWV Statistical profiling Is used to see in which functions of your code, CPU is spending too much of time when program is running in MCU. To use SWV Statistical Profiling we do not have to write any code, just do as mentioned in Various Trace Features by SWV and Using them section above and enable the PC Sampling in SWV configuration window. Then start the trace and Resume the Code in Debug code as told in above sections. Now For Statistical Profiling wait for x number of secs after resuming your code according to your choice, in that time no data will be shown on Screen. After x amount, suspend the Program Execution and You will see something like this. As you can see, in above pic one can analyse in which functions our code is spending most of the and how much time. Which can be of great help in Very Complex codes which includes multiple I/O
Table of Contents Overview Okay so hello guys and hope u are doing great; in the last 2 Blogs we get to know about Debug Trace Features in Embedded Systems and about ARM CoreSight Architecture for Debug and Trace in ARM based SoC/MCU. Now, in this Blog we will implement the theoretical knowledge of previous blogs to action and do them practically! We will do so by exploring the Trace Features in STM32MCU practically (STM32F103 Blue pill) using STLINKv2-B ( Official one white one) in STM32CubeIDE.  This Topic has been divided into 2 Blogs. In this Blog Hardware connections between STLINKv2-STM32MCU and Code Generation is explained. The Video For that is also Uploaded on Gettobyte YouTube channel here. In next Blog How to use Trace Features using SWV is explained. The Video for that too is Uploaded on Gettobyte YouTube Channel here. Intro on STLINKv2 Programmers and Debuggers Now STLINKv2 which you can see in the above image is different from USB based STLINKv2 Programmer and debugger( Chinese clone one). It is different in terms of more features and JTAG support for Debugging the Firmware’s. Original STLINKv2 can be used for Programming and Debugging Both STM8 and STM32 MCU. For STM8 it uses SWIM Protocol and for STM32 it has SWD, JTAG Communication Protocol and SWO pin for trace features. In USB based STLINKv2 Programmer Chinese cloned one also both STM8 and STM32 MCU can be programmed and debugged. For STM8 it also uses SWI Protocol but for STM32 MCU it has only SWD Protocol and pins available. For using the trace features, In USB based Chinese cloned one STLINKv2 (which is relatively cheaper than above STLINKv2) we must solder the 5V pin of Programmer by one of the pins of the onboard pin of the MCU used in Programmer. And it is a kind of long and Cumbersome Process. But in Official STLINKv2 which is shown in above pic, we do not have to solder any of the pins for using Trace Features, The Programmer has Pinout and dedicated pins for using Trace feature using (SWD + SWO pins) and it has JTAG Dedicated pins too for Doing Debugging . Now as given u some comparisons between Official and Unofficial STLINKv2 Programmer and Debugger let us dive into some Practical Part. In the rest of the doc, STLINKv2 programmer and Debugger will signify the Official white in one derivative which is shown in above pic. Hardware Connections for STLINKv2 and MCU The STLINKv2 Programmer comes in with following things as u open its Box. Main STLINKv2 Programmer and Debugger 20 Pin JTAG connector USB 2.0 A to USB 2.0 Mini B 2 x Connecting Cable for STM8 SWIM Now coming to the pain Connections for connecting STM32 MCU with STLINKv2.Programmer has the following pins for connecting it to STM32 MCU(Blue Circle). These Pins have Pinout like these: Right side from the Embarked Area (Orange Color), is pin 1 of the Programmer and then the pinout goes as shown in above pic. Now the Essential Pins out of these 20 pins of the STLINKv2 programmer to Program and Debug STM32 MCU using ARM Proprietary SWD Protocol are only 5 pins. SWIO/TMS(Pin 7) à SWD PIN SWCLK/TCK(Pin 9) à SWD PIN TDO/SWO(Pin 13) à SWO PIN STM32 RESET(Pin 15) à RESET PIN VCC(Pin1&2) à POWER PIN GND(Below Horizontal line’s any pin can be used as GND except 2) à POWER PIN SWD Pins of STM32 MCU will be connected to SWD PIN if we want to only use Debugging features alongside Programming the Microcontroller. Like as shown in PIC.  Now for Using the Trace Features we must connect one additional Pin from the Programmer to OUR Microcontroller and that is SWO Pin (13th pin) of Programmer to the Respective Trace SWO Pin Of our STM32 Microcontroller. In STM32F103 SWO PIN is PB3 as shown in this schematic. So, for Using Trace Features Connections will be like this. To be noted down: Any pin from the below horizontal line except the VCC pin of that line can be taken as GND pin when using SWD/SWD+SWO pins and can be connected to GND pin of our STM32 MCU. Sometimes or in some Programmers we have to short all the VCC pins by Jumper wire for Proper connections or encase device isn’t able to power up MCU or Program it. In some cases, VCC pins 1&2 can be wrongly mapped in Some Programmer, and they can be at left hand side of the programmer that is at pins 19 and 20. So in case MCU does not Power up by above connections, then do not panic just change the VCC Pins and it might work out. ( This is in my case, so below pitcher is according to that) Now so after successful Connections between STLINKv2 and STM32 MCU, Connect the USB cable between STLINKv2 and Laptop and LED light on the programmer will lighten up in RED color. Figure 5 (These are the Final Connections For SWD+SWO) Software Part used Now I will be Showing STM32CubeProgrammer and STM32Cube IDE In this blog in software part. First with STM32CubeProgarmmer: As u connect your STLINKv2 Programmer to your computer, IN STM32CubeProgrammer u will see the Serial Number of Programmer if all goes well. As shown in Pic. Figure 6 Now as u click on Connect Button by selecting STLINK, u will see all the details of Your respective MCU details and showing its memory Content. (In doing so Your programmer will start blinking in red, green color and Screen of STM32CubeProgrammer might take 1-2 secs of time for showing Memory contents and MCU details.) Figure 7 This is just Demonstration of Successful connections of STLINKv2 and MCU for SWO+SWO pins and established Communication between Programmer and Laptop via STM32Cube Programmer. As if now, we have not used the trace features, for using that we must create a project and Upload in MCU by things mentioned in below section. For
- 1
- 2