<?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>ColdFire/68K Microcontrollers and ProcessorsのトピックRe: MCF5407 UART interrupt masks seem inverted</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859122#M13653</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MCF5407 is a quite old product, we couldn't debug the code.&lt;/P&gt;&lt;P&gt;While, I find MCF5407 UART driver for your reference.&lt;/P&gt;&lt;P&gt;Wish it helps.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt; Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Mar 2019 05:15:07 GMT</pubDate>
    <dc:creator>Hui_Ma</dc:creator>
    <dc:date>2019-03-15T05:15:07Z</dc:date>
    <item>
      <title>MCF5407 UART interrupt masks seem inverted</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859121#M13652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I am having a lot of trouble configuring the UART on the MCF5407. The only way I was able to make the UART work with the interrupt is to inverse the UIMR bit logic; the datasheet says that we must set TxRDY and FFULL so the interrupts can be asserted but for me, it's the opposite.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I must clear FFULL for Rx, and clear TxRDY when sending and set when software tx fifo is empty.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I copied the problematic code below. To make it work for me, I must inverse ENABLE and DISABLE in the main loop and in HandleUart(void).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I try to transfer this code to the main project, we have interrupt issues. There is something wrong that I can't figure out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help&lt;/P&gt;&lt;PRE&gt;#include "mcf5407.h"
#include "CpuReg.h"
#include "FifoBuffer.hpp"

#define ENABLE TRUE
#define DISABLE FALSE

#define CPU_CLOCK_FREQ_HZ 54000000 // 54 MHz for NGDU

#define VECTOR_TABLE 0x00000000

#define UART0_ICR MCF5407_SIM_ICR4

void Hardware_Init();
void SetSR( UINT32 sr );
UINT32 GetSR();

static unsigned char g_rxBuffer[256];
static FifoBuffer&amp;lt;unsigned char&amp;gt; g_rxFifo(g_rxBuffer, 256);

static unsigned char g_txBuffer[256];
static FifoBuffer&amp;lt;unsigned char&amp;gt; g_txFifo(g_txBuffer, 256);

typedef enum
{
 SERIAL_CMD_NONE = 0x00, // no command - ignored
 SERIAL_CMD_RESET_MRP = 0x01, // reset mode register pointer
 SERIAL_CMD_RX_RESET = 0x02, // reset the receiver
 SERIAL_CMD_TX_RESET = 0x03, // reset the transmitter
 SERIAL_CMD_RST_ERR_STAT = 0x04, // reset the receiver
 SERIAL_CMD_RESET_BCI = 0x05, // reset break change interrupt
 SERIAL_CMD_START_BREAK = 0x06, // start a break
 SERIAL_CMD_STOP_BREAK = 0x07 // stop break
} SERIAL_CMD;

void SendCommand(SERIAL_CMD enCmd)
{
 uint8 cmd = ((UINT8)enCmd &amp;amp; 0x07)&amp;lt;&amp;lt;4;
 CPU_WR(MCF5407_UART0_UCR, cmd);
}

void SetBaudrate()
{
 UINT16 divisor = ROUND32(CPU_CLOCK_FREQ_HZ / 32.0f / 19200 ); // SERIAL_19K2_BAUD

 CPU_WR(MCF5407_UART0_UCSR, 0xDD); // Use prescaled CLKIN for tx/rx
 CPU_WR(MCF5407_UART0_UBG2, (UINT8)divisor); // Lower byte of divisor
 CPU_WR(MCF5407_UART0_UBG1, (UINT8)(divisor &amp;gt;&amp;gt; 8)); // Upper byte of the divisor
}

void Transmitter(BOOL bEnable)
{
 UINT8 bitCode = bEnable ? (0x01 &amp;lt;&amp;lt; 2) : (0x02 &amp;lt;&amp;lt; 2);
 CPU_WR(MCF5407_UART0_UCR, bitCode);
}

void Receiver(BOOL bEnable)
{
 UINT8 bitCode = bEnable ? 0x01 : 0x02;
 CPU_WR(MCF5407_UART0_UCR, bitCode);
}

void ReceiverInterrupts(BOOL bEnable)
{
 volatile UINT8 status = CPU_RD(MCF5407_UART0_UIMR);
 if (bEnable) {
 status |= MCF5407_UART_UIMR_FFULL; // Enable
 } else {
 status &amp;amp;= ~MCF5407_UART_UIMR_FFULL; // Disable
 }
 CPU_WR(MCF5407_UART0_UIMR, status);
}

