This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

[Cortex-M3] SWO Packet Parsing

Note: This was originally posted on 21st February 2012 at http://forums.arm.com

Hi,

I'm trying to play with SEGGER JLink device and ARM M3 micro in order to implement a SWV engine.
Currently I set a SWD protocol communication, and all other needed definitions for the SWO activation:

DEMCR    = 0x01000000
DWT_FUNCTION0 = 0x00000000
DWT_FUNCTION1 = 0x00000000
DWT_FUNCTION2 = 0x00000000
DWT_FUNCTION3 = 0x00000000

I would like to monitor a variable located at address 0x2000017C, a 2 bytes length interger that changes every 100us:

DWT_COMP0   = 0x2000017C
DWT_MASK0  = 0x00000001
DWT_FUNCTION0 = 0x00000023

SELECTED_PIN_PROTOCOL_REG = 0x00000002
TPIU_ACPR       = 0x0000008F
LOCK_ACCESS_REGISTER   = 0xC5ACCE55
ITM_TCR       = 0x0001000F
ITM_TPR       = 0x0000000F
ITM_TER       = 0x00000000
DWT_CTRL       = 0x400003FE
TPIU_FFCR       = 0x00000100

When I start my acquisition phase, I'm able to obtain the buffer content from the TPIU (see attachment):


00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FC 00 00 00 05 8F 00 00 00 00 D0...

but I have difficulties regarding the parsing process: I'm not able to understand if the 28 bytes of 0s belong to the header that should terminates with only one 0b1.
The serie, in fact, terminates with 0xFC = 0b11111100, but I don't know if the first 1 bit (position [7]) belongs to the header definition, so if I have to discard it and consider the remaining value (0b1111100) value for the next data retrieving.

And after the header, how can I understand what type of info is following?

