klonyyy / MCUViewer

Real-time embedded variable & trace viewer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

STMViewer and STM32H7

folny opened this issue · comments

Version/Branch:

5.0

Operating system:

windows 11

Debug probe:

ST-Link v2

Details:

Hello

Has anyone tried STMViewer with an STM32H7 processor?. In my case, Trace Viewer doesn't want to work. I have this particular board https://www.aliexpress.us/item/3256806446021431.html?spm=a2g0o.order_list.order_list_main.20.47861c247DAPaT&gatewayAdapt=glo2usa4itemAdapt

Screenshots/Video:

No response

Hello, please provide more details, for example a screenshot, and the latest log file (located C:\Users<user>\AppData\Roaming\STMViewer\logs).

My test code and cpu clock
CPU Clock

while (1) {
ITM->PORT[0].u8 = 0xaa;
status ^= 1;
HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);
ITM->PORT[0].u8 = 0xbb;
HAL_Delay(1);
}

Var Viewer OK
Var Viewer

Trace Viewer not work
Trace Viewer

Logs

[2024-06-20 21:16:40.577] [logger] [info] Starting STMViewer!
[2024-06-20 21:16:40.577] [logger] [info] Version: 0.5.0
[2024-06-20 21:16:40.577] [logger] [info] Commit hash f65dd13
[2024-06-20 21:16:40.749] [logger] [info] GDB version: 121
[2024-06-20 21:16:41.061] [logger] [info] Unable to match requested speed 24000 kHz, using 4000 kHz
[2024-06-20 21:16:41.063] [logger] [info] STM32H74x_H75x: 128 KiB SRAM, 2048 KiB flash in at least 128 KiB pages.
[2024-06-20 21:16:41.063] [logger] [info] STLink serial number 066BFF323532534157163257
[2024-06-20 21:16:45.239] [logger] [info] Adding variable: status
[2024-06-20 21:16:45.239] [logger] [info] Adding plot: new plot0
[2024-06-20 21:16:45.239] [logger] [info] Adding series: status
[2024-06-20 21:16:45.239] [logger] [info] Adding trace plot: CH0
[2024-06-20 21:16:45.239] [logger] [info] Adding trace plot: CH1
[2024-06-20 21:16:45.239] [logger] [info] Adding trace plot: CH2
[2024-06-20 21:16:45.239] [logger] [info] Adding trace plot: CH3
[2024-06-20 21:16:45.239] [logger] [info] Adding trace plot: CH4
[2024-06-20 21:16:45.239] [logger] [info] Adding trace plot: CH5
[2024-06-20 21:16:45.240] [logger] [info] Adding trace plot: CH6
[2024-06-20 21:16:45.240] [logger] [info] Adding trace plot: CH7
[2024-06-20 21:16:45.240] [logger] [info] Adding trace plot: CH8
[2024-06-20 21:16:45.240] [logger] [info] Adding trace plot: CH9
[2024-06-20 21:16:45.240] [logger] [info] Project config path: D:/Projekty/STM32H7_Metal_Detector/Firmware/STM32H7_NRF24_LCD_Data_Test/Data.cfg
[2024-06-20 21:16:45.278] [logger] [info] Unable to match requested speed 24000 kHz, using 4000 kHz
[2024-06-20 21:16:45.280] [logger] [info] STM32H74x_H75x: 128 KiB SRAM, 2048 KiB flash in at least 128 KiB pages.
[2024-06-20 21:16:45.280] [logger] [info] STLink serial number 066BFF323532534157163257
[2024-06-20 21:16:47.719] [logger] [info] Start trace clicked!
[2024-06-20 21:16:47.749] [logger] [info] Unable to match requested speed 24000 kHz, using 4000 kHz
[2024-06-20 21:16:47.750] [logger] [info] STM32H74x_H75x: 128 KiB SRAM, 2048 KiB flash in at least 128 KiB pages.
[2024-06-20 21:16:47.752] [logger] [info] Trace frequency 2000000
[2024-06-20 21:16:47.752] [logger] [info] Trace prescaler 31
[2024-06-20 21:16:47.752] [logger] [info] Trace channels mask 1
[2024-06-20 21:16:47.754] [logger] [info] Starting reader thread!
[2024-06-20 21:16:50.333] [logger] [error] No trace registered for 2s!
[2024-06-20 21:16:50.333] [logger] [error] Trace invalid, stopping!
[2024-06-20 21:16:50.334] [logger] [info] Trace stopped.
[2024-06-20 21:16:50.334] [logger] [info] Closing trace thread false
[2024-06-20 21:17:14.533] [logger] [info] Unable to match requested speed 24000 kHz, using 4000 kHz
[2024-06-20 21:17:14.533] [logger] [info] STM32H74x_H75x: 128 KiB SRAM, 2048 KiB flash in at least 128 KiB pages.
[2024-06-20 21:17:14.533] [logger] [info] STM32H74x_H75x: 128 KiB SRAM, 2048 KiB flash in at least 128 KiB pages.
[2024-06-20 21:17:20.718] [logger] [info] Unable to match requested speed 24000 kHz, using 4000 kHz
[2024-06-20 21:17:20.719] [logger] [info] STM32H74x_H75x: 128 KiB SRAM, 2048 KiB flash in at least 128 KiB pages.
[2024-06-20 21:17:20.721] [logger] [info] STM32H74x_H75x: 128 KiB SRAM, 2048 KiB flash in at least 128 KiB pages.
[2024-06-20 21:17:27.912] [logger] [info] Start trace clicked!
[2024-06-20 21:17:27.946] [logger] [info] Unable to match requested speed 24000 kHz, using 4000 kHz
[2024-06-20 21:17:27.948] [logger] [info] STM32H74x_H75x: 128 KiB SRAM, 2048 KiB flash in at least 128 KiB pages.
[2024-06-20 21:17:27.950] [logger] [info] Trace frequency 2000000
[2024-06-20 21:17:27.950] [logger] [info] Trace prescaler 31
[2024-06-20 21:17:27.950] [logger] [info] Trace channels mask 1
[2024-06-20 21:17:27.952] [logger] [info] Starting reader thread!
[2024-06-20 21:17:30.573] [logger] [error] No trace registered for 2s!
[2024-06-20 21:17:30.573] [logger] [error] Trace invalid, stopping!
[2024-06-20 21:17:30.574] [logger] [info] Trace stop

