JLINK SWO Viewer

  1 
  2 
  3 #define ITM_ENA   (*(volatile unsigned int*)0xE0000E00) // ITM Enable
  4 #define ITM_TPR   (*(volatile unsigned int*)0xE0000E40) // Trace Privilege Register
  5 #define ITM_TCR   (*(volatile unsigned int*)0xE0000E80) // ITM Trace Control Reg.
  6 #define ITM_LSR   (*(volatile unsigned int*)0xE0000FB0) // ITM Lock Status Register
  7 #define DHCSR     (*(volatile unsigned int*)0xE000EDF0) // Debug register
  8 #define DEMCR     (*(volatile unsigned int*)0xE000EDFC) // Debug register
  9 #define TPIU_ACPR (*(volatile unsigned int*)0xE0040010) // Async Clock presacler register
 10 #define TPIU_SPPR (*(volatile unsigned int*)0xE00400F0) // Selected Pin Protocol Register
 11 #define DWT_CTRL  (*(volatile unsigned int*)0xE0001000) // DWT Control Register
 12 #define FFCR      (*(volatile unsigned int*)0xE0040304) // Formatter and flush Control Register
 13 //
 14 // STIM word and byte acces
 15 #define ITM_STIM_U32  (*(volatile unsigned int*)0xE0000000)
 16 #define ITM_STIM_U8   (*(volatile char*)0xE0000000)
 17 
 18 // The stimulus port from which SWO data is received and displayed.
 19 unsigned int ITM_PORT_BIT0 = 0;
 20 
 21 // Has to be calculated according to the CPU speed and the output baud rate
 22 unsigned int TargetDiv = 1;
 23 
 24 void SWO_Enable( void )
 25 {
 26   unsigned int StimulusRegs;
 27   //
 28   // Enable access to SWO registers
 29   //
 30   DEMCR |= ( 1 << 24 );
 31   ITM_LSR = 0xC5ACCE55;
 32   //
 33   // Initially disable ITM and stimulus port
 34   // To make sure that nothing is transferred via SWO
 35   // when changing the SWO prescaler etc.
 36   //
 37   StimulusRegs = ITM_ENA;
 38   StimulusRegs &= ~( 1 << ITM_PORT_BIT0 );
 39   ITM_ENA = StimulusRegs; // Disable ITM stimulus port
 40   ITM_TCR = 0;            // Disable ITM
 41 
 42   //
 43   // Initialize SWO (prescaler, etc.)
 44   //
 45   TPIU_SPPR = 0x00000002;     // Select NRZ mode
 46   TPIU_ACPR = TargetDiv - 1;  // Example: 72/48 = 1,5 MHz
 47   ITM_TPR = 0x00000000;
 48   DWT_CTRL = 0x400003FE;
 49   FFCR = 0x00000100;
 50   //
 51   // Enable ITM and stimulus port
 52   //
 53   ITM_TCR = 0x1000D; // Enable ITM
 54   ITM_ENA = StimulusRegs | ( 1 << ITM_PORT_BIT0 ); // Enable ITM stimulus port
 55 }
 56 
 57 // Prints a character to the ITM_STIM register in order to provide data for SWO
 58 void SWO_PrintChar( char c )
 59 {
 60   // Check if SWO is set up. If it is not,
 61   // return to avoid that a program hangs if no debugger is connected.
 62   //
 63   // Check if DEBUGEN in DHCSR is set
 64   //
 65   if ( ( DHCSR & 1 ) != 1 )
 66     return;
 67 
 68   //
 69   // Check if TRACENA in DEMCR is set
 70   //
 71   if ( ( DEMCR & ( 1 << 24 ) ) == 0 )
 72     return;
 73 
 74   //
 75   // Check if ITM_TRC is enabled
 76   //
 77   if ( ( ITM_TCR & ( 1 << 22 ) ) == 1 )
 78     return;
 79 
 80   //
 81   // Check if stimulus port 0 is enabled
 82   //
 83   if ( ( ITM_ENA & 1 ) == 0 )
 84     return;
 85 
 86   //
 87   // Wait until STIMx is ready to accept at least 1 word
 88   //
 89   while ( ( ITM_STIM_U8 & 1 ) == 0 )
 90   {
 91 
 92   }
 93 
 94   ITM_STIM_U8 = c;
 95 }
 96 
 97 // Prints a string via SWO
 98 void SWO_PrintString( const char *s )
 99 {
100   //
101   // Print out character per character
102   //
103   while ( *s )
104   {
105     SWO_PrintChar( *s++ );
106   }
107 }

 JLINK SWO Viewer

Free-of-charge utility for J-Link. Displays the terminal output of the target using the SWO pin.
Can be used in parallel with a debugger or stand-alone.

This is especially useful when using debuggers which do not come with built-in support for SWO.

 http://www.segger.com/j-link-swo-viewer.html

 

你可能感兴趣的:(view)