Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB Host either triggers "No free interrupt" error or stalls after connecting to a UPS #2

Open
x-magic opened this issue Jul 10, 2024 · 3 comments

Comments

@x-magic
Copy link

x-magic commented Jul 10, 2024

While I'm trying to adapt your code to support a Cyberpower UPS, I encountered some issues that I have no clue how to debug. Would really appreciate if you can shed some lights :D

Hardware: A clone of YD-ESP32-S3 N16R8 with OTG pad connected
IDF Components:

  • espressif/usb_host_hid: 1.0.2
  • espressif/led_strip: 2.5.4
  • idf 5.2.1

When the board is connected to Wi-Fi in app_main() (calling example_connect()) it triggers

intr_alloc: No free interrupt inputs for USB interrupt (flags 0x802)

this error. Since it looks like a compatibility error, so I commented out the line of code to connect to Wi-Fi, the code can finally boot into USB sections, and looping and waiting for UPS to connect at timer_task().

(当Wi-Fi连接后USB无法初始化,会显示如下错误,似乎和个别AP有兼容性问题,如果不连接Wi-Fi的话是可以继续的)

However when UPS is connected through USB port, this happens:

I (416) main_task: Returned from app_main()
I (796) ups: hid_host_device_event: HID Device, protocol 'NONE' CONNECTED
E (1376) USBH: Dev 1 EP 0 STALL

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x7 (TG0WDT_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)

Looks like something caused the USB Host to stall. Since I don't have JTAG debugger, that's as far as I can go for now.

(当UPS连接到USB后会显示 USB Host stall, 如上,然后就重启了,也不知道是哪个部分出错的)

Wonder if you have any idea what may cause this issue, or if it's something you know during development as well.

Thank you!

@ludoux
Copy link
Owner

ludoux commented Jul 10, 2024

To be honest, I didn't meet the two problems before.

I quickly searched for the USB issue and found espressif/esp-idf#13986 and https://www.esp32.com/viewtopic.php?t=27763 . It may be (a) bugs in the latest idf code and/or (b) incompatibility between the transfer protocol and your UPS, as the repo is designed for my UPS spec.

If (a), I suggest you to use v5.1.1 or the version around that time, as the code I used was the master branch code after the release of v5.1 . Just make sure it have hid_class_request_get_report

You can follow the USB HID Class example provided by ESP official. Remember to use the master branch or any future release gt v5.1. The example in v5.1 does not contain hid_class_request_get_report, and the whole structure is different.

If (b), you may have to find out the real protocol by yourself. You can try to use Device Monitoring Studio to send the protocol in my repo README and check if the result is familar with mine.

Here are the steps I done to figure out the protocol:

  1. Install a NUT client( or may be a server ? I just forgot) and Wireshark in your PC. Connect the UPS to your PC and just use the Wireshark to capture the tranfer packets.
  2. Use websites like https://eleccelerator.com/usbdescreqparser/ to "view" HID descriptor you just captured. Find out the IDs it support.
  3. Capture the routine transfer between NUT and your NAS. It should contains the battery level info. Find the ID it used and find the description from the step2 result.
  4. Shutdown NUT and use Device Monitoring Studio to send HID packet and view the result. Try the IDs from step2 and "translate" the result mannually.

:)

@x-magic
Copy link
Author

x-magic commented Jul 10, 2024

Great insights thank you!

So I think it's kind of working now - WiFi is still an issue - with IDF 5.1.1 it connects to an iPhone hotspot but not my AP, sounds like something to do with WPA3? Not sure about that. I'll just have WiFi disconnected while working on the protocol.

So USB Host stalls/crashes spectacularly on IDF 5.1.1 + usb_host_hid 1.0.0 🤣 but mostly working on IDF 5.2.1 + usb_host_hid 1.0.2. It seems to have something to do with feature report 0x1f on alarms. Once I stop that particular get report it kind of working now. I referred to cyberpower-usb-watcher where it mentions Cyberpower HID is compatible with HID PD, however I'm still trying to figure out the format of each feature report as none of them matches the documentation trivially.

image

Not bad for mid-night coding and my first C, ESP32 and USB HID project 🫠

Again, great code base to begin with!

@ludoux
Copy link
Owner

ludoux commented Jul 11, 2024

Great!

as none of them matches the documentation trivially

I found and listed some docs in the README but my NAS is not the same as any of them, and there are always some diffs. Strange ha.

pdcv11.pdf - Usage Tables for HID Power Devices 1.1
NUT_MGE_USB_Devices_Draft_AA.pdf
51029473zaac.pdf - Simplified SHUT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants