Skip to content

Pi Zero 2W Freezes after about 30 seconds #134

Description

@chazzawalla

I'm cross-posting this from the home_assistant_streamdeck_yaml git, which is the python script I'm running when this happens - but it looks like the issue might be related to the LibUSBHIDAPI code so thought it might be more relevant to the folks over here

Hi all, I went through two identical installs over the last week - first on an RPi 4 (works flawlessly), then on a Pi Zero 2 W so I can get that smaller footprint.

The problem is on the Pi Zero, it'll work great at first but after +/- 30 seconds the Streamdeck freezes up.

Sometimes I get some code in terminal, sometimes not. Here's what I saw last time:

[13:10:54] Updating key 7 for             home_assistant_streamdeck_yaml.py:1130
           light.kitchen_hue_zone_pendant
Traceback (most recent call last):
  File "/home/<username>/home-assistant-streamdeck-yaml/home_assistant_streamdeck_yaml.py", line 1943, in <module>
    main()
  File "/home/<username>/home-assistant-streamdeck-yaml/home_assistant_streamdeck_yaml.py", line 1932, in main
    asyncio.run(
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/<username>/home-assistant-streamdeck-yaml/home_assistant_streamdeck_yaml.py", line 1848, in run
    await handle_changes(websocket, complete_state, deck, config)
  File "/home/<username>/home-assistant-streamdeck-yaml/home_assistant_streamdeck_yaml.py", line 1092, in handle_changes
    await asyncio.gather(
  File "/home/<username>/home-assistant-streamdeck-yaml/home_assistant_streamdeck_yaml.py", line 1057, in process_websocket_messages
    _update_state(complete_state, data, config, deck)
  File "/home/<username>/home-assistant-streamdeck-yaml/home_assistant_streamdeck_yaml.py", line 1131, in _update_state
    update_key_image(
  File "/home/<username>/home-assistant-streamdeck-yaml/home_assistant_streamdeck_yaml.py", line 1476, in update_key_image
    deck.set_key_image(key, image)
  File "/home/<username>/.env/lib/python3.11/site-packages/StreamDeck/Devices/StreamDeckOriginalV2.py", line 139, in set_key_image
    self.device.write(payload + padding)
  File "/home/<username>/.env/lib/python3.11/site-packages/StreamDeck/Transport/LibUSBHIDAPI.py", line 407, in write
    return self.hidapi.write(self.device_handle, payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/<username>/.env/lib/python3.11/site-packages/StreamDeck/Transport/LibUSBHIDAPI.py", line 322, in write
    raise TransportError("Failed to write out report (%d)" % result)
StreamDeck.Transport.Transport.TransportError: Failed to write out report (-1)
python3: ../../libusb/os/threads_posix.h:46: usbi_mutex_lock: Assertion `pthread_mutex_lock(mutex) == 0' failed.
python3: ../../libusb/os/threads_posix.h:58: usbi_mutex_destroy: Assertion `pthread_mutex_destroy(mutex) == 0' failed.
Aborted (core dumped)
(.env) <username>@ubuntu:~$

Any idea whats going on here?

Activity

  1. danielskowronski commented on Feb 7, 2025

    @danielskowronski

    I had the same problem with Raspberry Pi 3B+ running Ubuntu 24.04 64-bit when interfacing Stream Deck Neo. It was running for several seconds, then all subsequent runs were failing with StreamDeck.Transport.Transport.TransportError and only RPi reboot could help.

    It turns out that Ubuntu images ship with dwc2,dr_mode=otg as default setting instead of dwc2,dr_mode=host (default on Raspbian), which impacts the onboard USB controller (DWC2) ability to handle large HID Feature reports.

    To solve the issue, you need to append dtoverlay=dwc2,dr_mode=host to /boot/firmware/config.txt and reboot.


    A few words on my debugging, maybe something will help maintainers.

    Output from failing example_neo.py usually looks like that (but sometimes it can pass reset and fail on first write command):

    Found 1 Stream Deck(s).
    
    Traceback (most recent call last):
      File "/home/daniel/streamdeck/example_neo.py", line 145, in <module>
        deck.reset()
      File "/usr/local/lib/python3.12/dist-packages/StreamDeck/Devices/StreamDeckNeo.py", line 120, in reset
        self.device.write_feature(payload)
      File "/usr/local/lib/python3.12/dist-packages/StreamDeck/Transport/LibUSBHIDAPI.py", line 400, in write_feature
        return self.hidapi.send_feature_report(self.device_handle, payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/StreamDeck/Transport/LibUSBHIDAPI.py", line 260, in send_feature_report
        raise TransportError("Failed to write feature report (%d)" % result)
    StreamDeck.Transport.Transport.TransportError: Failed to write feature report (-1)
    python3: ../../libusb/os/threads_posix.h:46: usbi_mutex_lock: Assertion `pthread_mutex_lock(mutex) == 0' failed.
    python3: ../../libusb/os/threads_posix.h:58: usbi_mutex_destroy: Assertion `pthread_mutex_destroy(mutex) == 0' failed.
    Aborted (core dumped)
    

    Those assertions failures (last 3 lines) are not the root cause, rather symptom of improper exit. I suspect there's something out of order in handling HID device closure, but I know just a few things about USB. Anyway, removing self.HIDAPI_INSTANCE.hid_exit() didn't impact Failed to write out report (-1), but assertions were gone. This could be fixed, as it's easy to trigger an ugly error with Ctrl+C even if things still work.

    I also tried making payloads of hidapi.send_feature_report and hidapi.write truncated, but writes were always failing.

    The problem is not with the device, I could make it fail on RPi, disconnect it, connect to some other computer with Elgato software, run it there, reconnect back to RPi, and it'd behave like before.

    OP has "Stream Deck original V2" which seems to be "Stream Deck Mk.2" and I guess it may be similar to my Neo (both use USB-C). Thus, both devices may be similarly too new or too heavy for OTG mode.

    If needed, I could do some USB traffic sniffing to help further, but for my scenario it's enough to keep dwc2,dr_mode=host (dwc_otg does not work on my board).

    Some more context on https://raspberrypi.stackexchange.com/a/77061

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions