printf() to Console in Simplicity Studio 5

This tutorial walks through the different elements needed to send printf() statements to the console of Simplicity Studio.

Assumptions

This page assumes that you are using an EFR32xG22 with radio board BRD4183 and eval board BRD4001, using Simplicity Studio 5. This tutorial explains how to print using single wire output (SWO) to print to the Program Output Console of Simplicity Studio (however this also means that any terminal accessed through the command line will also show printf() statements).

Step-by-Step Walkthrough

  1. In 'Software Components', install the following (haven't tested how many of these are necessary, but this is what I did):
    1. IO Stream: SWO
    2. IO Stream
    3. SWO Debug (default settings are just fine)
  2. Go into your SSv5 files and drag-and-drop the following:
    1. hardware/kit/common/bsp_trace.c + bsp_trace.h
    2. hardware/kit/common/drivers/retargetswo.c + retargetswo.h
    3. hardware/kit/common/drivers/retargetio.c - This one is crucial, the program will compile without this file, but printf() will not work.
    4. bspconfig.h, bsphalconfig.h, bsp.h, traceconfig.h, and bsp_bcp.h (otherwise I had compilation errors).
  3. In your pintool, make sure you have assigned GPIO_SWCLK and GPIO_SWV (for whatever reason, GPIO_SWDIO seemed optional for me, however once it's in there it won't budge. These are also built into the eval board, so make sure you understand your board schematics before you assign these - they are already wired in.) pintool_swo.PNG
  4. Include "retargetswo.h" in your preprocessor directives.
  5. Optional: just in case, turn on your clock for your GPIO in app_init with "CMU_ClockEnable(cmuClock_GPIO, true);".
  6. In your app_init, add "RETARGET_SwoInit();" before your print statements.

That should be enough to allow you to print regular statements to your console (as well as get it to print using the commander functions in your terminal). Make sure you are looking to your "Program Output Console". I also found that I had to restart SSv5 and my board for this to work, and I also find that I have to reset it every once in a while or else the print statements pick up noise (if someone happens to be reading this and understands what is happening, I would be very interested to understand this phenomenon better).

hello.png

Bonus: printf() with Floats

For some reason, printing floats is not enabled by default. To fix this, go to Settings —> GNU Arm C++ Linker —> General, make sure that "Printf float" is checked (it is not by default).

printf_floats.png
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License