Buggy USB connexion on rpi4

Hi all,
I work on project that needs a rpi4 to communicate with a measurement device over USB. Everything is working well except sometimes when I download “a lot” of data the device doesn’t respond anymore and I can’t reconnect to it until I unplug and replug. I use pyserial and there are no error reported, neither from dmesg, or pyserial. There’s just nothing! The same code is working well on my laptop.

The code:

    def CmdDownloadSectorData(self, numSector, keepPortOpen = False):
        if self.CmdDownloadSector(numSector, True) is False:
            return False

        retry = 0
        buf = bytearray([])

            while len(buf) < self.SectorSize and retry < 10:
                while self.SerialPort.in_waiting <= 0 and retry < 10:
                    retry = retry + 1
                    # afer a while , there's just nothing in_waiting and I can't reach the device anymore
                    buf = bytearray(self.SerialPort.read(self.SectorSize - len(buf)))
                except serial.SerialException:
                    return False
                except serial.SerialTimeoutException:
                    retry = retry + 1
        except OSError:
            return False

        if not keepPortOpen:
            print("Serial Port is being closed !")

        if len(buf) != self.SectorSize:
            return False
        return bytes(buf)

This function is called on every 256 sectors of the device. It’s randomly stuck at a sector, once it even succeeded!

The RPi runs Manjaro KDE ARM and my laptop Manjaro KDE.
I updated the rpi eeprom to the latest and pacman -Syu.

[pi@raspberrypi ~]$ sudo rpi-eeprom-update
[sudo] password for pi: 
BOOTLOADER: up to date
   CURRENT: Thu Apr 29 04:11:25 PM UTC 2021 (1619712685)
    LATEST: Thu Apr 29 04:11:25 PM UTC 2021 (1619712685)
   RELEASE: critical (/lib/firmware/raspberrypi/bootloader/critical)
            Use raspi-config to change the release.

  VL805_FW: Dedicated VL805 EEPROM
     VL805: up to date
   CURRENT: 000138a1
    LATEST: 000138a1

Dmesg with the device connected, the bug occured then I unplugged the device.


# See /boot/overlays/README for all available options

initramfs initramfs-linux.img followkernel

#enable sound

#enable vc4



root=PARTUUID=2a586bd1-02 rw rootwait selinux=0 quiet splash plymouth.ignore-serial-consoles smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 elevator=noop usbhid.mousepoll=8 snd-bcm2835.enable_compat_alsa=0 audit=0 dwc_otg.speed=1

I’ve tried to change some kernel parameters etc but nothing helps…
Thank you for your help! Cheers

I was using wireless keyboard/mouse on rpi4 that was unreliable. Moving the wifi dongle away from the unit with a usb extension cable helped a lot, but still had to unplug/replug on occasion.EMI maybe? Now using hardwired keyboard/mouse without issue. rpi4 would not support an SSD directly off usb. Bought a hub that powers the SSD, problem solved. Definitely a power draw issue. Perhaps you are dealing with a hardware issue. btw, no errors for keyboard/mouse issue; just stopped communicating.

It looks like it is related to this xhci: Regression for cdc_acm device (bisected) · Issue #4061 · raspberrypi/linux · GitHub

1 Like