SWO with MQX 4.1.0, JLink, IAR, K64 Freedom

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

SWO with MQX 4.1.0, JLink, IAR, K64 Freedom

Jump to solution
1,321 Views
razed11
Contributor V

Hi Everyone,

I've been reading through the IAR and MQX documentation and can't seem to find explicit instructions as to how to enable SWO. I have choose SWO for stderr/stdout with semihosting using the "Hello" example but it continues to call _io_serial_polled_write.

Related to this is the library build. I followed the instructions and built all the libraries and then added the existing "Hello" project. I chose SWO in the BSP library as well.

I cut/opened the trace at J8 and J12 to allow the JLink connection.

My application will eventually use four serial ports and I'd like to use SWO for debugging.

The libraries and RTOS look promising in general.

Kenny

0 Kudos
1 Solution
732 Views
razed11
Contributor V

Final ITM answer:


Set BSPCFG_ENABLE_IODEBUG to 1 in user_config.h.

Change the following:

const IODEBUG_INIT_STRUCT _bsp_iodebug_init = {

    IODEBUG_MODE_SEMIHOST,  /* Driver mode */

    127,                    /* Length of buffered data */

    '\n'                    /* Default flush character */

};

to

const IODEBUG_INIT_STRUCT _bsp_iodebug_init = {

    IODEBUG_MODE_ITM,  /* Driver mode */

    0,                    /* Length of buffered data */

    '\n'                    /* Default flush character */

};

In IAR the other piece is to direct stimulus port 0 to the terminal window and enable PC samples.

Screen Shot 2014-08-26 at 5.39.40 PM.png

Screen Shot 2014-08-26 at 5.40.07 PM.png

So ITM initialization code is not required by the firmware. The debugger + JLink will configure these registers appropriately.

Unfortunately IAR seems to forget to enable the ITM ports between debugging sessions. Maybe it is a JLink issue.

View solution in original post

0 Kudos
6 Replies
732 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Kenny,

Please check the following thread

Re: How to use SWO on Kinetis?


Have a great day,
Daniel

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
732 Views
razed11
Contributor V

Hi Daniel,

Thanks. I read that thread before I posted but I'll give it another read.

Specifically I'd like to understand the following:

Does the MQX 4.1.x environment already provide the configuration code to do this? Seems a shame to rewrite it. Seems like it should be included.

Why, when I select semithosting/SWO, is the low-level routine that implements this not being called when printf() is invoked?

Kenny

0 Kudos
732 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Kenny,

I suggest you open the psp C:\Freescale\Freescale_MQX_4_1\mqx\source\include\fio.h file, please comment the next line like this:

//define printf  _io_printf

after that  recompile all libraries and your application and debug it, open the io terminal in view->terminal I/O menu, you will see that every printf will be routed to the internal IAR terminal.

I hope it helps


Have a great day,
Daniel

0 Kudos
732 Views
razed11
Contributor V

Thanks for the suggestion Daniel. I'm going to be a stickler and suggest that I'd prefer not to modify the library file directly.

The MQX IO User Guide Chapter 23 suggests how to enable this using user_config.h by setting BSPCFG_ENABLE_IODEBUG to 1.

I can step in to this call from the debugger in bsp_init.c:

#if BSPCFG_ENABLE_IODEBUG

    _io_debug_install("iodebug:", &_bsp_iodebug_init);

#endif

The following is defined in init_iodebug.c (although I'd prefer to use SWO)

const IODEBUG_INIT_STRUCT _bsp_iodebug_init = {

    IODEBUG_MODE_SEMIHOST,  /* Driver mode */

    127,                    /* Length of buffered data */

    '\n'                    /* Default flush character */

};

It gets a little low-level after this but it seems to want to do the correct thing but still prints to the UART.

0 Kudos
732 Views
razed11
Contributor V

OK. Working. Just needed the call to open this device. I'm not sure if this is global or local to the task. In other words, if another task calls printf() will it use semihosting.

In summary set BSPCFG_ENABLE_IODEBUG to 1. This is for semihosting output. I'll try SWO next.

    FILE_PTR fh_ptr;

    if (NULL == (fh_ptr = fopen("iodebug:", NULL)))

    {

        printf("Cannot open the debug output\n");

    }

    else

    {

        _io_set_handle(IO_STDOUT, fh_ptr);

        printf("This is printed to the debug output\n");

    }

    fflush(stdout);

   

    if (fh_ptr != NULL)

    {

        fclose(fh_ptr);

    }

0 Kudos
733 Views
razed11
Contributor V

Final ITM answer:


Set BSPCFG_ENABLE_IODEBUG to 1 in user_config.h.

Change the following:

const IODEBUG_INIT_STRUCT _bsp_iodebug_init = {

    IODEBUG_MODE_SEMIHOST,  /* Driver mode */

    127,                    /* Length of buffered data */

    '\n'                    /* Default flush character */

};

to

const IODEBUG_INIT_STRUCT _bsp_iodebug_init = {

    IODEBUG_MODE_ITM,  /* Driver mode */

    0,                    /* Length of buffered data */

    '\n'                    /* Default flush character */

};

In IAR the other piece is to direct stimulus port 0 to the terminal window and enable PC samples.

Screen Shot 2014-08-26 at 5.39.40 PM.png

Screen Shot 2014-08-26 at 5.40.07 PM.png

So ITM initialization code is not required by the firmware. The debugger + JLink will configure these registers appropriately.

Unfortunately IAR seems to forget to enable the ITM ports between debugging sessions. Maybe it is a JLink issue.

0 Kudos