<?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>i.MX Processorsのトピックi.MX7D RS485 problems</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1923848#M226946</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to get RS485 running on our custom i.MX7D based board.&lt;/P&gt;&lt;P&gt;I can write some data to RS485 correctly, but when any data is received, there are some random data automatically generated to the line probably by imx.c driver. I have tried to interconnect 2 RS485 lines, open them from C++ code and just write few bytes to one of them and it results in endless pinging of random data on the line.&lt;/P&gt;&lt;P&gt;Both RS485 are working in half-duplex mode with SN65HVD1780 chip, direction control using RTS as GPIO.&lt;/P&gt;&lt;P&gt;Devicetree (UARTS are aliased to ports 2,3):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;amp;uart4 {
	pinctrl-names = "default";
	pinctrl-0 = &amp;lt;&amp;amp;pinctrl_uart4&amp;gt;;
	assigned-clocks = &amp;lt;&amp;amp;clks IMX7D_UART4_ROOT_SRC&amp;gt;;
	assigned-clock-parents = &amp;lt;&amp;amp;clks IMX7D_OSC_24M_CLK&amp;gt;;
	
	rts-gpios = &amp;lt;&amp;amp;gpio3 21 GPIO_ACTIVE_HIGH&amp;gt;; //DIR control
	linux,rs485-enabled-at-boot-time;
	rs485-rts-delay = &amp;lt;1 1&amp;gt;;		// in milliseconds
	status = "okay";
};

&amp;amp;uart6 {
	pinctrl-names = "default";
	pinctrl-0 = &amp;lt;&amp;amp;pinctrl_uart6&amp;gt;;
	assigned-clocks = &amp;lt;&amp;amp;clks IMX7D_UART6_ROOT_SRC&amp;gt;;
	assigned-clock-parents = &amp;lt;&amp;amp;clks IMX7D_OSC_24M_CLK&amp;gt;;
	
	rts-gpios = &amp;lt;&amp;amp;gpio3 22 GPIO_ACTIVE_HIGH&amp;gt;; //DIR control
	linux,rs485-enabled-at-boot-time;
	rs485-rts-delay = &amp;lt;0 1&amp;gt;;		// in milliseconds
	status = "okay";
};&lt;/LI-CODE&gt;&lt;P&gt;Part of testing code:&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;bool InitRS485(int fd)
{
	struct serial_rs485 rs485conf;
	rs485conf.flags |= SER_RS485_ENABLED; //Enable RS485 mode
	rs485conf.flags |= SER_RS485_RTS_ON_SEND; //Set logical level for RTS pin equal to 1 when sending
	rs485conf.flags &amp;amp;= ~(SER_RS485_RTS_AFTER_SEND); //Set logical level for RTS pin equal to 0 after sending
	rs485conf.delay_rts_before_send = 1; //Set rts delay before send
	rs485conf.delay_rts_after_send = 1; //Set rts delay after send
	if(ioctl(fd, TIOCSRS485, (void*)&amp;amp;rs485conf) == 0)
	{
		struct termios tty; //Get current settings
		if(tcgetattr(fd, &amp;amp;tty) == 0)
		{
			tty.c_cflag &amp;amp;= ~PARENB;		//No Parity
			tty.c_cflag &amp;amp;= ~CSTOPB;		//1 Stop Bit
			tty.c_cflag &amp;amp;= ~CSIZE;
			tty.c_cflag |= CS8;			//8 Bits
			cfsetspeed(&amp;amp;tty, 19200); //Set baudrate
			if(tcsetattr(fd, TCSANOW, &amp;amp;tty) == 0) //Set settings to port
			{
				return true;
			}	
		}		
	}
	return false;
}

void rs485TaskTest1()
{
	int fd = open("/dev/ttymxc2", O_RDWR);
	if (InitRS485(fd))
	{
		const uint8_t data[] = { 0x11, 0x01, 0x02, 0x32, 0x00};
		write(fd, data, sizeof(data));
	}
	close(fd);
}