Have you enabled SWD + trace (SWO) setting in cube IDE?
image

Yes, this is fine, without this setting Var Viewer probably wouldn't work either.
Trace EN

Have you checked if the SWO outputs any data to the ST-Link on the SWO pin?

Var Viewer works only with SWCLK, SWDIO and GND. SWO is needed additionally for Trace Viewer.

I have not tried to check that, I will try to connect the oscilloscope to the SWO pin today and let you know if there is any data on the pin.

I found that I have no data on the SWO pin. Please check my .ioc file if everything is set correctly.
STM32H743_STMViewer_Test.zip

The *.ioc seems to be correct. Have you checked the SWO signal directly at the MCU pin? Are you sure there is nothing connected to it that could interfere with the signal?

Today I tested the second STM32H7 this time I have data on pin SWO but STMViewer does not show any data.

Test
1719257952053

Ok this is an improvement. Could you try different prescaler values? If you're not using an original stlink there may be some problems with maximum SWO pin bandwidth. Could you try an official stlink?

Have you tried modifying the prescaler?

Yes, I tried different values ​​but nothing is displayed. With cpu STM32f446 it works beautifully, only with H7 I have a problem.

Could you try connecting the oscilloscope so that you see proper frames? It seems you only get error frames, so maybe the problem is in the electrical connection somehow? The scope last screen you've sent me seems to have very bad edges and overall signal quality.

Today I tested the same code on the STM32F446 NUCLEO and the data on the SWO pin is fine and looks like this.

1719941755476

The next test is on the H7 and there is a much higher frequency on the SWO pin, even if I change the prescaler in STMViewer to a higher value, no changes are reflected.

1719943058761

So today I searched on the internet what could be the problem with the SWO and I found this configuration that helped me and the STM32H7 SWO is now working properly :-)

https://gist.github.com/tstellanova/107cb66cd0599fa20cca1fce9556468c

Thank you for the research! Is it possible for you to narrow down the whole SWO setup to a particular register write(s) that make it work with STMViewer?

Yes, STMViewer works fine with this setup.

So I meant like, are all these register writes indispensable? Or you could test which one is really necessary?

I haven't tried to change anything yet, I will try to make some changes and add more information.

Closing due to inactivity. I currently don't have any H7 mcu on my hand - please reopen to let us know which register write was missing (or I will when I have a H7 to work on). I'll paste the working config here so that we do not lose it:

void SWD_Init(void)
{
  *(__IO uint32_t*)(0x5C001004) |= 0x00700000; // DBGMCU_CR D3DBGCKEN D1DBGCKEN TRACECLKEN
 
  //UNLOCK FUNNEL
  *(__IO uint32_t*)(0x5C004FB0) = 0xC5ACCE55; // SWTF_LAR
  *(__IO uint32_t*)(0x5C003FB0) = 0xC5ACCE55; // SWO_LAR
 
  //SWO current output divisor register
  //This divisor value (0x000000C7) corresponds to 400Mhz
  //To change it, you can use the following rule
  // value = (CPU Freq/sw speed )-1
   *(__IO uint32_t*)(0x5C003010) = ((SystemCoreClock / 2000000) - 1); // SWO_CODR
 
  //SWO selected pin protocol register
   *(__IO uint32_t*)(0x5C0030F0) = 0x00000002; // SWO_SPPR
 
  //Enable ITM input of SWO trace funnel
   *(__IO uint32_t*)(0x5C004000) |= 0x00000001; // SWFT_CTRL
 
  //RCC_AHB4ENR enable GPIOB clock
   *(__IO uint32_t*)(0x580244E0) |= 0x00000002;
 
  // Configure GPIOB pin 3 as AF
   *(__IO uint32_t*)(0x58020400) = (*(__IO uint32_t*)(0x58020400) & 0xffffff3f) | 0x00000080;
 
  // Configure GPIOB pin 3 Speed
   *(__IO uint32_t*)(0x58020408) |= 0x00000080;
 
  // Force AF0 for GPIOB pin 3
   *(__IO uint32_t*)(0x58020420) &= 0xFFFF0FFF;
}