USB-Serial Reading frequency goes wrong every 2 minutes

Hi,

I have a TX1 (R24.2.1) with ASG003, and I want to use Range Sensor named ‘SF11
( Product manual : https://acroname.com/sites/default/files/assets/sf11_-laser_altimeter_manual-_rev_6.pdf )

That sensor can communicate with UART serial.

So I connected range sensor with ‘CP210x uart to usb converter’. I built the cp210x driver with reference to http://elinux.org/Jetson/Tutorials/Program_An_Arduino#FTDI_kernel_module.

SF11 range sensor sends encoded ASCII characters which meaning range information (7byte) every 0.05sec (20Hz) through serial communication.

The serial setting is : baud 115200, no parity, 8 data bits, 1 stop bits, no handshaking.

And this is the test code made with Python 3. Recording the time when data has received.

import serial
import time

class RANGE():
		adr='/dev/ttyUSB0'
		self.ser = serial.Serial(adr, 115200)
		self.data=None
		
	def processdata(self):
		
		readbyte=self.ser.inWaiting()
		if readbyte>0:                                                    #When data received
			self.data=str(time.time())+self.ser.readline().decode()   #Time tagging on data
			
		else:
			self.data=None	

if __name__ == '__main__' :

	RANGE=RANGE()
	f = open('sf11.txt', 'w')
	print("Laser Range Finder DAQ Start")
	d=[]

	try:
		while True:
			RANGE.processdata()

			#do something
			
			if RANGE.data:
				d.append(RANGE.data)   #Storing data
				
	except KeyboardInterrupt:
		for i in range(len(d)):                #Saving data before exiting script
			f.write(d[i])
		RANGE.ser.close()
		f.close()

And this is the plot of the Reading frequency. Calculated with 1/(current timetag - previous timetag). Testing time is 800s.

Most of the values stay near 20Hz, but you can see these 4 lines down to 10Hz. The spacing between each line is exactly 120 seconds. This happens not always, but often.

I tested the same code on Windows and Linux Desktop, but this issue happens only on TX1.

And the similar problems also come up not only cp210x but FTDI serial converter.

So I think that every reading performance drops every 2 minutes.

To solve this problem, what should I check? Have any similar symptoms been reported?

Thanks in advance.

I cannot explain why, but some problems with USB serial communication have disappeared after disabling usbcore autosuspend at boot time. For doing so, add this line to file /boot/extlinux/extlinux.conf :

usbcore.autosuspend=-1

and reboot.

You might also make sure performance is maximized, try “sudo /home/ubuntu/jetson-clocks.sh” (use --show option before and after if you want to see what changes).

@Honey_Patouceul

Thanks for reply, but I have already tried that with reference to this :
[url]https://devtalk.nvidia.com/default/topic/1003756/jetson-tx1/usb-serial-communication-problem-with-novatel-gps-on-tx1/2[/url]

However, whether usbcore autosuspend is working or not, the result is same.


@linuxdev

Thank you for your help, but it does not seem to be related to cpu performance.

The result is also same when the performance is maximized.

Thanks you all for your help.

My guess (and it is only conjecture) is that during a spike CPU0 is servicing another hardware driver (thus starving the measured device). One example might be that gigabit networking or hard drive are processing. What other devices are connected (testing results after disconnecting WiFi, ethernet, and USB devices which might be useful…I wouldn’t expect a keyboard or mouse to be significant, but anything like hard drive or even an active WiFi should be removed and/or disabled while testing)?

Note: If you have a specific PID you might want to also test renicing to a higher priority (default user priority is 0, a renice to -2 would give the process significant advantage over almost any other non-critical process). If you have a custom driver of your own running it might be rearranged or changed to play nicer with other hardware drivers (e.g., dividing it into a hardware IRQ top half and software IRQ bottom half)…but I suspect you aren’t writing your own driver since you are just using USB.

Please check if there is any difference in ‘cat /sys/kernel/debug/clock/clock_tree’ when the issue happens.

Useful command:

sudo watch -n 1 cat /sys/kernel/debug/clock/clock_tree