- Silicon Labs Community
- Welcome and Announcements
- Silicon Labs Knowledge Base
- 8-bit MCU
- 32-bit MCU
- Bluetooth / Wi-Fi
- Other Products Category
- Optical/RH/Temp Sensor
- Other Products
- Hardware and Software Tools
- Simplicity Studio and Software
- General Discussions and Suggestions
- Chinese Forum
- Software Libraries
- Development Kits
- Reference Designs
- Third Party Tools
- White Papers
- Official Blog of Silicon Labs
- Chinese Blog
09-12-2017 10:50 AM
I created a debug print helper for adding debug output to projects, attached. To use:
- Add to your project
- In project configuration > C/C++ General > Paths and Symbols
- Click Manage Configurations
- Clone the default active configuration
- Rename the default active configuration to add (debug)
- Rename the new configuration to add (production)
- Click OK
- Select Symbols in the tabs and GNU C at the side
- Symbol = DEBUG
- Value = 3
- Click OK
- Click Manage Configurations
- Use the new debug statements in your code
- During debug use the debug configuration
- To disable debug output use the production configuration (Right click project > Build configurations > Set Active > (production))
09-13-2017 03:42 PM
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).
09-13-2017 03:56 PM
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.
09-15-2017 09:27 AM
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:
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.
09-15-2017 01:10 PM
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.
09-16-2017 06:37 AM
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.
09-16-2017 10:33 AM
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.
09-16-2017 04:42 PM
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