Showing posts with label STMStudio. Show all posts
Showing posts with label STMStudio. Show all posts

Thursday, September 14, 2023

STMViewer update: Trace Viewer module

 Hello, 


Today I want to give you a quick tour of the latest STMViewer update.


The update introduces a new module in the STMViewer which is called Trace Viewer. It serves as a visualizer for trace data read using an ST-Link programmer. SWO output is usually used to print messages from an embedded target to a console on the PC. However, I think there is an even better application for this excellent piece of hardware installed in Cortex M3/M4/M7/M33 cores. Since the trace output can be really fast, and the protocol is designed in a very bandwidth-efficient way (I might make a separate post about it someday), we can send a lot of data with precise timestamps that are automatically added by the trace peripheral. This sounds like a perfect way for profiling parts of a codebase, displaying interrupts and their durations, checking if a timer is configured properly, or displaying very fast "analog" signals, like ADC measurements. What's even better is that you only need one additional pin except SWDIO, SWCLK, and GND - the SWO pin. 


To send a byte with a so-called, "local timestamp" you simply write a register of the ITM peripheral (Instrumentation Trace Macrocell) like so:


ITM->PORT[<number>] .u8 = value; 


That's simple, isn't it? For the STMViewer to interpret the data as a high state you have to send 0xaa byte, for a low state you have to send 0xbb byte. You can also switch each channel to the "analog" domain and send full 8-,16- and 32-bit values that will be displayed. 


There is no need to configure the ITM peripheral as STMViewer does it using the debug interface on each trace start.


Below is a short demonstration GIF. In the beginning, you can see three digital channels of interrupts with different priorities (the highest priority is the top one, lowest is the bottom one). Preemption can be easily spotted by looking at the varying CH3 frequency. By using markers one can measure the time between two actions represented on the trace plots. Notice that the SysTick interrupt takes around 200ns (!) to complete and it's easily registered among much slower signals. 


The other part of the GIF shows a fast analog signal (each new sample is created every 10us) in combination with a high-priority interrupt that performs a memcopy of a large buffer.



This is just a demonstration, not a real application, however, I believe it will help to understand the use cases for this new STMViewer module. 


Please see the README.md file for a quick startup guide. 


Be sure to let me know if you have any feedback or feature ideas. Happy debugging! 

Sunday, June 11, 2023

STMViewer - visualize your embedded data in real-time


Hey,

This entry is going to be a software one or rather one about a software tool that I've been developing for a few months now - STMViewer:



Currently, I'm working at MAB Robotics, where I work on various stuff around MD80 brushless motor controllers, mostly software-related. The software stack incorporates a couple of control loops, with many tuning parameters and variables that should be observed in real-time to make sure the drive is operating correctly.

I’ve been using STMStudio for that purpose since it offers a high update rate data visualization without intervening in the software execution. All you need is the programmer that usually is connected to the target anyways during the development stage. STMStudio would be totally enough if it would be still supported, however, ST decided to abandon that project and currently, it is declared NRND. It has some annoying bugs; for example, it doesn’t support C++ mangled names directly using the list variables option (typing the names manually works, but sometimes it stops updating the addresses, no idea why). Moreover, it is only available for Windows. The CubeMonitor which should be the STMStudio’s successor turned out to be a disaster even though it seemed to have an interesting idea behind it, and it looks like its abandoned as well. Having no other options I decided to make my own real-time data visualizer, taking inspiration from the great STMStudio project.

STMViewer is almost a copy of the most important STMStudio functionalities that allow for basic debugging using time graphs, bar graphs, and tables. There are some small differences and changes though.

Similarly to STMStudio, it has two main sections – the workspace section on the left and the plotting area on the right. The workflow works as follows:

    1. First you have to select your project’s elf file in the Options -> Acquisition settings

    2. Then you have to add all variables of interest and click the update variable addresses button to try to find the addresses of these variables in the elf file you’ve provided. If this step didn't work, make sure you've got GDB installed and added to the PATH. 

    3. After that you simply drag and drop the variables onto the plotting area and the data acquisition can be started.


You can add multiple plots and changes their names and types. The table view supports writing new data using the “write value” column. This can be especially useful to issue some commands to the target you’re debugging. Read values can be displayed in hex, bin, or decimal formats.

Some more advanced functionalities are still missing:

    - no math operations and statistics

    - no dump to CSV file

    - no “list variables from elf file” option

    - no X-Y plots available

I’m going to work on these soon, however, since they aren’t essential to basic debugging, I'm releasing the first version of the STMViewer right now

If you've got any questions, or suggestions be sure to let me know.