<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Make printf work in ISRs with interrupt driven UART driver in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179783#M2604</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use interrupt driven UART driver ("ittya:") on my project and wanted to have unexpected exception beeing displayed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, in the mqx/source/bsp/&amp;lt;myboard&amp;gt;/init_bsp.c, I added&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _int_install_unexpected_isr();&lt;/P&gt;&lt;P&gt;to set the default handler for unexpected ISRs; this is&amp;nbsp; _int_unexpected_isr() defined in mqx/source/psp/coldfire/int_unx.c&lt;/P&gt;&lt;P&gt;But as said in this file "&amp;nbsp;This default I/O must NOT be an interrupt drive I/O channel"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, with a very small change to the UART driver this works fine. The trick is : when printf is called from an ISR, send the characters directly to the UART.&lt;/P&gt;&lt;P&gt;For this, just edit&lt;/P&gt;&lt;P&gt;mqx/source/io/serial/int/serl_int.c&lt;/P&gt;&lt;P&gt;to add the following lines at the beginning of _io_serial_int_putc_internal()&amp;nbsp; (just after /* End CR 388 */) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (_io_serial_int_write_force_polled_mode) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* directly write to UART, bypassing normal interrupt driven code */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int_io_dev_ptr-&amp;gt;DEV_PUTC(int_io_dev_ptr, c);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;Then add to mqx/source/fio/io_util.c :&lt;/P&gt;&lt;P&gt;boolean _io_serial_int_write_force_polled_mode = FALSE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And to mqx/source/include/fio.h&lt;/P&gt;&lt;P&gt;extern boolean _io_serial_int_write_force_polled_mode;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in mqx/source/psp/coldfire/int_unx.c, before first printf() add :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _io_serial_int_write_force_polled_mode = TRUE; /* force polled UART mode (needed when called from ISR) */&lt;/P&gt;&lt;P&gt;and after last printf() :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _io_serial_int_write_force_polled_mode = FALSE; /* no more force polled mode */&lt;BR /&gt;&lt;BR /&gt;You can also force the output to be written to the default serial port instead of the current stdout (useful if the terminal of the task producing the exception is not a serial port; a telnet session for example); for this declare :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; pointer stdout_orig;&lt;BR /&gt;then before first printf :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _io_serial_int_write_force_polled_mode = TRUE; /* force polled UART mode (needed when called from ISR) */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; stdout_orig = td_ptr-&amp;gt;STDOUT_STREAM;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; td_ptr-&amp;gt;STDOUT_STREAM = kernel_data-&amp;gt;PROCESSOR_STDOUT; /* force printf output on default console */&lt;BR /&gt;and after last one :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; td_ptr-&amp;gt;STDOUT_STREAM = stdout_orig; /* restore stdout */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; _io_serial_int_write_force_polled_mode = FALSE; /* no more force polled mode */&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 05 Nov 2011 05:40:23 GMT</pubDate>
    <dc:creator>trailman</dc:creator>
    <dc:date>2011-11-05T05:40:23Z</dc:date>
    <item>
      <title>Make printf work in ISRs with interrupt driven UART driver</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179783#M2604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use interrupt driven UART driver ("ittya:") on my project and wanted to have unexpected exception beeing displayed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, in the mqx/source/bsp/&amp;lt;myboard&amp;gt;/init_bsp.c, I added&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _int_install_unexpected_isr();&lt;/P&gt;&lt;P&gt;to set the default handler for unexpected ISRs; this is&amp;nbsp; _int_unexpected_isr() defined in mqx/source/psp/coldfire/int_unx.c&lt;/P&gt;&lt;P&gt;But as said in this file "&amp;nbsp;This default I/O must NOT be an interrupt drive I/O channel"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, with a very small change to the UART driver this works fine. The trick is : when printf is called from an ISR, send the characters directly to the UART.&lt;/P&gt;&lt;P&gt;For this, just edit&lt;/P&gt;&lt;P&gt;mqx/source/io/serial/int/serl_int.c&lt;/P&gt;&lt;P&gt;to add the following lines at the beginning of _io_serial_int_putc_internal()&amp;nbsp; (just after /* End CR 388 */) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (_io_serial_int_write_force_polled_mode) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* directly write to UART, bypassing normal interrupt driven code */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int_io_dev_ptr-&amp;gt;DEV_PUTC(int_io_dev_ptr, c);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;Then add to mqx/source/fio/io_util.c :&lt;/P&gt;&lt;P&gt;boolean _io_serial_int_write_force_polled_mode = FALSE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And to mqx/source/include/fio.h&lt;/P&gt;&lt;P&gt;extern boolean _io_serial_int_write_force_polled_mode;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in mqx/source/psp/coldfire/int_unx.c, before first printf() add :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _io_serial_int_write_force_polled_mode = TRUE; /* force polled UART mode (needed when called from ISR) */&lt;/P&gt;&lt;P&gt;and after last printf() :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _io_serial_int_write_force_polled_mode = FALSE; /* no more force polled mode */&lt;BR /&gt;&lt;BR /&gt;You can also force the output to be written to the default serial port instead of the current stdout (useful if the terminal of the task producing the exception is not a serial port; a telnet session for example); for this declare :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; pointer stdout_orig;&lt;BR /&gt;then before first printf :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _io_serial_int_write_force_polled_mode = TRUE; /* force polled UART mode (needed when called from ISR) */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; stdout_orig = td_ptr-&amp;gt;STDOUT_STREAM;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; td_ptr-&amp;gt;STDOUT_STREAM = kernel_data-&amp;gt;PROCESSOR_STDOUT; /* force printf output on default console */&lt;BR /&gt;and after last one :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; td_ptr-&amp;gt;STDOUT_STREAM = stdout_orig; /* restore stdout */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; _io_serial_int_write_force_polled_mode = FALSE; /* no more force polled mode */&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Nov 2011 05:40:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179783#M2604</guid>
      <dc:creator>trailman</dc:creator>
      <dc:date>2011-11-05T05:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Make printf work in ISRs with interrupt driven UART driver</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179784#M2605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's probably a simplier solution without the extra variable&amp;nbsp; _io_serial_int_write_force_polled_mode, but I have not tested it yet.&lt;/P&gt;&lt;P&gt;Use&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_mqx_kernel_data-&amp;gt;IN_ISR) {&lt;/P&gt;&lt;P&gt;instead of&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_io_serial_int_write_force_polled_mode) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or cleaner but longer :&lt;/P&gt;&lt;P&gt;&amp;nbsp; KERNEL_DATA_STRUCT_PTR kernel_data;&lt;BR /&gt;&amp;nbsp; _GET_KERNEL_DATA(kernel_data);&lt;BR /&gt;&amp;nbsp; if (kernel_data-&amp;gt;IN_ISR) {&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Nov 2011 05:52:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179784#M2605</guid>
      <dc:creator>trailman</dc:creator>
      <dc:date>2011-11-05T05:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Make printf work in ISRs with interrupt driven UART driver</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179785#M2606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Does this:&amp;nbsp; int_io_dev_ptr-&amp;gt;DEV_PUTC(int_io_dev_ptr, c);&lt;/P&gt;&lt;P&gt;call the function: void _kuart_int_putc().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function waits TX-register to be empty:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; while (!(sci_ptr-&amp;gt;S1 &amp;amp; UART_S1_TDRE_MASK)) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Wait while buffer is full */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; } /* Endwhile */&lt;/P&gt;&lt;P&gt;Prevents/blocks other interrupts to be served during this time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about, if you increase a global variable in unexpected int routine and check and print&lt;/P&gt;&lt;P&gt;that variable in main task of you system.&lt;/P&gt;&lt;P&gt;~Mark&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Nov 2011 19:52:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179785#M2606</guid>
      <dc:creator>MarkP_</dc:creator>
      <dc:date>2011-11-05T19:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: Make printf work in ISRs with interrupt driven UART driver</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179786#M2607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're right, the function called by int_io_dev_ptr-&amp;gt;DEV_PUTC() polls the TX register before sending a character.&lt;/P&gt;&lt;P&gt;For MCF52259, this function is&amp;nbsp;_mcf52xx_uart_serial_int_putc() defined in&amp;nbsp;mqx/source/io/serial/int/serl_int_mcf52xx.c (this is set when calling _io_serial_int_install() in mqx/source/io/serial/int/serl_int.c to install the driver)&lt;/P&gt;&lt;P&gt;But this is not worse than doing this when using the polled UART driver. The purpose here is just to have the same functionality than with the polled UART driver.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OK, other interrupts are lost when printing characters from the ISR, but it's OK for me because the purpose is not to use prinf() in the ISRs used by the drivers (which would not be a good idea), but to display fatal exceptions (data access error, code corruption, ...) or unhandled ISRs (that should never occur).&lt;/P&gt;&lt;P&gt;On my system, I added a reset at the end of the int_unx.c to reset the board when such a problem occur, so I don't care about loosing interrupts. The more important to me is to know the task, the type of error, and the address in code at which the porblem occured.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Nov 2011 23:29:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Make-printf-work-in-ISRs-with-interrupt-driven-UART-driver/m-p/179786#M2607</guid>
      <dc:creator>trailman</dc:creator>
      <dc:date>2011-11-05T23:29:52Z</dc:date>
    </item>
  </channel>
</rss>