void rs485TaskTest2()
{
	int fd = open("/dev/ttymxc3", O_RDWR);
	if (InitRS485(fd))
	{
		while (1)
		{
			std::this_thread::sleep_for(100ms);
		}	
	}
	close(fd);
}&lt;/LI-CODE&gt;&lt;P&gt;As you can see, I'm writing on first RS485 and just opening port on second with sleeping.&lt;/P&gt;&lt;P&gt;Result caught on analyzer (1 - DIR, 2 - RX, 3 -TX):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/291658i2BBEAD83E925A3D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/291659i2FE73AAAE8C42F51/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see, there is also problem, that on first transition with normal data, RTS delay before send (delay_rts_before_send) is not applied. On randomly generated transitions it is applied correctly.&lt;/P&gt;&lt;P&gt;Any ideas, what am I doing wrong, or I have hit some kind of bug?&lt;/P&gt;&lt;P&gt;I'm running kernel version 5.15.52. I have tried to backport changes in imx.c from 6.x kernel, but with same results.&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Michal Špánik&lt;/P&gt;</description>
    <pubDate>Fri, 02 Aug 2024 09:04:20 GMT</pubDate>
    <dc:creator>mischo5500</dc:creator>
    <dc:date>2024-08-02T09:04:20Z</dc:date>
    <item>
      <title>i.MX7D RS485 problems</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1923848#M226946</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to get RS485 running on our custom i.MX7D based board.&lt;/P&gt;&lt;P&gt;I can write some data to RS485 correctly, but when any data is received, there are some random data automatically generated to the line probably by imx.c driver. I have tried to interconnect 2 RS485 lines, open them from C++ code and just write few bytes to one of them and it results in endless pinging of random data on the line.&lt;/P&gt;&lt;P&gt;Both RS485 are working in half-duplex mode with SN65HVD1780 chip, direction control using RTS as GPIO.&lt;/P&gt;&lt;P&gt;Devicetree (UARTS are aliased to ports 2,3):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;amp;uart4 {
	pinctrl-names = "default";
	pinctrl-0 = &amp;lt;&amp;amp;pinctrl_uart4&amp;gt;;
	assigned-clocks = &amp;lt;&amp;amp;clks IMX7D_UART4_ROOT_SRC&amp;gt;;
	assigned-clock-parents = &amp;lt;&amp;amp;clks IMX7D_OSC_24M_CLK&amp;gt;;
	
	rts-gpios = &amp;lt;&amp;amp;gpio3 21 GPIO_ACTIVE_HIGH&amp;gt;; //DIR control
	linux,rs485-enabled-at-boot-time;
	rs485-rts-delay = &amp;lt;1 1&amp;gt;;		// in milliseconds
	status = "okay";
};

&amp;amp;uart6 {
	pinctrl-names = "default";
	pinctrl-0 = &amp;lt;&amp;amp;pinctrl_uart6&amp;gt;;
	assigned-clocks = &amp;lt;&amp;amp;clks IMX7D_UART6_ROOT_SRC&amp;gt;;
	assigned-clock-parents = &amp;lt;&amp;amp;clks IMX7D_OSC_24M_CLK&amp;gt;;
	
	rts-gpios = &amp;lt;&amp;amp;gpio3 22 GPIO_ACTIVE_HIGH&amp;gt;; //DIR control
	linux,rs485-enabled-at-boot-time;
	rs485-rts-delay = &amp;lt;0 1&amp;gt;;		// in milliseconds
	status = "okay";
};&lt;/LI-CODE&gt;&lt;P&gt;Part of testing code:&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;bool InitRS485(int fd)
{
	struct serial_rs485 rs485conf;
	rs485conf.flags |= SER_RS485_ENABLED; //Enable RS485 mode
	rs485conf.flags |= SER_RS485_RTS_ON_SEND; //Set logical level for RTS pin equal to 1 when sending
	rs485conf.flags &amp;amp;= ~(SER_RS485_RTS_AFTER_SEND); //Set logical level for RTS pin equal to 0 after sending
	rs485conf.delay_rts_before_send = 1; //Set rts delay before send
	rs485conf.delay_rts_after_send = 1; //Set rts delay after send
	if(ioctl(fd, TIOCSRS485, (void*)&amp;amp;rs485conf) == 0)
	{
		struct termios tty; //Get current settings
		if(tcgetattr(fd, &amp;amp;tty) == 0)
		{
			tty.c_cflag &amp;amp;= ~PARENB;		//No Parity
			tty.c_cflag &amp;amp;= ~CSTOPB;		//1 Stop Bit
			tty.c_cflag &amp;amp;= ~CSIZE;
			tty.c_cflag |= CS8;			//8 Bits
			cfsetspeed(&amp;amp;tty, 19200); //Set baudrate
			if(tcsetattr(fd, TCSANOW, &amp;amp;tty) == 0) //Set settings to port
			{
				return true;
			}	
		}		
	}
	return false;
}