Thank you very much.
  • Note: This was originally posted on 13th April 2012 at http://forums.arm.com

    Ciao,

    can you please describe your SWO activation flow?
    And later, you should copy&paste a bunch of bytes that you're receving from the JLink device.

    I will let you know, if I'm able, the meaning of the frames.

    Thanks!
  • Note: This was originally posted on 16th April 2012 at http://forums.arm.com

    Hi,

    I tried to decode your data buffer with my own SWO packet parser and the result is here displayed:


    Unrecognized packet.
    Source data: 0xFE 0xF8 0xF9
    -----------------------------------------------------------------------
    Extension packet: EX = 523765.
    Source data: 0xDC 0xFC 0xFD 0x1F
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 28 - DATA: -54659847.
    Source data: 0xE3 0xF9 0xF4 0xBD 0xFC
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0xFD 0xFE
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 31 - DATA: 244.
    Source data: 0xF9 0xF4
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFD 0xFE
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0xFC 0xF7
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 31 - DATA: 244.
    Source data: 0xF9 0xF4
    -----------------------------------------------------------------------
    Data trace packet: FORMAT: Address - COMP.NUMBER: 3 - RAO: True - DATA: 56.
    Source data: 0x7D 0x38
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xF8 0xFD 0xFE 0xFD 0xFA 0xEC 0xFC 0xFC 0x7F
    -----------------------------------------------------------------------
    Local timestamp packet: GENERATION: DelayedToITMOrDWTData - VALUE: 2078334.
    Source data: 0xF0 0xFE 0xEC 0x7E
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFC 0xC7 0xFA 0xF9 0xDD 0xF2 0xFD 0x3F
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xC7 0xF8 0xF8 0xFC 0xFE
    -----------------------------------------------------------------------
    Extension packet: EX = 5119.
    Source data: 0xFC 0xFE 0x13
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0xF9 0xFD
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFD 0xFF
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFC 0xFC 0xFC 0xF8 0xF4 0xB2 0xFC 0xFD 0xFC 0xFC 0xF9 0xFC 0xFF 0xFE 0xFC 0xF1 0xFD 0xFE 0xFC 0x7C
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0x7F 0xFC
    -----------------------------------------------------------------------
    Extension packet: EX = 2060775.
    Source data: 0xFC 0xF9 0xF0 0x7C
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0x7F 0xFD
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 31 - DATA: -58921736.
    Source data: 0xFB 0xF8 0xEC 0x7C 0xFC
    -----------------------------------------------------------------------
    Data trace packet: FORMAT: Address - COMP.NUMBER: 3 - RAO: True - DATA: -84160514.
    Source data: 0x7F 0xFE 0xCF 0xFB 0xFA
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFF 0xFC 0xFC 0xFC 0xC7
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 31 - DATA: 65249.
    Source data: 0xFA 0xE1 0xFE
    -----------------------------------------------------------------------
    Extension packet: EX = 1048063.
    Source data: 0xFC 0xFF 0xFC 0x3F
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xE7 0xF8 0xDD 0xFC 0xF5
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0x1F 0xFC 0xF9 0xFE 0xBC
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0xFF 0xFE
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0x1F 0xD9 0xE8 0xFD 0xFC
    -----------------------------------------------------------------------
    Extension packet: EX = 319.
    Source data: 0xFC 0x4F
    -----------------------------------------------------------------------
    Extension packet: EX = 2095079.
    Source data: 0xFC 0xF9 0xF6 0x7E
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 30 - DATA: 252.
    Source data: 0xF1 0xFC
    -----------------------------------------------------------------------
    Data trace packet: FORMAT: ReadAccess - COMP.NUMBER: 0 - RAO: True - DATA: -34801412.
    Source data: 0x87 0xFC 0xF8 0xEC 0xFD
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0xFD 0xFE
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 30 - DATA: 254.
    Source data: 0xF1 0xFE
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xED 0xFE
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFD 0xBF
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFC 0xF8 0xF8 0xDC 0xBC 0xFD 0xFE 0xC7 0xFA 0xF9 0xDC 0xFE 0xFC 0xFC 0xF2 0xF8 0xF8 0xFF 0xFD 0xFC 0x1F
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 28 - DATA: -21629698.
    Source data: 0xE3 0xFE 0xF4 0xB5 0xFE
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFD 0xFE
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 28 - DATA: -50530818.
    Source data: 0xE3 0xFE 0xF5 0xFC 0xFC
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0xF1 0xF5
    -----------------------------------------------------------------------
    Extension packet: EX = 32247.
    Source data: 0xF8 0xFC 0x7C
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFD 0xFF
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0xFD 0xF1
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 31 - DATA: 31969.
    Source data: 0xFA 0xE1 0x7C
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFC 0xFF 0xFF 0xCF 0xFC 0xFD 0xFE 0xFD 0xF0 0xC7 0xFE 0xF9 0xFF 0xFD 0xFE 0x7F
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xC7 0xFE 0xE6 0xFD 0xFC
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0xFC 0xFA
    -----------------------------------------------------------------------
    Instrumentation packet: PORT: 31 - DATA: 63677.
    Source data: 0xFA 0xBD 0xF8
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFF 0xF2 0xFD 0xFC 0xF8
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xF6 0xFC 0xFF
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFF 0xFD 0xE0 0xF5 0xBC
    -----------------------------------------------------------------------
    Unrecognized packet.
    Source data: 0xFE 0x7F 0xF9
    -----------------------------------------------------------------------
    Remaining bytes: 14.
    0xF8 0xEC 0xF0 0xFF 0x87 0xF1 0xF9 0x8D 0xFF 0xFC 0xFC 0xFC 0xF2 0xF9
    -----------------------------------------------------------------------



    I have to admit that my parser seems to work, but it's still under debugging, so take my outcomes with care; in case you found any error...please le me know about it  .

    In case you didn't know it, the SWO protocol is described in this document: DDI0403D_arm_architecture_v7m_reference_manual_errata_markup_1_0.pdf, Appendix D.

    Bye bye.
  • Note: This was originally posted on 28th February 2012 at http://forums.arm.com

    Thank you Joseph,

    I already decoded the messages I retrieve via SWO, or better I've understood how to do that

    Thank you very much for the support.
  • Note: This was originally posted on 13th April 2012 at http://forums.arm.com

    Hi there,

    Can you please let me know the way to decode those packets.
    My problem is: I am using Cortex M3 microcontroller and using Eclipse IDE (C/C++) for the same. So I want to display the debug messages in my code(printf). I am checking SWV and I cn see SWP packets in Jlink control panel.I am receiving data but I cant really comprehend it.
    Please advice.

    Thanks
    Sushant
  • Note: This was originally posted on 13th April 2012 at http://forums.arm.com


    Ciao,

    can you please describe your SWO activation flow?
    And later, you should copy&paste a bunch of bytes that you're receving from the JLink device.

    I will let you know, if I'm able, the meaning of the frames.

    Thanks!


    Hi,
    Thanks for the quick response.

    I am not completely sure when you say SWO activation flow.(Sorry I am a newbie ).But allow me to give your detailed scenario.

    I am using 32-Micro-controlller from Energy Micro having Cortex M3 core for my development. The IDE is Eclipse Helios along with segger Jlink tools for debugging.
    Problem description: I am trying to develop some wireless application using Lightweight IP stack on FREE RTOS as lower level operating system.Now there are many Debug printf messages in LWIP stack which I want to get it displayed on some kind of terminal or any console so I can debug my code.

    I have enabled SWo using the Code provided by Energy Micro:void setupSWO(void) function.I know the enzable code works for sure because after calling the function and executing printf ("Hello world "),I can see the SWO packets in SWV tab of JLINK V4.36e control panel.Also , in JLINK Commander I can see the data by enabling by commands SWOread and SWOshow. but these bytes are in HEX and I am not sure whether these are the same data packets which i need or something else .  
    The SWObytes are as shown below:

    J-Link>SWOread
    256 bytes read (5201 bytes in host buffer)
    00000000 = FE F8 F9 DC FC FD 1F E3 F9 F4 BD FC FE FD FE F9
    00000010 = F4 FD FE FE FC F7 F9 F4 7D 38 F8 FD FE FD FA EC
    00000020 = FC FC 7F F0 FE EC 7E FC C7 FA F9 DD F2 FD 3F C7
    00000030 = F8 F8 FC FE FC FE 13 FE F9 FD FD FF FC FC FC F8
    00000040 = F4 B2 FC FD FC FC F9 FC FF FE FC F1 FD FE FC 7C
    00000050 = FE 7F FC FC F9 F0 7C FE 7F FD FB F8 EC 7C FC 7F
    00000060 = FE CF FB FA FF FC FC FC C7 FA E1 FE FC FF FC 3F
    00000070 = E7 F8 DD FC F5 1F FC F9 FE BC FE FF FE 1F D9 E8
    00000080 = FD FC FC 4F FC F9 F6 7E F1 FC 87 FC F8 EC FD FE
    00000090 = FD FE F1 FE ED FE FD BF FC F8 F8 DC BC FD FE C7
    000000A0 = FA F9 DC FE FC FC F2 F8 F8 FF FD FC 1F E3 FE F4
    000000B0 = B5 FE FD FE E3 FE F5 FC FC FE F1 F5 F8 FC 7C FD
    000000C0 = FF FE FD F1 FA E1 7C FC FF FF CF FC FD FE FD F0
    000000D0 = C7 FE F9 FF FD FE 7F C7 FE E6 FD FC FE FC FA FA
    000000E0 = BD F8 FF F2 FD FC F8 F6 FC FF FF FD E0 F5 BC FE
    000000F0 = 7F F9 F8 EC F0 FF 87 F1 F9 8D FF FC FC FC F2 F9

    Also Code to activate SWO:
    void setupSWO(void)
    {
       uint32_t *dwt_ctrl = (uint32_t *) 0xE0001000;
       uint32_t *tpiu_prescaler = (uint32_t *) 0xE0040010;
       uint32_t *tpiu_protocol = (uint32_t *) 0xE00400F0;

       CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
       /* Enable Serial wire output pin */
       GPIO->ROUTE |= GPIO_ROUTE_SWOPEN;
    #if defined(_EFM32_GIANT_FAMILY)
       /* Set location 0 */
       GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC0;

       /* Enable output on pin - GPIO Port F, Pin 2 */
       GPIO->P[5].MODEL &= ~(_GPIO_P_MODEL_MODE2_MASK);
       GPIO->P[5].MODEL |= GPIO_P_MODEL_MODE2_PUSHPULL;
    #else
       /* Set location 1 */
       GPIO->ROUTE = (GPIO->ROUTE & ~(_GPIO_ROUTE_SWLOCATION_MASK)) | GPIO_ROUTE_SWLOCATION_LOC1;
       /* Enable output on pin */
       GPIO->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE15_MASK);
       GPIO->P[2].MODEH |= GPIO_P_MODEH_MODE15_PUSHPULL;
    #endif
       /* Enable debug clock AUXHFRCO */
       CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;

       while(!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));

       /* Enable trace in core debug */
       CoreDebug->DHCSR |= 1;
       CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;

       /* Enable PC and IRQ sampling output */
       *dwt_ctrl = 0x400113FF;
       /* Set TPIU prescaler to 16. */
       *tpiu_prescaler = 0xf;
       /* Set protocol to NRZ */
       *tpiu_protocol = 2;
       /* Unlock ITM and output data */
       ITM->LAR = 0xC5ACCE55;
       ITM->TCR = 0x10009;
    }

    So please advice me on the issue
  • Note: This was originally posted on 28th February 2012 at http://forums.arm.com

    Hi there,
    I guess you need to get back to Segger to try to get more information from them.
    Or you can try to capture the data using a logic analyzer and compare against this.

    One thing you can try first is to use ITM stimulus port to generate easy to identify data on the trace, and see how the buffer content looks like.
    Then you can ensure the trace setup is working correctly before decoding other packet types.

    regards,
    Joseph