SWO Data Output on i.MX7D

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SWO Data Output on i.MX7D

1,416 Views
andy_kiser
Contributor II

Does the i.MX7D support outputting data through the TDO/SWO pin by code running on the Cortex-M4 core?

* I configured the debug port to SWD mode

* Connected an oscilloscope to the SWO pin

* On the M4 I tried to run various examples I found to output debug data through SWO.

The code runs without problems, but I couldn't see any toggling of the SWO pin. My conclusion is that either I missed some initialization such as turning on a clock or configuring the SWO pin, or the i.MX7D does not support SWO.

I attached the core routines `SWO_Enable()` and `SWO_SendDataPolling()` for reference.

Side note: I'm also interested whether the i.MX8 family supports SWO. But to keep the focus of the question, let's stay with the i.MX7D here.

Regards, 

Andy

Tags (3)
0 Kudos
4 Replies

1,223 Views
Yuri
NXP Employee
NXP Employee

Hello,

 

 You may try the attached.

 

Have a great day,

Yuri

 

 

-------------------------------------------------------------------------------

Note:

- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored

 

Please open a new thread and refer to the closed one, if you have a related question at a later point in time.

0 Kudos

1,223 Views
andy_kiser
Contributor II

Dear Yuri 

Thank you for getting back to me. I tried your suggestion, but unfortunately without success.

Compared to my previous tests, your suggestion contains an additional check for bit TRCENA in the DEMCR register, so I added this bit to my initialization code and output routine. It finally looks as follows:

/*!brief Ensure that output via SWO is enabled in order to guarantee that the
   application does not hang. */
void SWO_Enable()
{
    const uint32_t _ITMPort = 0;
    const uint32_t TargetDiv = 266;

    uint32_t StimulusRegs;//// Enable access to SWO registers//
    
    DEMCR |= (1 << 24);  ITM_LSR = 0xC5ACCE55;
    //
    // Initially disable ITM and stimulus port
    // To make sure that nothing is transferred via SWO
    // when changing the SWO prescaler etc.
    //  
    StimulusRegs = ITM_ENA;
    StimulusRegs &= ~(1 << _ITMPort);
    ITM_ENA = StimulusRegs; // Disable ITM stimulus 
    ITM_TCR = 0; // Disable ITM
    //
    // Initialize SWO (prescaler, etc.)
    //  
    TPIU_SPPR = 0x00000002; // Select NRZ mode
    TPIU_ACPR = TargetDiv - 1; // Example: 72/48 = 1,5 MHz
    ITM_TPR = 0x00000000;
    DWT_CTRL = 0x400003FE;
    FFCR = 0x00000100;
    //
    // Enable ITM and stimulus port
    //
    ITM_TCR = 0x1000D;  // Enable ITM  
    ITM_ENA = StimulusRegs | (1 << _ITMPort); // Enable ITM stimulus port
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And my output routine is:

/* send data to SWO port, as suggested by Yuri Muhin at 
https://community.nxp.com/message/1216347?commentID=1216347#comment-1216347 */ 
int SWO_Write(int iFileHandle, char *pcBuffer, int iLength) 
{
       int32_t num = 0;

    // TODO : Should potentially check that iFileHandle == 1 to confirm
    // that write is to stdout
    
    if ((DEMCR & TRCENA) &&             // debugger connected and ITM channel enabled for tracing?
        (ITM_TCR & ITM_TCR_ITMENA) &&   // ITM enabled?
        (ITM_TER & ITM_TER_PORT0ENA))   // ITM Port #0 enabled?
    {
        while (num < iLength) 
        {
            while (ITM_Port32(0) == 0) 
            {}
            ITM_Port8(0) = pcBuffer[num++];
        }
        return 0;
    } 
    else
    {    // Function returns number of unwritten bytes if error
        return (iLength);
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I called SWO_Enable() once, and then SWO_Write() repeatedly, with a delay of 100ms after each character.

By stepping through the code I could prove that the execution path successfully made it through all if-conditions of SWO_Write(), so the actual write
    ITM_Port8(0) = pcBuffer[num++];

got executed each time.

On the hardware side, I used an oscilloscope to monitor the behavior

  • As expected, the SWDIO/TMS pin (pin 7 of 20) was toggling when the debugger talked to the target while stepping through the code.
  • The SWO/TDO pin (pin 13 of 20) stayed high at all times - the i.MX7 did not output any data through this pin.
    • To make sure there is no connection issue, I switched the debugger from SWD to JTAG mode without modifying the hardware setup, and started debugging again. Now I was able to see the TDO pin (pin 13 of 20) toggling as expected.

Did you ever see SWO working on the i.MX7, or might that feature be broken at all?

Best Regards,

Andy

0 Kudos

1,223 Views
Yuri
NXP Employee
NXP Employee

Hello,

  imx7d can support SWD mode;
 
1> When the JTAG interface is in Debug Mode, it can be operating in
 JTAG/cJTAG/SWD interface ;
a> JTAG_MOD == 0, Debug Mode:
DAP is the only TAP controller in the daisy chain. SJC and SDMA will be attached to JTAG-AP of DAP.
b> JTAG_MOD == 1, Test Mode:
  
SJC is the only TAP controller in the daisy chain.
 
2> when operate in debug mode (pad JTAG_MODE=0), configure DAP to opeation in SWD mode;   
     TMS -> SWDIO 
     TCK ->  SWCLK

Regards,

Yuri.

0 Kudos

1,223 Views
andy_kiser
Contributor II

Dear Yuri
Thank you for getting back to me. I'm aware that SWD mode is supported.  

The question was, whether the i.MX7 supports to send data through the SWO signal. 

Regards, Andy

0 Kudos