void TransmitterInterrupts(BOOL bEnable)
{
 volatile UINT8 status = CPU_RD(MCF5407_UART0_UIMR);
 if (bEnable) {
 status |= MCF5407_UART_UIMR_TXRDY; // Enable
 } else {
 status &amp;amp;= ~MCF5407_UART_UIMR_TXRDY; // Disable
 }

 CPU_WR(MCF5407_UART0_UIMR, status);
}

void SetInterruptMask(BOOL bSet)
{
 UINT32 mask = CPU_RD32(MCF5407_SIM_IMR);
 if (bSet) {
 mask |= MCF5407_SIM_IMR_UART0;
 } else {
 mask &amp;amp;= ~MCF5407_SIM_IMR_UART0;
 }
 CPU_WR32(MCF5407_SIM_IMR, mask);
}

#define ANY_UART_ERRORS (MCF5407_UART_USR_RB | \
 MCF5407_UART_USR_FE | \
 MCF5407_UART_USR_PE | \
 MCF5407_UART_USR_OE)

void HandleUart(void)
{
 int maxRead = 4;

 volatile uint8 uisr = CPU_RD(MCF5407_UART0_UISR);
 // RX INTERRUPT
 if (uisr &amp;amp; (MCF5407_UART_UIMR_FFULL))
 {
 volatile uint8 usr = CPU_RD(MCF5407_UART0_USR);
 //while FIFO is not empty?
 while (usr &amp;amp; (MCF5407_UART_USR_RXRDY) &amp;amp;&amp;amp; (maxRead--) &amp;gt; 0)
 { 
 if (usr &amp;amp; ANY_UART_ERRORS)
 {
 SendCommand(SERIAL_CMD_RST_ERR_STAT);
 }
 g_rxFifo.Insert(CPU_RD(MCF5407_UART0_URB));
 usr = CPU_RD(MCF5407_UART0_USR);
 }
 }

 // TX INTERRUPT
 if (uisr &amp;amp; (MCF5407_UART_UIMR_TXRDY))
 {
 if (g_txFifo.GetCurrentLength() &amp;gt; 0)
 {
 volatile UINT8 usr = CPU_RD(MCF5407_UART0_USR);
 // determine if this buffer descriptor is ready to be loaded 
 if (usr &amp;amp; MCF5407_UART_USR_TXRDY) { // TX Ready Bit Set
 UINT8 byte = g_txFifo.Extract();
 CPU_WR(MCF5407_UART0_UTB, byte);
 }
 }

 }

 if (g_txFifo.IsEmpty())
 {
 TransmitterInterrupts(DISABLE);
 }
}

__declspec( interrupt ) void UartIntHandler(void)
{
 HandleUart();
}

void InstallHandler()
{
 UINT32 *vt = (UINT32 *)(VECTOR_TABLE);
 // Autovector isr 1-7 --&amp;gt; vector number 25-31 (UINT32)
 // isr level 6 == vector 30
 vt[ 30 ] = (UINT32)UartIntHandler;
}

void InitUart()
{
 Receiver(DISABLE);
 Transmitter(DISABLE);
 
 ReceiverInterrupts(DISABLE);
 
 SetInterruptMask(TRUE);
 
 InstallHandler();

 SendCommand(SERIAL_CMD_RX_RESET);
 SendCommand(SERIAL_CMD_TX_RESET);
 
 SendCommand(SERIAL_CMD_RESET_MRP);
 
 CPU_WR(MCF5407_UART0_UACR, 0);
 
 SetBaudrate();

 volatile UINT8 mrp1 = (0x0 &amp;lt;&amp;lt; 7) | (0x0 &amp;lt;&amp;lt; 6) | (0x1 &amp;lt;&amp;lt; 5) | (0x4 &amp;lt;&amp;lt; 2) | (0x3 &amp;lt;&amp;lt; 0);
 volatile UINT8 mrp2 = (0x0 &amp;lt;&amp;lt; 6) | (0x0 &amp;lt;&amp;lt; 5) | (0x0 &amp;lt;&amp;lt; 4) | (0x7 &amp;lt;&amp;lt; 0);
 
 CPU_WR(MCF5407_UART0_UMR, mrp1);
 CPU_WR(MCF5407_UART0_UMR, mrp2);
 
 SendCommand(SERIAL_CMD_RST_ERR_STAT); //reset error status
 SendCommand(SERIAL_CMD_RESET_BCI); //reset break-change interrupt

 UINT8 intLevel = 6;
 UINT8 intPrio = 3;
 UINT8 icrValue = (MCF5407_SIM_ICR_AVEC) | MCF5407_SIM_ICR_IL(intLevel) | (intPrio);
 // Set up the interrupt level and priority
 CPU_WR( UART0_ICR, icrValue );

 SetInterruptMask(FALSE);

 ReceiverInterrupts(ENABLE);
 TransmitterInterrupts(DISABLE);
 
 Receiver(ENABLE);
 Transmitter(ENABLE);
}

