Reply
Posts: 54
Registered: ‎09-06-2017

Debug print helper

I created a debug print helper for adding debug output to projects, attached. To use:

 

  1. Add to your project
  2. In project configuration > C/C++ General > Paths and Symbols
    1. Click Manage Configurations
      1. Clone the default active configuration
      2. Rename the default active configuration to add (debug)
      3. Rename the new configuration to add (production)
      4. Click OK
        Screen Shot 2017-09-12 at 16.36.46.png
    2. Select Symbols in the tabs and GNU C at the side
    3. Add:
      1. Symbol = DEBUG
      2. Value = 3
    4. Click OK
      Screen Shot 2017-09-12 at 16.47.17.png
  3. Use the new debug statements in your code
  4. During debug use the debug configuration
  5. To disable debug output use the production configuration (Right click project > Build configurations > Set Active > (production))
Posts: 54
Registered: ‎09-06-2017

Re: Debug print helper

Usage:

 

#include "debug.h"

...

LogError("Hello! %d", 1);
LogWarn("World! %d", 2);
LogInfo("Goodbye! %d", 3);

Screen Shot 2017-09-12 at 16.50.57.png

Posts: 518
Registered: ‎12-05-2016

Re: Debug print helper

Hi @nickb,

 

Thank you for sharing your solution!  

 

My only caution is that "DEBUG" is a very generic and widely used symbol, so if the intent is only to control the log messages a more specific symbol might be used instead. (see platform\base\hal\micro\generic\compiler\platform-common.h for example).

 

Thank you,

jpitt

Posts: 54
Registered: ‎09-06-2017

Re: Debug print helper

Thanks for your suggestion @jpitt, a different name would probably be more appropriate. This was just intended to guide others though, and should be fairly simple to understand and modify for different circumstances. The process to add the global symbol and the macros themselves are hopefully helpful to others though.

 

Side note: I can't see a way to edit posts, so I couldn't make your suggested changes in my original posts.

Posts: 16
Registered: ‎04-20-2017

Re: Debug print helper

Thanks for posting this.  In my project DEBUG_H was already defined so the header file wasn't included.  Do you know where stderr is should be defined?  It's not in my project.  

Posts: 54
Registered: ‎09-06-2017

Re: Debug print helper

Sorry about that, I should have included stdio.h in the file. Improved version attached with the macro changed from DEBUG to LOG_LEVEL. I also added some options to control if it outputs colours (some terminals don't support it like the built in console in Simplicity Studio) and if it outputs the file, function and line number.

 

If you don't already have printf set up to print to your chosen output you'll need to set it up:

http://community.silabs.com/t5/Simplicity-Studio-and-Software/SWO-debug-printf-in-IDE-for-the-EFR32B...

 

Note that if LOG_LEVEL is not defined, this will not add the print statements to your code, so will not affect performance in production.

Posts: 54
Registered: ‎09-06-2017

Re: Debug print helper

A better version again, sorry, can't edit posts.

Posts: 16
Registered: ‎04-20-2017

Re: Debug print helper

What is the trick for getting output into the console window?  No errors (I see you already found the cut and paste error for the no location option) but nothing shows up in the window.  I tried just putting some fprintf and fflush for both stderr and stdout statements in my code but nothing.   

 

thanks

Posts: 54
Registered: ‎09-06-2017

Re: Debug print helper

If it isn't working with your STK/board then it's because of a bug in Simplicity Studio which I have reported (it doesn't work for me). If you put a breakpoint in retargetswo.c > RETARGET_WriteChar and keep resuming you will see the characters appear in the console one by one. Your other options are to use commander in terminal (macOS):

/Applications/Simplicity\ Studio.app/Contents/Eclipse/developer/adapter_packs/commander/Commander.app/Contents/MacOS/commander swo read -s <serial>

Get the serial from Launcher in Simplicity studio "J-Link Silicon Labs (<serial>)"

 

You cannot debug in Simplicity Studio and run commander at the same time.

 

Or, configure it to use UART with retargetserial.c. For me this conflicts with the joystick input so I'm using SWO for now.

Posts: 16
Registered: ‎04-20-2017

Re: Debug print helper

Yes I am using the STK board. I just assumed stdout (stderr is set equal to stdout in stdio.h) would be piped to the Jlink debugger but that may not be the case.  I'll look into it more next week if I get time.  This would be a very helpful tool.

 

Thanks

Posts: 54
Registered: ‎09-06-2017

Re: Debug print helper

Not by default. You have to use retargetswo for that, but as I say it doesn't work right now due to a bug. Best to use a serial terminal and retargetserial.c. Both options are described in the link in my previous post

Posts: 16
Registered: ‎04-20-2017

Re: Debug print helper

Sorry, I skimmed over the link.  That explains a lot.

 

I'll let you know if I get it working.

 

Thanks