Reply
<a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Ninja</font></font> </a> tj
Posts: 40
Registered: ‎07-04-2016
Accepted Solution

SWO printf on ERF32MG

I am trying to run debug printf() with SWO in  Simplicity Studio.

I have code from AN0043, but got compilation errors.

 

../src/debug_printf.c: In function 'SWO_Setup':
../src/debug_printf.c:60:23: error: 'CMU_HFPERCLKEN0_GPIO' undeclared (first use in this function)
   CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
                       ^
../src/debug_printf.c:60:23: note: each undeclared identifier is reported only once for each function it appears in
../src/debug_printf.c:63:7: error: 'GPIO_TypeDef' has no member named 'ROUTE'
   GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
       ^
../src/debug_printf.c:63:18: error: 'GPIO_ROUTE_SWOPEN' undeclared (first use in this function)
   GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
                  ^
../src/debug_printf.c:78:4: error: #error Unknown device family!

 

I have changed 

  CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;

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

to

 

  CMU->HFBUSCLKEN0 |= CMU_HFBUSCLKEN0_GPIO;

  /* Enable Serial wire output pin */
  GPIO->ROUTEPEN |= GPIO_ROUTEPEN_SWVPEN;

But I don't known how to modify "#error Unknown device family!" part

Posts: 269
Registered: ‎03-03-2015

Re: SWO printf on ERF32MG

Hi TJ,

 

It looks like you are missing some of the emlib definitions in your program.  Do you have em_cmu.c and em_gpio.c in your project, and em_cmu.h and em_gpio.h included in this source file?  Can you find what line the #error preprocessor definition is occuring?  It will likely be inside an #if case, which will let you know what the preprocessor is looking for.

 

Regards,

Joe

Posts: 260
Registered: ‎09-18-2015

Re: SWO printf on ERF32MG

[ Edited ]

Hi tj,

 

I've attached some code to use SWO printf on Jade/Pearl/Blue/Flex/Mighty Gecko (they all work the same way for the purposes of SWO printf.

 

At least in Studio v3, the functions we included in the retargetswo.c driver did not work for these devices because the AUXHFRCO default frequency is 19 MHz and not 14 MHz as it is on the earlier EFM32 family parts.

 

This is supposed to be fixed in emlib 5.0, but a quick look at the bsp_trace.c function, which is where the SWO setup was moved, has me wondering if this is really the case.

 

Regardless, drop these into a project for Mighty Gecko. I put the pg_retargetswo.* files in the project's Drivers folder, but you can place them wherever is convenient.

 

John

<a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Ninja</font></font> </a> tj
Posts: 40
Registered: ‎07-04-2016

Re: SWO printf on ERF32MG

Demo is working correctly. 

I have added _write function, for printf redirect. Why printf don't call RETARGET_WriteChar  ?

 

int _write(int file, const char *ptr, int len)
{
    int x;
    for (x = 0; x < len; x++)
    ITM_SendChar (*ptr++);
    return (len);
}

 

SWO output I have only seen in Commander.

In Simplicity Studio V4 output console was empty. How to enable SWO in Simplicity ?

 

 

Posts: 260
Registered: ‎09-18-2015

Re: SWO printf on ERF32MG

[ Edited ]

Hi tj,

 

In Simplicity Studio V4 output console was empty. How to enable SWO in Simplicity ?

 

To be fair, I have not yet tried this in Studio v4, but I don't think the code should change.

 

I have seen some inconsistency in the behavior of SWO in both Studio v3 and v4. It seems to work on some STKs and not others, and I can't explain why this is the case. As I needed the SWO functionality for some customer RMA work that had to be completed, I ended up moving on and using the virtual COM port in those cases when I could not get SWO printf to work (which I think was on Wonder Gecko).

 

I'll try to run this in Studio v4 on a Mighty Gecko WSTK to see what happens.

 

Also, as I think I mentioned in my earlier reply, the SWO printf functionality has been moved into the BSP's trace enabling code. In discussions with the software team, they explained that they were going to centralize SWO support in the BSP code for all parts.

 

This is probably the way we ought to be doing it, not using my hack job Smiley Happy @Marius_G might be able to comment if this change has been made as it might require SDK 5.0 or later to use it.

 

John

Highlighted
Posts: 260
Registered: ‎09-18-2015

Re: SWO printf on ERF32MG

Hi tj,

 

I ported the project to the Mighty Gecko SDK with the BRD4151A Mighty Gecko 19.5 dBm Radio Board, and everything works as expected, in v4, too.

 

I've attached the project if you want to try it and have the our Mighty Gecko WSTK.

 

You import the project this way:

 

  1. In the Simplicity Studio IDE, go the File menu (not the Project menu) and select Import…
  2. Under General, select Existing Projects into Workspace, then click Next.
  3. For Select archive file, locate the shared project .ZIP file and select it.
  4. Make sure Copy projects into workspace is checked.
  5. Click Finish.

John

<a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Ninja</font></font> </a> tj
Posts: 40
Registered: ‎07-04-2016

Re: SWO printf on ERF32MG

Demo works perfectly Robot wink

Thank you for help.