Blog

Dynamic Printf in Atollic TrueSTUDIO v.6.0.0

Dynamic Printf in Atollic TrueSTUDIO v.6.0.0

Atollic has recently released TrueStudio v6.0.0, their most recent major update to the TrueSTUDIO IDE. The update comes with new features such as support for CMSIS-pack, updates to the build analyzer, and an interesting debugging tool that Atollic calls “dynamic printf” which we’ll look at today.

A dynamic printf is a hybrid between a traditional breakpoint and a printf() function. Essentially, it’s a printf() that you can insert into the code like a breakpoint, even during runtime. Normally when debugging with printf(), the programmer has to insert a printf() line into the source code, recompile, run it, and wait for the program to hit the line (or to skip over it in some cases). Then when testing is good and finished, the programmer hopefully remembers to delete the printf() line later.

Let’s see an example on a STM32 NUCLEO board using a simple blinky LED project where we want an LED to blink every second:

Atollic TrueSTUDIO STM32 Nucleo LED main program dynamic printf

A blinky LED program

While the code is running in Debug mode, we can right click the left side of a line just like we would when adding a breakpoint and select “Add Dynamic Printf.”

Atollic TrueSTUDIO dynamic printf breakpoint debugger

You can add a dynamic printf in or out of Debug mode.

 

You’ll get a popup where you can specify the output on the console (and a few other options):

Atollic TrueSTUDIO debugger dynamic printf properties menu

Note that you can’t make a function call within a dynamic printf but you can reference variables

You should see messages print out in the Console window when the code hits the dynamic printf:

Atollic TrueSTUDIO debug dynamic printf console output

Blinking every second just like it should be

“Now, wait a minute,” you might say. “Isn’t this example a little forced? You had to call the HAL_GetTick() function in the source code to get the tick count so that you could put it in your dynamic printf. That means you had to modify your source code and recompile!” Okay, you got me. While it isn’t the best example ever, it is simple enough to explain how a dynamic printf works. And it’s not too difficult to imagine a scenario where a dynamic printf could come in handy and where no extra lines are needed in the source code at all such as “Am I ever getting to this line of code?” Or, “What values are being passed into this function during run time?”

Learn More:

DMC's Custom Software and Hardware Services

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above: