wizzomafizzo / tapto

Launch games using physical objects
GNU General Public License v3.0
64 stars 9 forks source link

Fails when CTRLDock USB is connected (on IOUSB Plus board from Antonio V) #54

Closed matthutchinson closed 1 month ago

matthutchinson commented 2 months ago

First up, many many thanks for such a wonderful project. It's given a whole new life to my MiSTer setup, since my kids can now easily launch their favourite games without having to bother me πŸ‘ πŸŽ‰


So my NFC reader is working great and has no issues, but when insert this CTRLDock USB accessory, the reader stops reading completely. The white LED that shows its polling, stops flashing, and I can no longer launch from cards. This happens if I insert the doc to USB after the MiSTer has booted, or if I boot with it inserted.

A few notes on my setup;

My taptoui.ini config is

[tapto]
connection_string="pn532_uart:/dev/ttyUSB0"
allow_commands=no

ls /dev/serial/by-id

usb-1a86_USB_Serial-if00-port0

ls /dev/ttyUSB*

/dev/ttyUSB0

I'd be keen to know if anyone else has similar issues with their MiSTer and TapTo reader when the CTRLDock is connected - or maybe if this is specific to Antonio's IOUSB board.

Also, I'm happy to help debug, I'm a developer (software only) so I know my way around cmd lines, grepping logs and the like.

Maybe there's some USB related conflict I can resolve here, by specifying another connection string?


Also, feel free to close this issue, as it's likely down to the specific hardware setup I have Β―\_(ツ)_/Β― And I can always fix it by starting with the dock disconnected.

sigboe commented 2 months ago

@matthutchinson what situation is it you got that output of ls /dev/ttyUSB* is it both when the control dock is connected and when it is not connected?

sigboe commented 2 months ago

Can you post the logs from /var/log/tapto/tapto.log ? get a situation from when it works to when it doesn't

matthutchinson commented 2 months ago

So when only the tapto is connected I get

/dev/ttyUSB0

With the unit then powered on (and tap to working) when I connect the dock I then see:

/dev/ttyUSB1

BUT, when I power cycle with both connected, its back to

/dev/ttyUSB0

... and not working / no LED / no launching

matthutchinson commented 2 months ago

Working..

/root# tail -f /var/log/tapto/tapto.log
{"level":"info","time":1714421949,"message":"starting file watcher"}
{"level":"info","time":1714421949,"message":"loaded 6 entries from database"}
{"level":"info","time":1714421949,"message":"reader not connected, attempting connection...."}
{"level":"info","time":1714421949,"message":"connecting to device: pn532_uart:/dev/ttyUSB0"}
{"level":"info","time":1714421949,"message":"successful connect after 0 tries"}
{"level":"info","time":1714421949,"message":"connection protocol: pn532_uart"}
{"level":"info","time":1714421949,"message":"device name: pn532_uart:/dev/ttyUSB0"}
{"level":"info","time":1714421949,"message":"opened connection: pn532_uart:/dev/ttyUSB0 pn532_uart:/dev/ttyUSB0"}
{"level":"info","time":1714421956,"message":"arcade database is up to date"}
{"level":"info","time":1714421956,"message":"arcade database has 2358 entries"}
{"level":"info","time":1714421985,"message":"found token UID: 044acb029c6581"}
{"level":"info","time":1714421985,"message":"NTAG detected"}
{"level":"warn","time":1714421985,"message":"no text NDEF found"}
{"level":"info","time":1714421985,"message":"processing token: {NTAG 044acb029c6581  2024-04-29 21:19:45.73668492 +0100 BST m=+38.171210661 false}"}
{"level":"info","time":1714421985,"message":"launching with csv uid match override"}
{"level":"info","time":1714421985,"message":"launching with text: SNES/1 US - F-M/Legend of Zelda NFC.sfc"}
{"level":"info","time":1714421987,"message":"found mapping: SNES -> SNES"}
{"level":"info","time":1714421988,"message":"card removed"}

Plugging in dock I get this, then no output to log when scanning

{"level":"error","time":1714422042,"message":"error during poll: input / output error"}
{"level":"error","time":1714422042,"message":"fatal IO error, device was possibly unplugged"}
matthutchinson commented 2 months ago

With both connected before power on, the log looks like this;

/root# tail -f /var/log/tapto/tapto.log
{"level":"info","time":1714422116,"message":"starting file watcher"}
{"level":"info","time":1714422116,"message":"loaded 6 entries from database"}
{"level":"info","time":1714422116,"message":"reader not connected, attempting connection...."}
{"level":"info","time":1714422116,"message":"connecting to device: pn532_uart:/dev/ttyUSB0"}
{"level":"info","time":1714422116,"message":"successful connect after 0 tries"}
{"level":"info","time":1714422116,"message":"connection protocol: pn532_uart"}
{"level":"info","time":1714422116,"message":"device name: pn532_uart:/dev/ttyUSB0"}
{"level":"info","time":1714422116,"message":"opened connection: pn532_uart:/dev/ttyUSB0 pn532_uart:/dev/ttyUSB0"}
{"level":"info","time":1714422128,"message":"arcade database is up to date"}
{"level":"info","time":1714422129,"message":"arcade database has 2358 entries"}

But scanning adds no more log lines, no game launches

sigboe commented 2 months ago

This is definitely because the connection string forces to look at a specific device. And then probably because the controller has a serial port to program it then it appears for Linux for a brief moment

If you only have the NFC reader connected and reboot so its working, then you

udevadm info -n /dev/ttyUSB0

Here is the information we need to make a udev rule

You can try to make a udev rule, a file name like /etc/udev/rules.d/10-nfc.rules with something like this but for your device

SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ttyUSB_custom_name"

I am not 100% confident this is the rule that should be used, usually just find a udev rule for something someone else has made, not make them my self

Then either reboot or reload your udev rules udevadm control --reload-rules

Then have the same custom name as the symlink made by udev, in your connection string

There might be a simpler way though if this becomes a common thing for many people

Also if SYMLINK doesnt work, then I know there is a way to force a specific path for the device...

matthutchinson commented 2 months ago

Thanks! πŸ™ will give that a try first thing tomorrow and report back here.

wizzomafizzo commented 2 months ago

