FlexSEA Wiki

A WEARABLE ROBOTICS TOOLKIT

User Tools

Site Tools


manage:debugger_tips

STM32 Debugging Tips and Tricks

Debugging STM32 projects can be tricky, especially with the current CLion system. Every time you waste hours getting the debugger working again please update this page with your conclusions.

CLion Run/Debug configuration

Example of a good configuration:

  • Using the Discovery config files works best for us
  • Download = Always will make sure you use the latest version of the sources
  • Reset: personal preference
  • Build before launch: best way to make sure you are debugging what you are looking at.

CLion Build/Execution/Deployment settings

  • Make sure you're pointing to the correct debugger executable (arm-none-eabi-gdb.exe)

USB connection and rights

  • The STLink does not always work well with hubs. We recommend connecting it directly to a USB 2.0 port.
  • Sometimes having ST-LINK Utility open will cause issues. Most of the time it's OK. We recommend terminating ST-LINK Utility during debugging session to avoid connection problems.

Optimizations

  • Make sure the compiler isn't optimizing too much such that you can't hit your breakpoints. Do this by adding a -g to your compiler flags in the CMakeLists.txt file.

Resets

Make sure to disable the boot notification:

//Notify Re that Mn just booted:
bootNotification();

Settings

Using ST-LINK Utility, double-check that your settings are OK, particularly the connection settings.

Option Bytes

Using ST-LINK Utility, double-check that your option bytes are OK. Once in a while they like to change…

Good:

Problematic:

Not shown on this screenshot is another problematic situation: having certain sectors protected.

Printing Floats

Printing floats is not enabled on most embedded systems by default, including STM32.

To enable printing floats, you must add “-u _printf_float” to the linker flags in cmake/chip/<chip_name>_definitions.cmake

For example:

set(MANAGE_LINK_FLAGS "-u _printf_float -specs=rdimon.specs")

In general we want to have this feature turned off for code size reasons, but it is essential for debugging complex code involving floats.

There also seems to be a bug in the provided cmake/obko/stm32_linker.cmake By default the _estack variable is set as follows:

_estack = ${STM32_RAM_ORIGIN} + ${STM32_RAM_SIZE} - 1

It should be set as follows, or else float prints will not work:

_estack = ${STM32_RAM_ORIGIN} + ${STM32_RAM_SIZE}
manage/debugger_tips.txt · Last modified: 2020/04/09 16:55 by tmayadagli