πŸ›‘ Breakpoint with condition in STM32CubeIDE

What are breakpoint are use for?

Breakpoints are used to stop program execution at a selected line, which helps to debug a particular piece of code:

Image

In some cases you need to stop the program, when variable reaches specific value:

  • Counter value
  • ADC value
  • Time Value
  • State value

This canΒ help trace all program stages and find out where code is wrong.

How to set ordinary breakpoint in STM32CubeIDE?

Just do double left-click right to the line's number of press Ctrl + Shift + B, the small blue dot should appear:

Image

Note, that in some cases breakpoints will not works, to fix this turn off any optimization.Β Go to: Project -> Properties -> C/C++ Build -> Settings -> MCU GCC CompilerΒ -> Optimization -> Optimization level: None (-O0)

Image

All breakpoints you can find in the (Ctrl+ 3 -> Breakpoint (Debug)) window:

Image

That's all, now when program reaches this breakpoint executing stops:

Image

And you can check your variables (both global and local) to find out bug:

Image

How to set condition-breakpoint in STM32CubeIDE?

Just do Ctrl +Β double left-click rightΒ to the line's number to open Properties for C/C++ Line Breakpoint and write in Condition field C-style condition with using your variable:

Image

It will work, but, unfortunately,Β very bad:

Image

This breakpoint type slows down code execution in approximately 100 times:

Image

Another good way to set condition-breakpoint

You can just write a few string of code with condition, that you need and add ordinary breakpoint:

Image

This works much more better, that condition-breakpoint, and don't much slow-down your program:

Image

899
No comments yet. Be the first to add a comment!
Cookies?