AnsweredAssumed Answered

IMX6 RS485 with 9th bit: how to change via termios

Question asked by Rick Veens on Aug 8, 2018

Hi,

 

I have RS485 working and i need to add the functionality to change the 9th bit (TXB8 of UMCR).

 

 

I have implemented a boolean in the drivers/tty/serial/imx.c that is set by parodd or ~parodd termios option.

 

I was wondering what should be the correct location to set TXB8 of UMCR. Currently i have added the following to the  imx_start_tx function:

 

unsigned long umcr = 0;

umcr |= UMCR_MDEN;
if(sport->nine_bit_high)
{
umcr |= UMCR_TXB8_HIGH;
}
writel(umcr, sport->port.membase + UMCR);

 

Where nine_bit_high is set via termios.

 

This seems to work, under some conditions.

In userspace i am required to call the sleep() function after writing some bytes, before changing the 9th bit again:

 

       unsigned char buf[10] = {0};

buf[0] = 0x02; //board id
buf[1] = 0x07; //control
buf[2] = 0x0; //request id
buf[3] = 0x01; //request id
buf[4] = 0x0; //datalen
buf[5] = 0x0; //datalen
buf[6] = 0x01; //xor

 

set9bit(true);
write_uart(buf, 1); //Send address

 

sleep(1); // this is required or else a problem

 

set9bit(false);
write_uart(buf+1, 6);

 

When looking at the first byte being sent (buf[0], 0x02) on scope i see the following when i do not include the sleep:

When running once again:

So it seems to be some kind of race condition, the data is always different.

 

 

When i do enable the sleep(1) function i always get the following (correct) result:

 

 

I was hoping to find someone here who has knowledge of how to debug this or what the possible problem could be.

The work-around i have found currently with the sleep function is not preferred as it required changes in user-space.

 

We are in the process of upgrading the BSP from 3.10.17 to 4.9.11. In the old version this sleep was not required and we made the same changes to the code in imx_start_tx.

 

I have seen the thread Some experiences with iMX.6 9-bit UART mode  where it is suggested there can be issues with transmitting but this did not offer me a solution.

 

Best regards,

 

Rick

Outcomes