π 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:
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:
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)
All breakpoints you can find in the (Ctrl+ 3 -> Breakpoint (Debug)) window:
That's all, now when program reaches this breakpoint executing stops:
And you can check your variables (both global and local) to find out bug:
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:
It will work, but, unfortunately,Β very bad:
This breakpoint type slows down code execution in approximately 100 times:
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:
This works much more better, that condition-breakpoint, and don't much slow-down your program:
- Comments