UART Rx latency issue imx7d Linux

Hi Experts,
I am getting ~3ms delay when I receive data (15 bytes or less) from UART in imx7d Linux. I am using kernel 3.0
Did lot of debugging, scope capture and I see data comes from outside is good & continuous without delay, but both poll or pselect waits for some timeout to give that data to application.
Could you please help me on this? I want to receive byte as soon as it arrives on UART RX.

Thank you

Could you please help me on this

Please let me know if you need any more details.

HI @neeraj.verma

Thanks for writing to the Toradex Community!

Could you provide the exact version of the software of your module?

I am getting ~3ms delay when I receive data (15 bytes or less) from UART in imx7d Linux

How did you measure this? What is your communication speed?
Could you provide some code sample?

Best regards,

Hi @jaski.tx

cat /proc/version
Linux version 4.14.170-3.0.4+gbaa6c24240a4 (oe-user@oe-host) (gcc version 8.2.0 (GCC))

measurement is done through oscilloscope triggering from first byte to 8 bytes, and measure total time on oscilloscope and then receive data into code by adding printf using time.
Receiving 1 byte or 16 bytes takes same time either just polling using read() or pselect.
pselect(max_fds + 1, &read_fd, NULL, NULL, NULL, NULL);
len = read(fd, buf, UART_DATA_LEN);

value of len is not 1 byte. it’s always 16 bytes or there is delay to receive 16 bytes even when it’s just 1 byte.

I want to receive 1 byte at a time and read shouldn’t wait for more bytes.

Baud is: 115200

Thank you

Could you share your code?

Hi @alex.tx
I thought I shared two important lines of code which I use is good enough. my source code is huge and private.

1. Init uart with 115200
2. in another thread 
    >pselect(max_fds + 1, &read_fd, NULL, NULL, NULL, NULL);
    >len = read(fd, buf, UART_DATA_LEN);

read() waits for 16 bytes or timeouts.
when I receive 1 byte, suppose read takes 1ms
when I receive 16 bytes, read takes 1ms too.

Please let me know if you need any other details to help me on this.

Thank you

Sorry, but I can’t compile you code to verify problem you reporting. Please share minimal but compilable code.

Hi @alex.tx ,
Sorry for confusion, I thought you can just suggest by explaining my issue.
Attaching source code to get compiled/run on imx7d 1GB eMMC.

If you have some way sending data to UART_B, you can send 1,2, 16 and bytes and see how much time read takes to print/ text

Thank you

Hi @alex.tx ,
Could you please suggest me your findings? or let me know if you need more details.

Thank you

@alex.tx I deadly need this fix… could you please help me on this?

Could anyone please reply on this? let me know if more details is needed.

Hi @jaski.tx ,
Could you please suggest me?

Hi @neeraj.verma , have you try to disable DMA of UART2 at imx7-colibri-eval-v3.dtsi?

&uart2 {
	status = "okay";
	dma-names = "", "";

Hi @benjamin.tx I added dma-names = “”, “”; but no luck. Thank you.

At your code you have

    len = read(fd, buf, UART_DATA_LEN);

Have you tried to read smaller amount of data?

Hi @neeraj.verma , do you successfully apply the device tree without DMA on uart2? The default one is imx7d-colibri-emmc-eval-v3.dtb. After you copy the device tree, you’d better to run sync to really flash it to eMMC. I do the same test and here is the code. SODIMM77 will be pulled low when bytes are read. 2 bytes of data are sent to ttymxc1. The yellow line is rxd of ttymxc1, the blue line is SODIMM77. The latency from last bit on rxd to the time when SODIMM77 is pulled low is 850us.

Set CPU to the highest clock.

echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Hi @benjamin.tx
Thank you for the details, let me refer your code and see if I am missing something (uart settings), I see two things, I am checking with my project code and I didn’t set cpu clock.
Let me try and update you.
Thank you so much for your help.

Thank you

You are welcome. Please provide us an update once you got results. Thanks.