ITM SWO with SAM4E when using Atmel Studio, Percepio Trace, and SAM-ICE

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has anyone successfully gotten SWO output to correctly in Atmel Studio's PercepioTrace when using a Cortex-M4 device (SAM4E) and the SAM-ICE debugger? I think my problem is in the ITM setup code I cobbled together using various internet searches:

*((volatile unsigned *)0xE000EDFC) = 0x01000000;   // "Debug Exception and Monitor Control Register (DEMCR)"
*((volatile unsigned *)0xE0042004) = 0x00000027;
*((volatile unsigned *)0xE00400F0) = 0x00000002;   // "Selected PIN Protocol Register": Select which protocol to use for trace output (2: SWO)
uint32_t SWOSpeed = 4000000;
uint32_t SWOPrescaler = (48000000 / SWOSpeed) - 1; // SWOSpeed in Hz
*((volatile unsigned *)0xE0040010) = SWOPrescaler; // "Async Clock Prescaler Register". Scale the baud rate of the asynchronous output
*((volatile unsigned *)0xE0000FB0) = 0xC5ACCE55;   // ITM Lock Access Register, C5ACCE55 enables more write access to Control Register 0xE00 :: 0xFFC
*((volatile unsigned *)0xE0000E80) = 0x0001000D;   // ITM Trace Control Register
*((volatile unsigned *)0xE0000E40) = 0x0000000F;   // ITM Trace Privilege Register
*((volatile unsigned *)0xE0000E00) = 0x00000001;   // ITM Trace Enable Register. Enabled tracing on stimulus ports. One bit per stimulus port.
*((volatile unsigned *)0xE0001000) = 0x400003FE;   // DWT_CTRL
*((volatile unsigned *)0xE0040304) = 0x00000100;   // Formatter and Flush Control Register

 

For the SWO transmit I'm using the code described in this Precepio Trace video on YouTube from 2014:

#define ITM_TER *(volatile int*)0xE0000E00 // Trace Enable Register
#define ITM_TCR *(volatile int*)0xE0000E80 // Trace Control Register
#define ITM_STIM_8(n) *(volatile uint8_t*)(0xE0000000 + ((n) * 4)) // 8 Bit N < 32

void SWO_print_char(int port, char c);
void SWO_print_string(int port, const char *s);

void SWO_print_char( int port, char c )
{
    while ((ITM_STIM_8(port) & 1) == 0);
    ITM_STIM_8(port) = c;
}

void SWO_print_string( int port, const char *s )
{
    if ((ITM_TCR & 1) == 0 ) return;
    if ((ITM_TER & 1) == 0 ) return;

    while (*s) SWO_print_char(port, *s++);
    SWO_print_char(port, 0);
}

 

Yet the output I get is garbled:

[244 - 3341] (28) " ``  ` `   ```````` "
[3377 - 5280] (28) "` `` ``` ` ```````"
[5379 - 5595] (28) "` "
[5595 - 8073] (28) "``` ```  ````  ``"
[8273 - 10276] (28) "     ``````` "
[10411 - 10591] (28) "` "
[10654 - 13700] (28) "  `` ```` `` ` `  ```` ``"
[13736 - 18168] (28) "   ` `````` ````  `  ``"
[18267 - 19223] (28) " ```  "
[19331 - 20495] (28) "````  ` ``` "
[20711 - 27572] (28) "   ` `````````` ``  `  ``  ``      ``` ``"

 

Does anyone have any insight as to what I'm doing incorrectly? This is frustrating that I can't get similar results as what is seen in the attached 1.jpg.

Attachment(s): 

Last Edited: Fri. Nov 11, 2016 - 04:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try first without your init code... Atmel Studio configures the TPIU and ITM module when you turn it on... 

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the response. Unfortunately, I not seeing any output in the PercepioTrace window.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the percepio settings, try to set '0' as the core frequency. This causes the sam-ice to measure the core frequency automatically

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Still no output unless I add the initialization code. I'm going to monitor the SWO output with an oscilloscope.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've managed to get it working with your help, thank you. My final issue was SWO_print_string() was being called too quickly and was likely overflowing buffers. That explains either no data or garbled data. You are correct that no initialization code is required and that when tracing is enabled the correct ITM and TPIU registers are set.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great :) 

 

Yes, the main issue I've seen when configuring trace is clocks (i.e either causing overflows or not syncing)

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)