MCUViewer: A GUI-Based Debugging Tool for Microcontrollers (MCUs)

What is MCUViewer?

To put it simply: MCUViewer is a real-time visualization debugging tool specifically designed for STM32 (and other Cortex-M chips). Originally named STMViewer, it was open-source until version 1.1.0, after which it became closed-source, but the source code can still be found here. It consists of two modules:

  • • Variable Viewer: It retrieves variable values directly from RAM without modifying the code or consuming CPU resources, displaying them in graphs with real-time updates.
  • • Trace Viewer: It utilizes the SWO hardware trace interface to capture high-frequency signals and function execution times.

How to connect? Simply plug in the ST-Link or JLink, ensuring SWDIO/SWCLK/SWO/GND are connected; it relies entirely on hardware support and is completely non-intrusive.

MCUViewer: A GUI-Based Debugging Tool for Microcontrollers (MCUs)

What pain points does it address?

In the embedded world, debugging often relies on printf, UART, or even logic analyzers. The problems are as follows:

  • • printf is too slow, consumes flash and CPU, and has poor real-time performance.
  • • UART has a small data volume, leading to frame loss in high-frequency signals, causing doubts about its reliability.
  • • STMStudio is not updated, is Windows-exclusive, and has a confusing C++ interface.
  • • CubeMonitor is feature-heavy and slow to get started, taking too long to plot a variable.

MCUViewer specifically targets these annoying issues: zero cost (hardware already available), real-time, cross-platform (Linux/Win), supports JLink, is C++ friendly, and can perform high-frequency tracing.

MCUViewer: A GUI-Based Debugging Tool for Microcontrollers (MCUs)

Core Functionality Showcase

Variable Viewer

  • • Automatically parses the symbol table from *.elf files
  • • Reads RAM in real-time and refreshes the graph
  • • Drag-and-drop, customizable axes, log export

Trace Viewer

  • • Parses SWO waveforms into waveform graphs
  • • Supports digital tags: function enter/exit time measurement
  • • Supports analog signals: high-frequency signals like ADC/sine waves

Code Example: Practical Hands-On

  1. 1. Variable Viewer (CubeIDE demonstration)
// Assume there is a global variable
volatile uint32_t sensor_val =0;

int main(void){
    HAL_Init();
    MX_USART2_UART_Init();
    while(1){
        sensor_val = read_adc();// sensor_val can be seen changing in real-time in MCUViewer
        HAL_Delay(10);
    }
}
  • • In MCUViewer: Options → Acquisition Settings → Import *.elf → Select sensor_val → Update → Drag into Plot.
  1. 1. Trace Viewer
// With SystemCoreClock=160MHz, SWO pin enabled
for(uint32_t i =0; i <1000; i++){
    ITM->PORT[0].u8 =0xAA;// Enter marker
    foo();// Business function
    ITM->PORT[0].u8 =0xBB;// Exit marker
    float x =sin(10.0f* i);
    ITM->PORT[1].u32 =*(uint32_t*)&x;// Analog signal trace
}
  • • Set the Trace prescaler to ensure the SWO frequency is below the maximum value of the probe. Press STOPPED to view the timing diagram.

Pros and Cons Overview

Pros Cons
⎯⎯⎯ Zero overhead: does not consume CPU or serial port ⎯⎯⎯ Variables must be global, and addresses must be fixed
⎯⎯⎯ Plug and play: supports STLink/JLink, cross-platform Win/Linux ⎯⎯⎯ 64-bit variables (double/uint64_t) are not currently supported
⎯⎯⎯ SWO hardware trace: high-frequency signals at your disposal ⎯⎯⎯ Some MCUs have complex SWO settings that require additional research
⎯⎯⎯ Open-source (1.1.0): can be compiled and customized ⎯⎯⎯ The latest version is closed-source, retaining only the old release source code

Conclusion

MCUViewer is like adding a “graphics card” to your STM32, visualizing CPU registers, global variables, and SWO traces. Once you use it, you won’t want to go back to printf serial bombardment or writing log files. The only drawbacks are the “address locking” of global variables and the occasional need to adjust SWO settings. Overall, it is reliable and quick to get started, especially recommended for engineers who frequently debug motor control, ADC signals, and real-time algorithms.

Project address: https://github.com/klonyyy/MCUViewer

Leave a Comment