Skip to main content
JayDev
Senior
February 11, 2021
Question

Is there a compile time conditional statement for debugging?

  • February 11, 2021
  • 2 replies
  • 802 views

Hello everyone!

I am trying to debug some code but there are some flags in flash that keep getting set when I exit debug and it enters run mode (or when I power up the sensor. Basically, anytime it gets a chance to run before I can get it in debug mode).

This had me wondering, is there a compile time debug command I can run that wouldn't run on the microcontroller unless I was in debug mode? Something like #DEBUG or something to that effect?

Tried searching the forums but it turns out, the word "debug" is very popular . . . heh. Any help you can give me would be appreciated. Thanks!

This topic has been closed for replies.

2 replies

Tesla DeLorean
Guru
February 11, 2021

You could add a breakpoint instruction (BKPT), or loop on a GPIO state.

Put external pull-downs on I2C pins so that the device operated differently when you want to debug it, or have it output diagnostic telemetry.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Ozone
Principal
February 12, 2021

Crossworks used to have an infinite loop in their debug startup code that waited for a debugger to connect.

Perhaps you can emulate that with your setup, possobly using TeslaDeLorean's suggested methods.