Reply
Posts: 1
Registered: ‎07-21-2014
Accepted Solution

SWO debug printf in Simplicity Studio IDE

Hello,

at the moment I'm evaluating the EFM32 TinyGecko with the STK3300 Starter Kit. I am trying to get debug printf() output in the program output console of Simplicity Studio IDE. For this I followed the instructions in AN0043. In the debug configuration on the Tracing panel, tracing is enabled, core clock is set to 14 MHz and SWO clock is set to "Auto".

When I run the debug session for the first time, the printf() text is displayed in the console as expected. But on subsequent debug runs, no text is displayed. After closing all Simplicity Studio programs (both IDE and launcher) and restarting them, it will work again for only one time.


Looking at the "SEGGER J-Link V4.84a Control panel" I find the following information:

In the SWV Tab:
Status: UART encoding, 900 kbps
"Bytes transferred" is counting as expected.
If "Analyze SWO data" is checked, packets are identified as SW source packets.

BUT:
The text is not shown in the program output console in Simplicity Studio IDE, although it seems that some data is transferred as indicated by the increasing "Bytes transferred" counter.

 

I would be grateful for your advice on how to fix this problem.

Kind regards, Sebastian

 

Posts: 147
Registered: ‎04-23-2013

Re: SWO debug printf in Simplicity Studio IDE

Unfortunately this is our bug, so you can't fix it yourself.  Robot Sad  I'm actually working on a fix for this as we speak, so it will be in the next update.  Until then, you'll have to use the SWO Terminal in eACommander to view SWO data.

 

Thanks,

Warren

Posts: 33
Registered: ‎01-27-2013

Re: SWO debug printf in Simplicity Studio IDE

Can this info be updated for Simplicity IDE?

In the debug configuration Trace is enabled, core clock is 14MHz and SWO clock is set to "auto", however I don't get any prints on the program output console.

 

Im also using a EFM32TG STK and this is the code:

int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();
  printf("Hello world!\n");
  while(1);
  return 0;
}

 

Posts: 147
Registered: ‎04-23-2013

Re: SWO debug printf in Simplicity Studio IDE

The bug was fixed in the last update.  I think the issue is that you haven't enabled SWO from your code.  Open eACommander, connect and go to the SWO Terminal tab.  That has a readme that contains the function setupSWOForPrint that you need to add and call before trying to write anything to SWO.  Also, I'm not sure what you need to do to get printf working.  I know ITM_SendChar works.

 

Thanks,

Warren

Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

@Warren: you state you're not sure what to do to get printf working in Simplicity IDE. According to me the example code of the application note works fine in Simplicity IDE, but I have the impression that the "ENDSWO" printf in the example code does something weird with the console output. At least what I see is that the first time I run a program the 'hello world' is printed. But then in subsequent runs of the application the SWO output is not always displayed. Could it be that somewhere in the SWO console source code there is a check on 'ENDSWO' that disables the output being displayed? And if there is, what steps should we undertake to enable the displaying again?

 

As answer to the initial question of this thread:

 

to get the printf working in your own application code in Simplicity IDE, you need to add the c file 'retargetio.c' from AN0043 to your project. Then, in your code, you have to define the following two functions:

 


/* Need to implement the two Retarget IO functions with the read/write functions we want to use for printf. */ int RETARGET_WriteChar(char c){ return ITM_SendChar (c); } int RETARGET_ReadChar(void){ return 0; }

 

Ensure stdio.h and em_device.h are included too.

 

