Using the SWV Reader

The Serial Wire Viewer from ARM (Cortex-M microcontroller) provides non-intrusive real-time tracing (ITM). Usually this mechanism is used for printfs only. The impulse SWV Reader enhances SWV use-cases as it allows to log and trace different kind of data (real, integer, strings, logic) to be stored, visualized and analyzed with impulse.

Screen Cast: Using the SWV Reader

Usage

The SWV reader can be used together with ports (direct connection to the target using TCP, Serial, J-Link, ...).

Configuration

You can modify the serializer behavior under Preferences->impuse->Serializer->[serializer name]:
  • You may modify the serializer parameters (see "Parameters" - global variables depending on the serializer type).
  • You may add serializer configurations. You can select one configuration when using the serializer.
The SWV reader requires a serializer configuration  to work. Get to Preferences>impuse->Serializer->Serial Wire Viewer, press Add and select the SWV configuration:
  • Frequency/Divider: Enter the SWV frequency and divider value of your target.
  • Wait for sync: If checked, the read will wait for a sync packet to continue.
  • ITM0..31: Enter the data type for each ITM channel or "Not used".

Prepare the target

To import the Simple SWV Trace library and demo code, go to Import->impulse->Import Simple SWV Trace, select a root folder and press ok.

Enable SWV

You may use the information of your board provider and the sample in demo.c to enable SWV tracing in your target:
  void initSwv() {

      DBGMCUCR |= 0x00000027;
      DEMCR |= (1 << 24);
      ITM_LSR = 0xC5ACCE55;

      TPIU_SPPR = 0x00000002;     // Select NRZ mode
      TPIU_ACPR = 1;              // Divider 1 means /2

      ITM_TPR = 0x00000000;
      DWT_CTRL = 0x400003FE;
      FFCR = 0x00000100;

      ITM_TCR = 0x1000F;             // Enable ITM
      ITM_ENA = 0xffff;             // Enable ITM stimulus port

  }
  

Use the Simple SWV Trace library

  void itm_write_i8(unsigned char port, signed char b);
  void itm_write_i16(unsigned char port, short b);
  void itm_write_i32(unsigned char port, long b);
  void itm_write_i64(unsigned char port, long long b);
  void itm_write_f32(unsigned char port, float f);
  void itm_write_f64(unsigned char port, double f);
  void itm_write_t0(unsigned char port, const char* text);
  void itm_write_tn(unsigned char port, const char* text, char e);
  void itm_write_log(unsigned char port, unsigned char severity, const char* source, const char* message);
The library convert several data types into a defined byte order. See the demo code in demo.c how to use.
 

5 Example

  void demo() {

      itm_write_t0(0, "Start Demo");
      wait(100);
      itm_write_t0(0, "Measure");

      int i = 0;
      float f = 0.0;
      double d = 0.0;
      unsigned char uc = 0;
      signed char sc = 0;
      unsigned short us = 0;
      signed short ss = 0;
      unsigned long ul = 0;
      signed long sl = 0;
      unsigned long long ull = 0;
      signed long long sll = 0;
      unsigned char logic = 0;

      while (1) {

          // float
          f = sin(i / 100.0) * 100.;
          d = cos(i / 50.0 + 1.0) * 50. + 20;
          itm_write_f32(1, f);
          itm_write_f64(2, d);

          wait(10);

          // text
          if (i % 500 == 0)
              itm_write_t0(0, "i%50 reached \nmore to come\n");

          // bytes
          if (i % 100 == 0) {
              uc = i / 20;
              sc += 1;
              itm_write_i8(3, uc);
              itm_write_i8(4, sc);
          }

          // short
          if (i % 125 == 0) {
              us = d + i;
              ss = d * 20;
              itm_write_i16(5, us);
              itm_write_i16(6, ss);
          }

          // long
          if (i % 175 == 0) {
              ul = i;
              sl = -i;
              itm_write_i32(7, ul);
              itm_write_i32(8, sl);
          }

          // long long
          if (i % 225 == 0) {
              ull += rand();
              sll = (((long long) d) << 32) + rand();
              itm_write_i64(9, ull);
              itm_write_i64(10, sll);
          }

          // logic
          if (i % 25 == 0) {
              logic = i & 1;
              itm_write_i8(11, logic);
          }

          // log
          if (i > 0 && i % 200 == 0)
              itm_write_log(12, SEVERITY_INFO, "Test", "i % 200 == 0");
          if (i > 0 && i % 350 == 0)
              itm_write_log(12, SEVERITY_ERROR, "Test", ">= 350");

          i++;
      }
  }

Print

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive