<?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 Re: MPC5643L UART interrupt handling in MPC5xxx</title>
    <link>https://community.nxp.com/t5/MPC5xxx/MPC5643L-UART-interrupt-handling/m-p/1400047#M20153</link>
    <description>&lt;P&gt;I have managed this to work, by making the following modifications to UART_init.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;reg-&amp;gt;UARTCR.B.TFBM = 0u; /* Buffered mode = 0 for TX */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.RFBM = 0u; /* Buffered mode = 0 for RX */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.TDFL_TFC = 0u; /* Number of bytes to transmit = 1 */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.RDFL_RFC0 = 0u; /* Number of bytes to receive = 1 */&lt;/P&gt;&lt;P&gt;This disables the FIFO which is undesirable in high speed transfers.&lt;/P&gt;&lt;P&gt;Seems to me that the spec of the UART is very strange.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;You do not expect to get receive interrupts without incoming characters.&lt;/LI&gt;&lt;LI&gt;You expect to have an active transmit interrupt if the FIFO is empty.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It seems like the FIFOs are useless in interrupt mode.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What is the expected structure of a UART driver in interrupt mode with FIFO enabled?&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Right now, I am forced to keep track if I am sending or not&lt;BR /&gt;The UART write character function will have to check a "sending" flag.&lt;BR /&gt;The function will place the character in a S/W FIFO.&lt;BR /&gt;If the "sending" flag is not set, the character has to be written to the UART.&lt;BR /&gt;The flag is then set.&lt;/P&gt;&lt;P&gt;The UART send interrupt will read a character from the S/W FIFO.&lt;BR /&gt;If empty, the flag will be cleared.&lt;/P&gt;&lt;P&gt;"Normal" UARTs will assert the TX interrupt if the FIFO is empty.&lt;BR /&gt;The Write character function will just enable the TX interrupt at the end.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;, and if I am sending&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jan 2022 07:51:48 GMT</pubDate>
    <dc:creator>emagii</dc:creator>
    <dc:date>2022-01-17T07:51:48Z</dc:date>
    <item>
      <title>MPC5643L UART interrupt handling</title>
      <link>https://community.nxp.com/t5/MPC5xxx/MPC5643L-UART-interrupt-handling/m-p/1399028#M20132</link>
      <description>&lt;P&gt;I have an bootloader which runs the UARTs in polled mode.&lt;BR /&gt;When I switch to the&amp;nbsp;application, I want to run the UARTs in interrupt mode&lt;BR /&gt;which maintains S/W FIFOs in both directions.&lt;/P&gt;&lt;P&gt;After I initialize and enable interrupts, I get continuous interrupts on the receiver.&lt;BR /&gt;I have looked at the UARTCR and UARTSR, and cannot find a reason for this.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;How can I stop the UART from generating continuous receive interrupts?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Here are the UARTCR/SR.&lt;/P&gt;&lt;P&gt;UARTCR = 233&lt;/P&gt;&lt;P&gt;TDFL&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;RDFL&amp;nbsp; &amp;nbsp;0&lt;BR /&gt;RFBM&amp;nbsp; 1 FIFO&lt;BR /&gt;TFBM&amp;nbsp; &amp;nbsp;0 BUFFER&lt;BR /&gt;WL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01 8 bit&lt;BR /&gt;PC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00 No Parity?&lt;BR /&gt;RXEN&amp;nbsp; 1 Enabled&lt;BR /&gt;TXEN&amp;nbsp; 1 Enabled&lt;BR /&gt;PCE&amp;nbsp; &amp;nbsp; 0 ?&lt;BR /&gt;UART 1 UART Mode&lt;/P&gt;&lt;P&gt;UARTSR = 0x4C&lt;/P&gt;&lt;P&gt;&amp;lt;upper&amp;gt;&amp;nbsp; &amp;nbsp;0&lt;BR /&gt;RPS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 Receive Pin State&lt;BR /&gt;WUF&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 Wakeup&lt;BR /&gt;TO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 Timeout&lt;BR /&gt;DRFRFE 1 FIFO Empty&lt;BR /&gt;DTFTFF&amp;nbsp; 0 Not Completed&lt;BR /&gt;NF&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 No event&lt;/P&gt;&lt;P&gt;I enable the receiver before the transmitter, and in a previous revision without disabling global interruipts, I got this stream of receive interrupts before enabling the transmit interrupt.&lt;/P&gt;&lt;P&gt;I am also curious how the transmit interrupt should work in a real system.&lt;BR /&gt;I am reusing code for another processor.&lt;/P&gt;&lt;P&gt;This works as follows:&lt;BR /&gt;In idle mode, the transmitter is empty, which generates a transmit interrupt request.&lt;BR /&gt;The transmit interrupt is disabled as long as there are no characters to send..&lt;BR /&gt;&lt;SPAN&gt;The putchar routine inserts a byte in the S/W FIFO and enables the transmit interrupt.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The transmit interrupt will send characters as long as the S/W FIFO is not empty.&lt;BR /&gt;When the S/W FIFO is empty, then the transmit interrupt will turn off the transmit interrupt.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;How do you do something similar with the MPC5643l?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;#define ENABLE_UART_RX_INTERUPT(reg) reg-&amp;gt;LINIER.B.DRIE = 1&lt;BR /&gt;#define ENABLE_UART_TX_INTERUPT(reg) reg-&amp;gt;LINIER.B.DTIE = 1&lt;/P&gt;&lt;P&gt;void UART_enable_rx_irq(UART_channel_t *uart)&lt;BR /&gt;{&lt;BR /&gt;UART_reg_t* reg = uart-&amp;gt;reg;&lt;BR /&gt;uart-&amp;gt;rx.mode = BUFFERED_UART;&lt;BR /&gt;reg-&amp;gt;LINIER.B.DRIE = 1&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void UART_enable_tx_irq(UART_channel_t *uart)&lt;BR /&gt;{&lt;BR /&gt;UART_reg_t* reg = uart-&amp;gt;reg;&lt;BR /&gt;uart-&amp;gt;tx.mode = BUFFERED_UART;&lt;BR /&gt;reg-&amp;gt;LINIER.B.DTIE = 1;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void UART_init(UART_channel_t *uart, uint32_t brs )&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;void UART_init(UART_channel_t* uart, const uint32_t speed) {&lt;BR /&gt;UART_reg_t* reg = uart-&amp;gt;reg;&lt;BR /&gt;uint32_t br;&lt;BR /&gt;ASSERT( reg != 0ul, "Invalid linflex pointer");&lt;/P&gt;&lt;P&gt;/* enter INIT mode */&lt;BR /&gt;reg-&amp;gt;LINCR1.R = 0x0081u; /* SLEEP=0, INIT=1 */&lt;/P&gt;&lt;P&gt;while (0x1000u != (reg-&amp;gt;LINSR.R &amp;amp; 0xf000u)) {&lt;BR /&gt;/* wait for the INIT mode */&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;reg-&amp;gt;UARTCR.B.UART = 1u; /* make the LINflex just be a UART */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.WL0 = 1u; /* 8 bits */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.WL1 = 0u; /* 4 bytes buffer */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.PCE = 0u; /* no parity */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.PC0 = 0u;&lt;BR /&gt;reg-&amp;gt;UARTCR.B.PC1 = 0u; /* no fixed parity */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.TFBM = 1u; /* FIFO mode = 0 for TX */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.RFBM = 1u; /* FIFO mode = 0 for RX */&lt;/P&gt;&lt;P&gt;reg-&amp;gt;UARTCR.B.TDFL_TFC = 4u; /* Number of bytes to transmit = 1 */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.RDFL_RFC0 = 4u; /* Number of bytes to receive = 1 */&lt;/P&gt;&lt;P&gt;br = 120000000u / speed; /* assuming 120 MHz peripheral set 1 ck */&lt;/P&gt;&lt;P&gt;reg-&amp;gt;LINFBRR.R = br &amp;amp; 0xfu; /* fractional baudrate */&lt;BR /&gt;reg-&amp;gt;LINIBRR.R = br &amp;gt;&amp;gt; 4; /* whole baudrate */&lt;/P&gt;&lt;P&gt;reg-&amp;gt;LINIER.R = 0u; /* disable all interrupts */&lt;/P&gt;&lt;P&gt;/* enter NORMAL mode */&lt;BR /&gt;reg-&amp;gt;LINCR1.R = 0x0080u; /* BYPASS_FILTER=1, INIT=0 (this clears any loopback) */&lt;/P&gt;&lt;P&gt;/* these bits work outside of init mode */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.TXEN = 1u; /* TX enabled */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.RXEN = 1u; /* RX enabled */&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;*&lt;BR /&gt;*/&lt;BR /&gt;reg-&amp;gt;LINCR1.R = 0x0081u; /* SLEEP=0, INIT=1 */&lt;/P&gt;&lt;P&gt;while (0x1000u != (reg-&amp;gt;LINSR.R &amp;amp; 0xf000u)) {&lt;BR /&gt;/* wait for the INIT mode to start. */&lt;BR /&gt;}&lt;BR /&gt;reg-&amp;gt;UARTCR.B.RFBM = 4u;&lt;BR /&gt;reg-&amp;gt;UARTCR.B.TFBM = 4u;&lt;BR /&gt;reg-&amp;gt;DMATXE.R = 0u;&lt;/P&gt;&lt;P&gt;reg-&amp;gt;LINCR1.R = 0x0080u; /* Leave INIT mode. */&lt;BR /&gt;TIMER_delay(10);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void UART_rx_interrupt(UART_channel_t *uart)&lt;BR /&gt;{&lt;BR /&gt;UART_reg_t* reg = uart-&amp;gt;reg;&lt;BR /&gt;uint8_t byte;&lt;BR /&gt;uint32_t rx_length;&lt;BR /&gt;uint32_t rx_size;&lt;BR /&gt;uint32_t flags;&lt;/P&gt;&lt;P&gt;byte = (uint8_t)(reg-&amp;gt;RXD &amp;amp; 0x000000FFU); // BDRM.B.DATA4&lt;BR /&gt;flags = reg-&amp;gt;FLAGS;&lt;BR /&gt;flags &amp;amp;= UART_ERRORS;&lt;BR /&gt;reg-&amp;gt;FLAGS = (uint32_t) flags;&lt;/P&gt;&lt;P&gt;rx_length = uart-&amp;gt;rx.length;&lt;BR /&gt;rx_size = uart-&amp;gt;rx.size;&lt;BR /&gt;if (rx_length &amp;lt; rx_size ) { /* We have room for one more char */&lt;BR /&gt;uint32_t *rx_wr_p;&lt;BR /&gt;uint32_t rx_wr;&lt;/P&gt;&lt;P&gt;rx_wr_p = (uint32_t *)&amp;amp;uart-&amp;gt;rx.wr; /* It is not volatile in the IRQ */&lt;BR /&gt;rx_wr = *rx_wr_p;&lt;BR /&gt;uart-&amp;gt;rx.data[rx_wr++] = byte;&lt;BR /&gt;rx_wr &amp;amp;= uart-&amp;gt;rx.mask;&lt;BR /&gt;*rx_wr_p = rx_wr;&lt;/P&gt;&lt;P&gt;uart-&amp;gt;rx.length++;&lt;BR /&gt;} else {&lt;BR /&gt;uart-&amp;gt;rx.dropped++;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (FRAMING_ERROR(flags)) {&lt;BR /&gt;uart-&amp;gt;framing_error++;&lt;BR /&gt;}&lt;BR /&gt;if (OVERRUN_ERROR(flags)) {&lt;BR /&gt;uart-&amp;gt;overrun_error++;&lt;BR /&gt;}&lt;BR /&gt;if (PARITY_ERROR(flags)) {&lt;BR /&gt;uart-&amp;gt;parity_error++;&lt;BR /&gt;}&lt;BR /&gt;uart-&amp;gt;counter++;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* @fn void UART_tx_interrupt(UART_channel_t *uart)&lt;BR /&gt;* @brief UART transmit interrupt routine&lt;BR /&gt;* @retval None&lt;BR /&gt;*/&lt;BR /&gt;void UART_tx_interrupt(UART_channel_t *uart)&lt;BR /&gt;{&lt;BR /&gt;UART_reg_t* reg = uart-&amp;gt;reg;&lt;BR /&gt;uint8_t byte;&lt;BR /&gt;if (uart-&amp;gt;tx.length &amp;gt; 0U) {&lt;BR /&gt;uint32_t *tx_rd_p;&lt;BR /&gt;uint32_t tx_rd;&lt;/P&gt;&lt;P&gt;tx_rd_p = (uint32_t *) &amp;amp;uart-&amp;gt;tx.rd; /* It is not volatile in the IRQ */&lt;BR /&gt;tx_rd = *tx_rd_p;&lt;/P&gt;&lt;P&gt;byte = uart-&amp;gt;tx.data[tx_rd++];&lt;BR /&gt;reg-&amp;gt;TXD = (uint32_t) byte; // BDRL.B.DATA0&lt;/P&gt;&lt;P&gt;tx_rd &amp;amp;= uart-&amp;gt;tx.mask;&lt;BR /&gt;*tx_rd_p = tx_rd;&lt;/P&gt;&lt;P&gt;uart-&amp;gt;tx.length--;&lt;BR /&gt;} else {&lt;BR /&gt;/* Nothing to send */&lt;BR /&gt;CLEAR_TX_INTERRUPT(reg);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;#define UART2_RX_VECTOR (99U)&lt;BR /&gt;#define UART2_TX_VECTOR (100U)&lt;BR /&gt;#define UART2_RX_PRIO (6U)&lt;BR /&gt;#define UART2_TX_PRIO (8U)&lt;BR /&gt;#define UART_RX_ACK (4U)&lt;BR /&gt;#define UART_TX_ACK (2U)&lt;/P&gt;&lt;P&gt;void UART2_rxIrq(void)&lt;BR /&gt;{&lt;BR /&gt;UART_channel_t* uart = uart2;&lt;BR /&gt;uart-&amp;gt;reg-&amp;gt;UARTSR.R = UART_RX_ACK;&lt;BR /&gt;UART_rx_interrupt(uart2);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void UART2_txIrq(void)&lt;BR /&gt;{&lt;BR /&gt;UART_channel_t* uart = uart2;&lt;BR /&gt;uart-&amp;gt;reg-&amp;gt;UARTSR.R = UART_TX_ACK;&lt;BR /&gt;UART_tx_interrupt(uart2);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;main init.&lt;BR /&gt;{&lt;BR /&gt;__disable_interrupt();&lt;BR /&gt;// Init device structure, does not touch UART&lt;BR /&gt;UART_channel_init("UART2", &amp;amp;LINFLEX1, uart2, u2_rx, U2_RX_SIZE, u2_tx, U2_TX_SIZE);&lt;BR /&gt;// H/W reinit&lt;BR /&gt;UART_init(uart2, B875000);&lt;BR /&gt;INTC_InstallINTCInterruptHandler(UART2_rxIrq, UART2_RX_VECTOR,UART2_RX_PRIO);&lt;BR /&gt;INTC_InstallINTCInterruptHandler(UART2_txIrq, UART2_TX_VECTOR,UART2_TX_PRIO);&lt;BR /&gt;INTC.CPR.B.PRI = 0;&lt;BR /&gt;UART_enable_rx_irq(uart2);&lt;BR /&gt;UART_enable_tx_irq(uart2);&lt;BR /&gt;__enable_interrupt();&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2022 07:38:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/MPC5643L-UART-interrupt-handling/m-p/1399028#M20132</guid>
      <dc:creator>emagii</dc:creator>
      <dc:date>2022-01-17T07:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: MPC5643L UART interrupt handling</title>
      <link>https://community.nxp.com/t5/MPC5xxx/MPC5643L-UART-interrupt-handling/m-p/1400047#M20153</link>
      <description>&lt;P&gt;I have managed this to work, by making the following modifications to UART_init.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;reg-&amp;gt;UARTCR.B.TFBM = 0u; /* Buffered mode = 0 for TX */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.RFBM = 0u; /* Buffered mode = 0 for RX */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.TDFL_TFC = 0u; /* Number of bytes to transmit = 1 */&lt;BR /&gt;reg-&amp;gt;UARTCR.B.RDFL_RFC0 = 0u; /* Number of bytes to receive = 1 */&lt;/P&gt;&lt;P&gt;This disables the FIFO which is undesirable in high speed transfers.&lt;/P&gt;&lt;P&gt;Seems to me that the spec of the UART is very strange.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;You do not expect to get receive interrupts without incoming characters.&lt;/LI&gt;&lt;LI&gt;You expect to have an active transmit interrupt if the FIFO is empty.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It seems like the FIFOs are useless in interrupt mode.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What is the expected structure of a UART driver in interrupt mode with FIFO enabled?&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Right now, I am forced to keep track if I am sending or not&lt;BR /&gt;The UART write character function will have to check a "sending" flag.&lt;BR /&gt;The function will place the character in a S/W FIFO.&lt;BR /&gt;If the "sending" flag is not set, the character has to be written to the UART.&lt;BR /&gt;The flag is then set.&lt;/P&gt;&lt;P&gt;The UART send interrupt will read a character from the S/W FIFO.&lt;BR /&gt;If empty, the flag will be cleared.&lt;/P&gt;&lt;P&gt;"Normal" UARTs will assert the TX interrupt if the FIFO is empty.&lt;BR /&gt;The Write character function will just enable the TX interrupt at the end.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;, and if I am sending&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2022 07:51:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/MPC5643L-UART-interrupt-handling/m-p/1400047#M20153</guid>
      <dc:creator>emagii</dc:creator>
      <dc:date>2022-01-17T07:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: MPC5643L UART interrupt handling</title>
      <link>https://community.nxp.com/t5/MPC5xxx/MPC5643L-UART-interrupt-handling/m-p/1400155#M20155</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;RxFIFO and TxFIFO interrupts of LinFlex in UART mode works in the opposite way&amp;nbsp;&lt;BR /&gt;- DRFRFE is set when the Rx FIFO is EMPTY&lt;BR /&gt;- DTFTFF is set when the Tx FIFO is FULL.&lt;BR /&gt;Moreover both&amp;nbsp;DRFRFE and&amp;nbsp;DTFTFF are read only in FIFO mode.&lt;/P&gt;
&lt;P&gt;So I would recommend to use either polling mode or interrupts with buffer mode.&lt;/P&gt;
&lt;P&gt;BR, Petr&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2022 09:03:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/MPC5643L-UART-interrupt-handling/m-p/1400155#M20155</guid>
      <dc:creator>PetrS</dc:creator>
      <dc:date>2022-01-17T09:03:32Z</dc:date>
    </item>
  </channel>
</rss>