You also need to add the SWO_Setup() function from the application note to ensure the SWO output is configured correctly. You can verify this configuration in your code by adding a direct call to ITM_SendChar('X"). The 'X' should appear in your console.

 

In your code, you should now be able to use 'printf' to print to the SWO output.

 

If it does not show up, put a breakpoint in the RETARGET_WriteChar function to check the function is actually called.

 

Regards,

 Lieven.

Posts: 2
Registered: ‎11-23-2014

Re: SWO debug printf in Simplicity Studio IDE

SWO debug printf in Simplicity Studio IDE is not working for me either.  It might be a HW problem because I still need to verify that SWO is connected on a custom board, but assuming it is connected, I would like to confirm the software setup:

 

1.  Add retargetio.c to the project

2.  Add the SWO_Setup() function from AN0043 to the source and call it before attempting a printf

3.  Implement the RETARGET_WriteChar() and RETARGET_ReadChar() functions.

4. I did not call printf("ENDSWO") or execute the following code:

 

/* First we need to wait until the ITM buffer is ready to accept new data. */
while (ITM_Port32(0) == 0);
/* Use the define at the top of this file to write to the correct ITM-port address. */
ITM_Port32(1) = i++;

 5. "Enable tracing" is checked on the Tracing menu in the Debug Configuration

 

Is there anything else that needs to be done?  I've confirmed that ITM_SendChar() is getting called (by virtue of the RETARGET_WriteChar() function), but I still do not see any output.

 

 

Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

Hello @DThomas, 

 

do you have an evaluation kit around that you could use to see if from the software side everything is working fine? Just flash the example code in the STK and you should see the characters being printed.

 

Regarding your software setup: looks OK to me. The fact that ITM_SendChar is called should print the characters to the output, so either the software is not working (check that with the STK reference code) or you did not correctly connect the SWO pin on your design.

 

Kind regards,

 Lieven.

Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

Hey @DThomas ,

 

another thing I noticed today is that you might need to add a '\n' at the end of the string you pass to 'printf' in order for it to appear in the console.

 

If you try this out and it works, please let us know.

 

Kind regards,

 Lieven.

 

 

Posts: 2
Registered: ‎11-23-2014

Re: SWO debug printf in Simplicity Studio IDE

@hollie,

 

I have a Giant Gecko development kit, so I can try it later.  I quickly tried adding a "\n" to the printf strings, but that did not solve the problem.

 

Posts: 147
Registered: ‎04-23-2013

Re: SWO debug printf in Simplicity Studio IDE

I took a look at AN0043 which has an example of setting up printf to go to the SWO terminal.  I believe the SWO_Setup function has an issue.  If you use setupSWOForPrint() instead it should work.  I'm not sure exactly why but have forwarded the issue to the responsible parties who will update the app note.  When using SWO_Setup it would occasionally print to the console but but not reliably.  Using setupSWOForPrint() instead it's working every time for me now.

 

You can find setupSWOForPrint() in eACommander's SWO terminal tab, or if using the latest Simplicity Studio, in the SWO Terminal tile.  It's also posted here:  http://community.silabs.com/t5/Simplicity-Studio-and-Software/how-to-enable-printf-output/m-p/133981...

 

I hope this helps.

 

Thanks,

Warren

 

Posts: 20
Registered: ‎02-26-2015

Re: SWO debug printf in Simplicity Studio IDE

Is it possible to use that example (AN0043) with the Gecko Starter Kit, or is it only for the Tiny Gecko and the Giant Gecko kits?

Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

Hey @benat

 

In my experience the example works on all kits, including the starter kits.

 

Regards,

 Lieven.

Posts: 20
Registered: ‎02-26-2015

Re: SWO debug printf in Simplicity Studio IDE

Hi,

 

As it can be seen on the attached video, I have followed all the steps to send Hello world through the SWO interface to the IAR IDE terminal output. However, as it can be seen on the video, I cant see the phrase Hello world in the IAR terminal output. I am using the AN0043 example and I havent change the source code. Where could be the mistake? Why could happen this?

 

Thank you

Posts: 20
Registered: ‎02-26-2015

Re: SWO debug printf in Simplicity Studio IDE

Here is the video

Posts: 20
Registered: ‎02-26-2015

Re: SWO debug printf in Simplicity Studio IDE

Highlighted
Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

Hey @benat,

 

I'm using Simplicity Studio and not IAR, so I'm afraid I can't help you with that.

 

Have you tried the example from the application note in combination with Simplicity Studio, just to verify that hardware-wise everything is OK?

 

And have you updated the SetupSWO function to use the most recent version of the code? I'm using:

 

void SWO_SetupForPrint(void) {
	/* Enable GPIO clock. */
	CMU ->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;

	/* Enable Serial wire output pin */GPIO ->ROUTE |= GPIO_ROUTE_SWOPEN;

#if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_LEOPARD_FAMILY) || defined(_EFM32_WONDER_FAMILY)
	/* Set location 0 */GPIO ->ROUTE = (GPIO ->ROUTE
			& ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC0;

	/* Enable output on pin - GPIO Port F, Pin 2 */GPIO ->P[5].MODEL &=
			~(_GPIO_P_MODEL_MODE2_MASK);
	GPIO ->P[5].MODEL |= GPIO_P_MODEL_MODE2_PUSHPULL;
#else
	/* Set location 1 */
	GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) |GPIO_ROUTE_SWLOCATION_LOC1;
	/* Enable output on pin */
	GPIO->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE15_MASK);
	GPIO->P[2].MODEH |= GPIO_P_MODEH_MODE15_PUSHPULL;
#endif

	/* Enable debug clock AUXHFRCO */CMU ->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;

	/* Wait until clock is ready */
	while (!(CMU ->STATUS & CMU_STATUS_AUXHFRCORDY))
		;

	/* Enable trace in core debug */CoreDebug ->DEMCR |=
			CoreDebug_DEMCR_TRCENA_Msk;
	ITM ->LAR = 0xC5ACCE55;
	ITM ->TER = 0x0;
	ITM ->TCR = 0x0;
	TPI ->SPPR = 2;
	TPI ->ACPR = 0xf;
	ITM ->TPR = 0x0;
	DWT ->CTRL = 0x400003FE;
	ITM ->TCR = 0x0001000D;
	TPI ->FFCR = 0x00000100;
	ITM ->TER = 0x1;
}

