cancel
Showing results for 
Search instead for 
Did you mean: 

SWO capture in st-link gdb server and STM32CubeProgrammer

u1kano
Associate III

I am developing software on Windows using STM32CubeIDE and STM32CubeProgrammer.
I have a question about how to run Debug using the st-link gdb server in a CLI environment.

I want to capture the results of Google Test running on the firmware via SWO output and retrieve them using STM32CubeProgrammer.
However, when I run Debug, the process stops before completion, and I am unable to determine the cause or solution.

[gdb server command line]
> C:\ST\STM32CubeIDE_1.12.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.500.202301161003\tools\bin\ST-LINK_gdbserver.exe -p 61234 -l 1 -d -z 61235 -s -cp C:\ST\STM32CubeIDE_1.12.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.600.202301161003\tools\bin -m 0 -g --frequency 24000 -t

 

 attached file: gdb server console log.txt

 

Cube Programmer SWO capture

Cube Programmer SWO capture.jpg

 

st-link gdb server in STM32CubeIDE (GUI) works correctly.

 

I am investigating whether there are any issues with the startup parameters of the gdb server or CubeProgrammer.
If you have any ideas on how to resolve this, I would greatly appreciate your help. Thank you in advance.

 

My environmental information is as follows:
CubeIDE(Windows11) - ST-Link/v2 - device
STM32CubeIDE:Version: 1.12.1 Build: 16088_20230420_1057 (UTC)
STM32CubeProgrammer: v2.16.0
ST-LINK FW: V2J41S7
Device: STM32H7Ax/7Bx

3 REPLIES 3
Aziz BRIGUI
ST Employee

Hello @u1kano,

In CubeIDE GUI, you can check the command line that's being used by going to "Run>Debug Configuration>Debugger>GDB Server Command Line Options>Show Command line".

Let me know if you find this helpful.

Aziz


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
BarryWhit
Senior III

partial duplicate of 

https://community.st.com/t5/stm32cubeide-mcus/about-capturing-with-serialwireviewer-in-a-openocd/td-p/707212

 

- when blurring parts of a screenshot, use a contrasting color to make it clear. combined with the heavy tiles windows it makes it very hard to read.

- why do you have two gdb sessions and 3 cubeProgrammer sessions going all at once?

- what is the order of operations the screenshot is meant to explicate?

- what exactly do you mean by "run Debug"?

- what exactly do you mean by the "process stops without completion"? do you mean gtest output piped over SWO seeming to hang?

- what is the cause of the "vRun" errors shown in your screenshot?

 

Once you've answered those questions....

 

- are you able to differentiate between the test suite stopping half way and the test suite running to completion but the SWO output borking half way? can you toggle a LED at the end of the test suite and see?

- When the test suite seems to hang, did you break with gdb and examine what the CPU is doing?

- If instead of running the test suite you simply print a running counter, does the output still hang?

- Post the code you use to forward the gtest output  over SWO. Is this code safe for when the output rate is faster than the SWO can support? is there a busy loop there which can lead to a deadlock? Did you copy-paste some random snippet from the internet? some of those are very naive and can fail in distasteful ways.

- What happens if you increase the SWV frequency? where did the 280 in your screenshot come from and what does it stand for? 280KHz? SWV can usually be run at least as high as 2Mhz and even 4Mhz.  Simply raising the SWV freq is not a robust solution if overrun is really the problem, but if raising the rate makes the issue go away it would at least be confirmation of the root cause.

 

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.

@BarryWhit 

I apologize for the delayed response despite your earlier reply. Thank you also for the advice you provided.

I will respond regarding some of the points I have confirmed, and I would appreciate it if you could continue providing advice.


- why do you have two gdb sessions and 3 cubeProgrammer sessions going all at once?

The screenshots appear strange because I stitched multiple screenshots together. In reality, there is only one GDB session and one CubeProgrammer session running.

 

- what is the order of operations the screenshot is meant to explicate?

I just wanted to explain that the Google Test results on the right side of the screenshot were cut off.

 

- what exactly do you mean by "run Debug"?

I would like to run Google Test within the firmware by executing the following steps.

- Download the compiled program (ELF file) to the debugger.
- Run the program using a gdb session.

 


- what exactly do you mean by the "process stops without completion"? do you mean gtest output piped over SWO seeming to hang?

Yes, I mean gtest output piped over SWO to hang.

 

- what is the cause of the "vRun" errors shown in your screenshot?

 

The cause of the issue has not been identified yet.

 

I would like to respond based on the points I have confirmed regarding some of the advice you provided.

- post the code you use to forward the gtest output  over SWO. Is this code safe for when the output rate is faster than the SWO can support? is there a busy loop there which can lead to a deadlock? Did you copy-paste some random snippet from the internet? some of those are very naive and can fail in distasteful ways.

I have directly implemented ITM_SendChar in the write system call.
I think it is equivalent to the official STM document.

__attribute__((weak)) int _write(int file, char* ptr, int len)
{
    (void)file;
#ifdef DEBUG
    int DataIdx;
    for (DataIdx = 0; DataIdx < len; DataIdx++) {
        ITM_SendChar(*ptr++);
    }
#endif
    return len;
}