int main()
{
 Hardware_Init();
 InitUart();
 
 ReceiverInterrupts(ENABLE);

 while (1)
 {
 if (g_rxFifo.GetCurrentLength() &amp;gt; 0)
 {
 while (!g_rxFifo.IsEmpty() &amp;amp;&amp;amp; g_txFifo.GetFree() &amp;gt;= 1)
 {
 g_txFifo.Insert(g_rxFifo.Extract());
 }
 TransmitterInterrupts(ENABLE);
 }
 }

 return 0;
}

void Hardware_Init()
{
 //-------------------------------------------------------------------------
 // Out of reset, only level 7 interrupts are enabled. Enable down to
 // level 3 interrupts (Timer and UART interrupts are enabled)
 //-------------------------------------------------------------------------
 SetSR( 0x2200 );

}

/*-----------------------------------------------------------------------------
| Title: Set CPU Status Register (SR) Value
\*---------------------------------------------------------------------------*/
void SetSR( UINT32 sr )
{
asm {
 move.w d0,sr
 nop
 }
}


/*-----------------------------------------------------------------------------
| Title: Get CPU Status Register (SR) Value
\*---------------------------------------------------------------------------*/
UINT32 GetSR()
{
asm {
 move.w sr,d0
 nop
 }
}

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2019 21:30:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859121#M13652</guid>
      <dc:creator>jbolduc</dc:creator>
      <dc:date>2019-03-14T21:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: MCF5407 UART interrupt masks seem inverted</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859122#M13653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MCF5407 is a quite old product, we couldn't debug the code.&lt;/P&gt;&lt;P&gt;While, I find MCF5407 UART driver for your reference.&lt;/P&gt;&lt;P&gt;Wish it helps.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt; Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2019 05:15:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859122#M13653</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2019-03-15T05:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: MCF5407 UART interrupt masks seem inverted</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859123#M13654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the answer. Unfortunately this driver doesn't use the interrupts, but I still managed to find my problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The UART interrupt mask register &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;MCF5407_UART0_UIMR&lt;/SPAN&gt; and the UART interrupt pending register&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;MCF5407_UART0_UISR&lt;/SPAN&gt; share the exact same address. The read operation returns UISR, not UIMR. So we &lt;STRONG&gt;cannot&lt;/STRONG&gt; do this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;void EnableTxInt()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;unsigned char uimr = CPU_RD(MCF5407_UART0_UIMR); // WRONG !!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;uimr |=&amp;nbsp;MCF5407_UART_UIMR_TXRDY; // ENABLE TX INTERRUPT&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CPU_WR(MCF5407_UART0_UIMR, uimr);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We &lt;STRONG&gt;should&lt;/STRONG&gt; do this instead :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;unsigned char g_uimr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// Initialize g_uimr somewhere...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;void EnableTxInt()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;g_uimr |=&amp;nbsp;MCF5407_UART_UIMR_TXRDY; // ENABLE TX INTERRUPT&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CPU_WR(MCF5407_UART0_UIMR, g_uimr);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it may help someone else.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Mar 2019 18:36:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859123#M13654</guid>
      <dc:creator>jbolduc</dc:creator>
      <dc:date>2019-03-19T18:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: MCF5407 UART interrupt masks seem inverted</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859124#M13655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the info.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;best regards,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 01:46:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859124#M13655</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2019-03-20T01:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: MCF5407 UART interrupt masks seem inverted</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859125#M13656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There should be some linux serial drivers for this hardware. Google might be able to find you some sources. They certainly aren't in the current distributions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found references to there being sources in the ucLinux sources here (reference, not the sources) under "Interrupt-based driver for Wacom Artpad":&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://acp.atari.org/articles/mcf5407eval/mcf5407eval.html#Modifications%20of%20the%20Linux%20driver" title="http://acp.atari.org/articles/mcf5407eval/mcf5407eval.html#Modifications%20of%20the%20Linux%20driver"&gt;My life with the MCF5407 Coldfire Board \\ (draft)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There might be something in here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://en.verysource.com/item/dbug_rar-152755.html" title="http://en.verysource.com/item/dbug_rar-152755.html"&gt;http://en.verysource.com/item/dbug_rar-152755.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2019 05:48:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF5407-UART-interrupt-masks-seem-inverted/m-p/859125#M13656</guid>
      <dc:creator>TomE</dc:creator>
      <dc:date>2019-03-20T05:48:37Z</dc:date>
    </item>
  </channel>
</rss>

