Debugging without compiler optimizations ?

Support for creating custom user applications on the VESC.
maxkinz
Posts: 29
Joined: 30 Jun 2017, 14:41

Debugging without compiler optimizations ?

Postby maxkinz » 22 Sep 2017, 20:46

Hi,
I hope someone can help me with this. I am trying to write a custom application and wanted to enable debugging. So I got an STLINK V2 off ebay and configured it. I can debug VESC firmware with the standard makefile and all seemed well except it isn't. It is generally suggested to turn off compiler optimizations using the -O0 CFLAG which is -O2 per default in the BLDC firmware. I followed suggestgions from this helpful page: http://www.chibios.org/dokuwiki/doku.ph ... ebug_guide - well.. after turning off compiler optimization the firmware gets stuck in the mc_interface_init(&mcconf) method in setup (main.c). I briefly tried stepping into it but didnt figure it out. When activating CH_DBG_SYSTEM_STATE_CHECK I get an SV#4. (see guide linked above).
Now obviously I tried just leaving the optimizations on but somehow the routine in my App to initialize the DMP on an MPU6050 randomly cuts out and restarts in no predictable manner when doing so although I am not certain it has to do with optimizations I wanted to be sure. It does cut out in different parts of the code each time I start so it has to be interfering with something. I got the initialization routine from here https://github.com/jevermeister/MPU6050-ChibiOS .

Any Ideas why VESC firmware (clean git clone without my app shows same behaviour) would crash with the -O0 option ? why could the DMP initialization cut out randomly (without the DMP communication with the MPU6050 works but I want to use the Onboard DMP rather than a kalman eating up resources on the STM32...)

Thanks for your help !
Max

rew
Posts: 898
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Debugging without compiler optimizations ?

Postby rew » 23 Sep 2017, 20:15

Chibios is quite complicated. Features like -O2 and "link time optimization" have been available for so long that things are unlikely to be tested and that's when bitrot sets in. And things have started to depend on it.

The advice to disable optimizations is a bit oldfashioned. You must realize that sometimes a local variable is totally optimized out: The debugger won't be able to find it. You must realize that the code-flow is not always linear. Then you can still debug with optimization turned on.

On the other hand, one thing that cannot be debugged with a debugger is the VESC. Benjamin decided that you should not be able to stop the CPU while the motor is turning. That could fry the power electronics. So he installs a watchdog that will reset the CPU once you try to debug things. (on the other hand, you can still examine variable values. You just can't continue the program from where you left off. )

maxkinz
Posts: 29
Joined: 30 Jun 2017, 14:41

Re: Debugging without compiler optimizations ?

Postby maxkinz » 24 Sep 2017, 17:32

Hey rew,

Thanks for the help. I did figure it out in the meantime - was something easy as always but just didn't see it ... allocated insufficient size to my thread's work area.... and could not figure it out because I was unable to properly debug there - as even with optimizations left on enabling the debugging features in chconf would kill the beast before I even got to my app...:((( thats like 8 hours of my life down the drain :cry: Oh well now DMP is running.

Thanks,
Max


Return to “Custom Applications”

Who is online

Users browsing this forum: No registered users and 1 guest