Best regards,

 Lieven.

Posts: 20
Registered: ‎02-26-2015

Re: SWO debug printf in Simplicity Studio IDE

I have just tried to use the code that you attached but I can still see nothing in the terminal output. 

Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

Hey @benat,

 

have you tried this example with Simplicity Studio?

 

Best regards,

 Lieven.

Posts: 8,080
Registered: ‎08-13-2003

Re: SWO debug printf in Simplicity Studio IDE

This is not an answer to your issue, it is an editorial.

 

I shy debug printf() as a pain in my largest muscle. I have solved many problems that were masked by the delays introduced by  debug printf() 

erik
Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

Hey Erik,

 

there is indeed a delay introduced by using printf, and it is useful to point out that this exists so that people can take it into account.

 

I'm interested: what alternative are you using to output debug information when developing an application?

 

Best regards,

 Lieven.

Posts: 8,080
Registered: ‎08-13-2003

Re: SWO debug printf in Simplicity Studio IDE

[ Edited ]

mainly "breadcrumbs".  If you think you need printf(), you can replace all your printf()s with array[aix] = mark_for_here; aix++;.  OK I use a circular buffer, but this should give the idea.

 

I guess that, of all the problems I have been called to solve timing counts for, at least, 75%.  For that reason I do not debug by methods that (significantly) affect timing.

 

In a very special application I did the above and in the idle loop transferred to a 512k flash memory to get a "behavioral report" for a unit you could not attach instrumentation to while operating

erik
Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

@erikm, thanks for your view on this. I'll try this out.

Posts: 451
Registered: ‎01-18-2004

Re: SWO debug printf in Simplicity Studio IDE


hollie wrote:

@erikm, thanks for your view on this. I'll try this out.


Erik's correct. printing to a terminal is useful but it takes some unknown amount of time, and embedded micros tend to be used in real-time applications. You don't want to miss some SPI thing when  the processor is busy handling a printf().

 

I've often found that it's easy enough to just run in the debugger and put a breakpoint on where I think I may have a problem. Sure, the breakpoint kills any follow-on real-time things, but it's quick and often useful.

 

Blinking LEDs or toggling unused output pins for monitoring on a 'scope is also a tried-and-true debug method.

Posts: 45
Registered: ‎05-16-2014

Re: SWO debug printf in Simplicity Studio IDE

Hello.

 

I'm using Simplicity Studio and STK3800 to debug EFM32TG mcu.

Is it possible to use SWO output console to print out some variables (ADC values, etc.)?

 

I found the code from SWO Terminal tab. But it isn't working when i call it to print info - console is clear.

 

Do i need to do any additional settings?

Posts: 45
Registered: ‎05-16-2014

Re: SWO debug printf in Simplicity Studio IDE

The default location for EFM32TG that defined in SWO Terminal function - is location 1. I changed it to location 0.

 

When i run debug mode and doing "Step into" (F5) - i saw test values into SWO console.
But when i pressed "Resume" (F8) - there were nothing.

 

Is that normal?

My problem is that i don't have any additional interface or display on the PCB.

That's why SWO is the way to get needed variable values.

Posts: 74
Registered: ‎02-05-2014

Re: SWO debug printf in Simplicity Studio IDE

Hey @benat

 

I just ported my existing code from a Leopard Gecko to a Gecko controller. I encountered the same problem you were seeing.

 

There is a missing statement in de setupSWOForPrint function that causes the ITM print to fail on Gecko controllers. In the first part of the function, the output pins are configured. You see that there is a different configuration used for Giant/Leopard/Wonder controllers versus all the other family types. 

The problem is that for regular Geckos the configuration should be identical to the one for Giant/Leopard/Wonder controllers.

 

So if you replace in the setupSWOForPrint function the following line:

 

#if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_LEOPARD_FAMILY) || defined(_EFM32_WONDER_FAMILY)

 

with:

#if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_LEOPARD_FAMILY) || defined(_EFM32_WONDER_FAMILY) || defined(_EFM32_GECKO_FAMILY)

 

Then the printing over ITM will work on the Gecko. The full code is here for your reference.

 

Best regards,

 Lieven.

Posts: 38
Registered: ‎04-28-2015

Re: SWO debug printf in Simplicity Studio IDE

Indeed, it seemed to output only if given a breakpoint on the printf line, perhaps to do with this comment from app note 0043.

 

    /* First we need to wait until the ITM buffer is ready to accept new data. */
    while (ITM_Port32(0) == 0);

 

In order to fix the builtin routine I found that using the following.

 

BSP_TraceSwoSetup();

DWT->CTRL = 0x400003FF;   //Taken from SetupSwoForPrint

 

This allows it to print during runtime repeatedly on the pearl starter kit atleast.