I was just curious if anyone knew what happens when you use a printf but don’t have the cable connected. Does it still run the statement? If so, is there any easy way to disable this so that I can basically comment out the code when in RUN mode but not in PROG mode?
The bios detects if the programming/debug cable is attached at startup and runs in debug mode enabling functions like printf to communicate with Dynamic ‘C’. When the cable is not attached the bios runs in run mode and functions like printf do nothing. This behaviour can be altered by redirecting printf to a serial port.
it would be better to determine programmatically if running in run mode or debug mode. The bios stores this state in a variable called OPMODE which can be tested with
debugMode = (OPMODE & 8) == 8;
or you can directly read the status of the SMODE pins by reading the SPCR register.
If you want to minimize your final non-debug code size, you can automatically turn the printf’s on and off based on the Dynamic C setting for RST 28 instructions (under Options / Project Options / Compiler / Advanced / “Include RST 28 instructions”) like this:
#if (DEBUG_RST == 1)
/* warning to not forget to turn of RST 28 for production code */ #warnt DEBUG RST 28 INSTRUCTIONS ENABLED! #define DEBUG_MSGS 1 #endif
And then encapsulate the printf’s like this:
#ifdef DEBUG_MSGS
printf( "Got to here
" ); #endif