Cube IDE / 32F4 breakpoints and "dynamic printf", etc - Page 1
Forum section: electronics / general

author: peter-h
author_rank: Super Contributor
timestamp: April 18, 2021, 09:20:25 am
content: Does anyone know how to use this featureI have googled around and it may be that some specific code has to be inserted into the project, i.e. this is not a special type of breakpoint which allows you to printf some variables to some window in Cube IDE. But I am not at all sure... everything I found online seems a mess.I have set up this dynamic printf and I see a load on debugger activity in the Console window, but no data comes out anywhere obvious.More basically, I am looking for a way to set up a breakpoint so that it doesn't stop the program but increments a counter. Obviously, the program will be interrupted for some time (does anyone know how long?).I have noticed there is an ignore count on a breakpoint and perhaps there is some way to monitor that, if it decrements. That must also pause the program, for however long the debugging system takes to process it. Do different debuggers affect this pause? I am using ST-LINK V2 ISOL.I have also noticed ST-LINK V3 has a VCP (on an extra connector) so if one of the UARTs is wired to these pins, you could run Teraterm on the PC to receive any debugs sent to that UART. But that requires target code, obviously, and my target has a USB port already with a VCP on it so we can send printfs to that.

author: DavidAlfa
author_rank: Super Contributor
timestamp: April 18, 2021, 11:45:51 am
content: You need to send the printf output somehow.To see it within the debugger you can use swv console, you need to write a _write function that sends the data.https://embeddedarea.com/stm32-debugging-with-printf-by-using-swv-or-openocd/It would be the same method to send it through a serial port:https://community.st.com/s/question/0D50X0000B8kTytSQE/printf-not-working-write-never-gets-called

author: peter-h
author_rank: Super Contributor
timestamp: April 18, 2021, 10:05:38 pm
content: OK; I had the impression this feature implemented a printf type debug output, to some window in the Cube IDE environment.I am now looking for a way to set up a breakpoint so that it doesn't stop the program but increments a counter. Obviously, the program will be interrupted for some time (does anyone know how long?).

author: bugnate
author_rank: Regular Contributor
timestamp: April 19, 2021, 03:26:25 am
content: Quote from: peter-h on April 18, 2021, 10:05:38 pmThis?https://sourceware.org/gdb/current/onlinedocs/gdb/Break-Commands.html

author: peter-h
author_rank: Super Contributor
timestamp: April 19, 2021, 06:21:50 am
content: That seems to be some sort of command line mode. I am using Cube IDE.However, thishttps://sourceware.org/gdb/current/onlinedocs/gdb/Dynamic-Printf.html#Dynamic-Printfsuggests that the dynamic printf does indeed do what I thought it did. And yes the output does end up in the "debugger console" window. So that's solved!This is a really brilliant feature!However, I have seen a comment that the execution time is quite long. I may do a setup where two pulses are generated, before and after, and measure it with a scope. Is this feature implemented wholly in the debugger, or does the data travel all the way to the PC via USB, and the printf is implemented on that? I think it must be, since the debugger is a small ARM and an FPGA, and it doesn't appear to be running on the target.

author: bugnate
author_rank: Regular Contributor
timestamp: April 19, 2021, 04:53:10 pm
content: Quote from: peter-h on April 19, 2021, 06:21:50 amIf by debugger you mean the ST-LINK V3, I would assume the latter. You'd be paying a lot more for something like the former.Note the "dprintf-style" parameter. I don't know what you already tried, but my reading is that this setting would determine if the printf (or whatever) is executed locally ("call") on the µC or handled on the PC. The former should be faster, but I'd expect both options to be relatively slow (milliseconds, at least) because either way GDB is coordinating things remotely from the PC which is just inherently slow, as you have noted.

author: peter-h
author_rank: Super Contributor
timestamp: April 19, 2021, 05:27:10 pm
content: I have found yet another way to send debugs: the SWO one-wire debug interface. This is one of the Jtag pins. The debugs come out in the SWV ITM data console in Cube IDE. This is supposed to be fairly fast, since it runs at 2mbps. You have to do something in main.c to connect printf() to this one-wire interface, and it does work.It is under Run / Debug Configurations / DebuggerI will have a go at timing this to see how much time it steals from the target.I can see the output (the window in Cube IDE) is not very fast; I reckon it could not display data at a few kbytes/sec. It also usually drops the first byte of the first message. But so long as it runs fast at the target end, that's ok.

author: peter-h
author_rank: Super Contributor
timestamp: April 19, 2021, 08:07:54 pm
content: Some updates on debug timing. I did a printf("1234567890") and timed the gap with a scope between two pulses generated before and after.SWO debug / SWV ITM data console: 6-20usDynamic Printf / debugger console: 120msA slight difference