Serial Wire Output (SWO) viewer for tracing purposes. Tested on F401 and ST-LINK Utility as well as for F103 and Segger J-Link SWO viewer.

Dependents:   WiFi_Scanner mbed_nucleo_swo DISCO-F429ZI_LCDTS_demo_richard TEST_SM_SPEED

Embed: (wiki syntax)

« Back to documentation index

SWO_Channel Class Reference

SWO_Channel Class Reference

An SWO interface for debugging that supports Stream. More...

#include <SWO.h>

Public Member Functions

 SWO_Channel (const char *name=NULL)
 Create an SWO interface for debugging that supports Stream.
bool claim (FILE *stream=stdout)
 Function: claim.
int putc (int c)
 Write a character to the display.
int printf (const char *format,...)
 Write a formatted string to the display.

Protected Member Functions

virtual int _putc (int value)
 Write a single character (Stream implementation)
virtual int _getc ()
 Get a single character (Stream implementation)

Detailed Description

An SWO interface for debugging that supports Stream.

 #include "mbed.h"
 #include "SWO.h"

 DigitalOut myled(LED1); 

 Serial pc(SERIAL_TX, SERIAL_RX);

 SWO_Channel SWO();

 int main() {
   pc.printf("Hello World\n\r"); 

   SWO.printf("\r\nHello World from SWO\r\n");
   SWO.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
 
   while(1) {
     myled = 1; // LED is ON
     wait(0.2); // 200 ms
     myled = 0; // LED is OFF
     wait(1.0); // 1 sec
   
     SWO.putc('#');    
   }
 }

Currently works on nucleo ST-LINK using ST-Link Utility and other devices that support SWD/SWO using Segger SWO viewer

Definition at line 71 of file SWO.h.


Constructor & Destructor Documentation

SWO_Channel ( const char *  name = NULL )

Create an SWO interface for debugging that supports Stream.

Create and SWO interface for debugging that supports Stream.

Parameters:
constchar *name Channel name (default = none)

Currently works on nucleo ST-LINK using ST-Link Utility and other devices that support SWD/SWO using Segger SWO viewer

Definition at line 39 of file SWO.cpp.


Member Function Documentation

int _getc (  ) [protected, virtual]

Get a single character (Stream implementation)

Returns:
-1 Not supported

Definition at line 60 of file SWO.cpp.

int _putc ( int  value ) [protected, virtual]

Write a single character (Stream implementation)

Parameters:
valuecharacter to be displayed
Returns:
value

Definition at line 49 of file SWO.cpp.

bool claim ( FILE *  stream = stdout )

Function: claim.

Claim and redirect a stream to this SWO object Important: A name parameter must have been added when creating the SWO object.

Redirect a stream to this SWO object

Important: A name parameter must have been added when creating the SWO object:

 #include "SWO.h"
 ...
 SWO_Channel pc("modser");
 
 int main() {
   pc.claim();            // capture <stdout>
   pc.printf("Uses the SWO library\r\n");
   printf("So does this!\r\n");
 }
Parameters:
FILE*stream The stream to redirect (default = stdout)
Returns:
true if succeeded, else false
Parameters:
FILE*stream The stream to redirect (default = stdout)
Returns:
true if succeeded, else false

Definition at line 71 of file SWO.cpp.

int printf ( const char *  format,
  ... 
)

Write a formatted string to the display.

Parameters:
formatA printf-style format string, followed by the variables to use in formatting the string.
int putc ( int  c )

Write a character to the display.

Parameters:
cThe character to write to the display