void rs485TaskTest1()
{
	int fd = open("/dev/ttymxc2", O_RDWR);
	if (InitRS485(fd))
	{
		const uint8_t data[] = { 0x11, 0x01, 0x02, 0x32, 0x00};
		write(fd, data, sizeof(data));
	}
	close(fd);
}

void rs485TaskTest2()
{
	int fd = open("/dev/ttymxc3", O_RDWR);
	if (InitRS485(fd))
	{
		while (1)
		{
			std::this_thread::sleep_for(100ms);
		}	
	}
	close(fd);
}&lt;/LI-CODE&gt;&lt;P&gt;As you can see, I'm writing on first RS485 and just opening port on second with sleeping.&lt;/P&gt;&lt;P&gt;Result caught on analyzer (1 - DIR, 2 - RX, 3 -TX):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/291658i2BBEAD83E925A3D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/291659i2FE73AAAE8C42F51/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see, there is also problem, that on first transition with normal data, RTS delay before send (delay_rts_before_send) is not applied. On randomly generated transitions it is applied correctly.&lt;/P&gt;&lt;P&gt;Any ideas, what am I doing wrong, or I have hit some kind of bug?&lt;/P&gt;&lt;P&gt;I'm running kernel version 5.15.52. I have tried to backport changes in imx.c from 6.x kernel, but with same results.&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Michal Špánik&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 09:04:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1923848#M226946</guid>
      <dc:creator>mischo5500</dc:creator>
      <dc:date>2024-08-02T09:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: i.MX7D RS485 problems</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1924080#M226954</link>
      <description>&lt;P&gt;To simplify the usecase, this happens, when I&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;echo "12345" &amp;gt; /dev/ttymxc3&lt;/LI-CODE&gt;&lt;P&gt;with interconnected port 2 and 3 (port 2 is with connected analyzer)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/291739i95D81F9F7A2ABFFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It seems OK. But when I run&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;cat /dev/ttymxc2&lt;/LI-CODE&gt;&lt;P&gt;and&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;echo "12345" &amp;gt; /dev/ttymxc3&lt;/LI-CODE&gt;&lt;P&gt;which opens the receiving port (but does not process data in any way), it looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/291741i49E5A64B9892CFD7/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It seems, that data is automatically echoed back to transmit after receive (even with correct RTS).&lt;/P&gt;&lt;P&gt;If I disable DMA, First byte is echoed immediately and rest of data is cut (because of direction change).&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 14:16:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1924080#M226954</guid>
      <dc:creator>mischo5500</dc:creator>
      <dc:date>2024-08-02T14:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: i.MX7D RS485 problems</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1927719#M227109</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Have you tried usin latest kernel instead of backporting?&lt;BR /&gt;Also, you may try using test code we have available under unit_test:&lt;BR /&gt;&lt;A href="https://github.com/nxp-imx/imx-test/blob/lf-6.6.3_1.0.0/test/mxc_mcc_tty_test/mxc_mcc_tty_test.c" target="_blank"&gt;https://github.com/nxp-imx/imx-test/blob/lf-6.6.3_1.0.0/test/mxc_mcc_tty_test/mxc_mcc_tty_test.c&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://github.com/nxp-imx/imx-test/blob/lf-6.6.3_1.0.0/test/mxc_uart_test/mxc_uart_test.c" target="_blank"&gt;https://github.com/nxp-imx/imx-test/blob/lf-6.6.3_1.0.0/test/mxc_uart_test/mxc_uart_test.c&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Best regards/Saludos,&lt;BR /&gt;Aldo.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 21:21:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1927719#M227109</guid>
      <dc:creator>AldoG</dc:creator>
      <dc:date>2024-08-07T21:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: i.MX7D RS485 problems</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1928296#M227142</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I found call to&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;cfmakeraw()&lt;/LI-CODE&gt;&lt;P&gt;in second test code, which seems to solve the issue. It was caused by ISIG flag, which is set by default and probably triggers on transferred data in our protocol/my test scenario.&lt;/P&gt;&lt;P&gt;Thank you very much for your support,&lt;/P&gt;&lt;P&gt;Michal Špánik&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2024 13:24:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX7D-RS485-problems/m-p/1928296#M227142</guid>
      <dc:creator>mischo5500</dc:creator>
      <dc:date>2024-08-08T13:24:05Z</dc:date>
    </item>
  </channel>
</rss>