You can also try just deleting your tapto.ini file and trying the auto-detect, if you haven't already. This would fix your issue as long as it doesn't cause any trouble with the ctrldock (it's been know to cause problems with a type of spinner and tty2oled project)

Udev rule may have some issues working well depending on the chip ctrldock uses. For example the USB chip in an arduino clone (and the DIY reader) cannot be differentiated by the OS and assigned a custom address reliably

sigboe commented 2 months ago

@wizzomafizzo Well the feature list for that product does list mouse support and paddle support... So... It can be the spinner thing.

matthutchinson commented 2 months ago

So with dock and tap connected, and no tapto.ini file set then I get this in the log (but no launching, no led flashing etc.)

/root# tail -f /var/log/tapto/tapto.log
{"level":"info","time":1714466427,"message":"loaded 6 entries from database"}
{"level":"info","time":1714466427,"message":"reader not connected, attempting connection...."}
{"level":"info","time":1714466427,"message":"probing for serial devices"}
{"level":"info","time":1714466427,"message":"trying pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714466427,"message":"success using serial: pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714466427,"message":"connecting to device: pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714466427,"message":"successful connect after 0 tries"}
{"level":"info","time":1714466427,"message":"connection protocol: pn532_uart"}
{"level":"info","time":1714466427,"message":"device name: pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714466427,"message":"opened connection: pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714466444,"message":"arcade database is up to date"}
{"level":"info","time":1714466444,"message":"arcade database has 2358 entries"}

Trying the udev thing now

matthutchinson commented 2 months ago

So with udev, I successfully created the rule and used tapto.ini to point to the symlink. This works as before when no CTRLdock plugged in.

But I get the same behaviour booting with both devices plugged in. Here's the tapto log for that;

{"level":"info","time":1714467815,"message":"starting file watcher"}
{"level":"info","time":1714467815,"message":"loaded 6 entries from database"}
{"level":"info","time":1714467815,"message":"reader not connected, attempting connection...."}
{"level":"info","time":1714467815,"message":"connecting to device: pn532_uart:/dev/ttyUSB_tapto_nfc"}
{"level":"info","time":1714467815,"message":"successful connect after 0 tries"}
{"level":"info","time":1714467815,"message":"connection protocol: pn532_uart"}
{"level":"info","time":1714467815,"message":"device name: pn532_uart:/dev/ttyUSB_tapto_nfc"}
{"level":"info","time":1714467815,"message":"opened connection: pn532_uart:/dev/ttyUSB_tapto_nfc pn532_uart:/dev/ttyUSB_tapto_nfc"}
{"level":"info","time":1714467822,"message":"arcade database is up to date"}
{"level":"info","time":1714467822,"message":"arcade database has 2358 entries"}

And heres the output of ls /dev/ttyUSB*

/dev/ttyUSB0  /dev/ttyUSB_tapto_nfc

Thanks for all your help on this πŸ™‡β€β™‚οΈ

sigboe commented 2 months ago

So that means that udev can't tell the difference between the two hardware identifiers I guess!

Can you try removing both the udev rule and the connection_string="pn532_uart:/dev/ttyUSB0"?

If you needed it before, maybe you don't need it now, if it still doesn't work can you try to enable the probe_device=true setting

matthutchinson commented 2 months ago

Thanks for your suggestions but still no dice.

Removing both the udev rule and tapto.ini having only probe_device=true - I get the same problem.

Here's the log when I boot in that scenario, with the dock and tapto nfc connected:

{"level":"info","time":1714515017,"message":"probing for serial devices"}
{"level":"info","time":1714515017,"message":"trying pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714515017,"message":"success using serial: pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714515017,"message":"connecting to device: pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714515017,"message":"successful connect after 0 tries"}
{"level":"info","time":1714515017,"message":"connection protocol: pn532_uart"}
{"level":"info","time":1714515017,"message":"device name: pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714515017,"message":"opened connection: pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 pn532_uart:/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0"}
{"level":"info","time":1714515024,"message":"arcade database is up to date"}
{"level":"info","time":1714515024,"message":"arcade database has 2358 entries"}

Interestingly the white LED does flash for 3, 4 secs after the mister boots up, but then stops. And attempting to launch a game does nothing (and nothing in the log)

When I unplug the dock and reboot, it works again. So at least I don't need hang onto the tapto.ini file (i.e. auto detect works).

sigboe commented 2 months ago

What does dmesg say when you connect NFC, then connect CtrlDock?

matthutchinson commented 2 months ago

(in both cases, no udev rules and no tapto.ini set)

matthutchinson commented 2 months ago

In the 2nd trace, you'll see the CTRLDock detected (Multisystem Controller Slice / Heber Ltd.) before the NFC reader, then these extra lines later:

[   16.746011] ch341-uart ttyUSB0: usb_serial_generic_read_bulk_callback - urb stopped: -32
[   16.922949] dwc2 ffb40000.usb: dwc2_hc_chhltd_intr_dma: Channel 7 - ChHltd set, but reason is unknown
[   16.932166] dwc2 ffb40000.usb: hcint 0x00000402, intsts 0x06000029
[   16.938458] dwc2 ffb40000.usb: dwc2_hc_chhltd_intr_dma: Channel 15 - ChHltd set, but reason is unknown
[   16.938493] dw_mmc ff704000.dwmmc0: Unexpected interrupt latency
[   16.947737] dwc2 ffb40000.usb: hcint 0x00000402, intsts 0x06000029
[   16.954032] dwc2 ffb40000.usb: dwc2_hc_chhltd_intr_dma: Channel 5 - ChHltd set, but reason is unknown
[   16.963231] dwc2 ffb40000.usb: hcint 0x00000402, intsts 0x06000029
[   19.696119] ch341-uart ttyUSB0: usb_serial_generic_read_bulk_callback - urb stopped: -32
sigboe commented 2 months ago

@matthutchinson so ch341-uart ttyUSB0: usb_serial_generic_read_bulk_callback - urb stopped: -32 suggest that the device connection drops, and the driver crashes.

It is possible that the device loses power, like if CtrlDock has a power spike when initializing.

What is the spec of your MiSTer's power supply? What kind of USB hub are you using on your MiSTer, how is this USB hub powered. Do you have another powered USB hub you can try just for testing this hypothesis?

sorry you already said you are using Antonio's USB hub, and this draws power from the MiSTer. I'm not 100% sure but I believe through the GPIO lines. And I am not 100% sure the amperage this is able to draw. So again, what is your MiSTer power supply, and do you have a powered USB hub for testing purposes?

matthutchinson commented 2 months ago

do you have a powered USB hub for testing purposes?

Unfortunately I don't :(. I could look at getting one tho..

what is your MiSTer power supply,

I've got a Mean Well 20W Power Supply, this;

IMG_1480

sigboe commented 2 months ago

@matthutchinson Just want to say this is a great power supply, but that doesn't rule out power on the USB port. But I still think there might be an issue here, because I believe your usb hub draws power from the GPIO, and that may limit the amperage.

Do you run Linux on your own computer? See if the problem is there, also.

If you connect NFC to your linux pc, and use any of the nfc-tools from libnfc package (on my distro) to check if its reading tags, then connect the controldeck, and see if it's working, the joyutils has jstest in my distro. Then see if the nfc reader still works. Or if dmesg shows the same disconnection

sigboe commented 2 months ago

@matthutchinson Here are some simplified instructions https://wiki.archlinux.org/title/NFC https://wiki.archlinux.org/title/Gamepad

matthutchinson commented 1 month ago

Thanks again, I've only got a mac here, I'll try with it. Failing that I could boot up one of my old Pi 3B+ boards, I think I have ubuntu on there...

matthutchinson commented 1 month ago

So I resurrected my old Raspberry Pi 3B+ (with Ubuntu server on it)...

Here's dmesg inserting the tapto first, the the ctrldock: dmesg log

No disconnects mentioned at least

Unfortunately, pcsc_scan wouldn't recognise the NFC reader, running pcscd -f -d I see that it can't find a driver for it;

00000244 pcscdaemon.c:671:main() pcsc-lite 2.0.3 daemon ready.
00000448 pcscdaemon.c:754:main() Using drivers directory: /usr/lib/pcsc/drivers
00027884 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x1D6B, PID: 0x0002, path: /dev/bus/usb/001/001
00001419 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x1D6B, PID: 0x0002, path: /dev/bus/usb/001/001
00001661 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x0424, PID: 0x2514, path: /dev/bus/usb/001/002
00001719 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x0424, PID: 0x2514, path: /dev/bus/usb/001/003
00001635 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x0424, PID: 0x7800, path: /dev/bus/usb/001/004
00001487 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x0424, PID: 0x2514, path: /dev/bus/usb/001/003
00001524 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x1A86, PID: 0x7523, path: /dev/bus/usb/001/017
00001659 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x0424, PID: 0x2514, path: /dev/bus/usb/001/003
00001387 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x0424, PID: 0x2514, path: /dev/bus/usb/001/002
03969930 hotplug_libudev.c:639:HPEstablishUSBNotifications() USB Device removed
03073935 hotplug_libudev.c:645:HPEstablishUSBNotifications() USB Device add
00001461 hotplug_libudev.c:298:get_driver() Looking for a driver for VID: 0x1A86, PID: 0x7523, path: /dev/bus/usb/001/018

Also, joyutils isn't packaged for Ubuntu...

If you think it would be helpful I could look at getting Arch Linux onto the Pi (or debian) since they have those packages...

sigboe commented 1 month ago

@matthutchinson If we take the most expensive and timeconsuming way out, we will spend all our money and have no time left. So I think it's faster to just get jstest working on ubuntu

According to this manpage https://manpages.ubuntu.com/manpages/xenial/man1/jstest.1.html Seams jstest is packaged in the jostick package on ubuntu. Hope it still holds true for newer ubuntus, It's many years since I've used ubuntu for anything other than servers.

@wizzomafizzo Do you have any input in testing just making sure nfc is working on ubuntu?

Still the working theory is that there is not enough, power to run both these devices on the usb hub. And this might be just for a moment. Other people who had the same errors when searching on DuckDuckGo also had power issues.

Do you have like a USB dock and a usb-c to usb-a adapter or usb-c to micro usb adapter so you can test this directly without committing money on a wild goose chase? Or a friend has a powered usb hub?

wizzomafizzo commented 1 month ago

I don't believe we have any simple way to test a PN532 is working ok outside mister. It's not supported natively on any other OS without some custom software (that I don't have any recommendation for), I don't think it will be useful to try it on another system anyway as I think it's functioning fine.

I'm getting a bit lost in the thread now sorry, so just to summarise so far:

Does the CTRLDock also stop working or is it fine the whole time?

sigboe commented 1 month ago

Just googling https://github.com/GSWXXN/NFCToolsGUI Here is a gui program that claims support for this module. It says the kernel should include CH341 driver built in, if it doesn't have that, there is a link to a file with a kernel module, it looks simple, one .c file one .h file and a Makefile, so it shouldβ„’ just be to run sudo make install on ubuntu?

matthutchinson commented 1 month ago

OK, some progress.

Before I went down the rabbit hole of linux/mac drivers etc. I realised I had a Philips monitor in storage. It has a built in USB hub, which I assume is powered by the monitor's PSU.

Using this, the TapTo NFC reader and the CTRLDock both work when both plugged in. Here's a short video demonstrating that;

https://www.youtube.com/shorts/nmhcZ40z0o8

So I guess Antonio's board isn't allowing enough power for both of these devices to be served at the same time.
I'll close this issue now, since it's clear there's not a problem here with the TapTo driver, or hardware.

I'll either get myself a powered USB, or live with plugging things in/out.

@sigboe, @wizzomafizzo thanks for your throughout help on this issue, much appreciated! πŸ™‡β€β™‚οΈπŸ€πŸ‘