AterialDawn / Nintendo-Switch-Pro-Controller-AVR-Firmware

Firmware for AVR devices to emulate a genuine Nintendo Switch Pro Controller (Currently Non-Functional)
13 stars 6 forks source link

Not working on a 16u2 device #3

Open WhileE opened 5 years ago

WhileE commented 5 years ago

Pulled the latest code, simply altered the CPU from the 32u4 to the 16u2. Built, and pushed to device just fine, but doesn't enumerate on the Switch. Tried sniffing it with USBProxy on the BBB, and it crashed every time with some "null pointer dereference" error.

Looking at the syslog, instead of the expected:

[ 6470.959476] usb 2-1: Manufacturer: Nintendo Co., Ltd.
[ 6470.981685] input: Nintendo Co., Ltd. Pro Controller as /devices/ocp.3/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb2/2-1/2-1:1.0/input/input43
[ 6471.013880] hid-generic 0003:057E:2009.002C: input,hidraw0: USB HID v1.11 Joystick [Nintendo Co., Ltd. Pro Controller] on usb-musb-hdrc.1.auto-1/input0

I simply got: [ 3.119889] usb 2-1: Manufacturer: Nintendo Co., Ltd.

So it's not even enumerating as a pro controller for whatever reason. Possibly the descriptors, not sure, will toy around with it later today if I have time. Just wanted to plug it here to see if maybe there's something glaringly obvious that my tunnel vision has me overlooking. Tried both with avr-gcc natively, and atmel studio, both with same results.

WhileE commented 5 years ago

Finally got it to enumerate, it was actually hanging up here:

void EVENT_USB_Device_ConfigurationChanged(void) {
    ResetReplyData();
    sendInputReports = false;
    bool Success = true;
    Success &= Endpoint_ConfigureEndpoint(EP_IN_ADDR, EP_TYPE_INTERRUPT, EP_SIZE, 1);
    Success &= Endpoint_ConfigureEndpoint(EP_OUT_ADDR, EP_TYPE_INTERRUPT, EP_SIZE, 1);
    if(!Success)
    {
        RXLED0;
        TXLED0;
        for(; ;) ; //die
    }
    RXLED1;
}

If I remove the if(!Success)... then it will move forward and enumerate as expected. However, it's clearly failing to setup the endpoints properly. Using USBProxy I get the following:

cleaning up /tmp
removing 0
Made directory /[ 6142.738843] nop musb-hdrc.0.auto: failed to start (null): -120
tmp/gadget-7U0Zg0 for gadget
Made directory /tmp/mqueue-QA6MCQ for mqueue
cleaning up /tmp/mqueue-QA6MCQ
removing 0
Device: 12 01 00 02 00 00 00 40 7e 05 09 20 00 0[ 6142.762309] gadgetfs: bound to musb-hdrc driver
2 01 02 03 01
  Manufacturer: Nintendo Co., Ltd.
  Product:      Pro Controller
  Serial:       000000000001
        *Config(1): 09 02 29 00 01 01 00 a0 fa
                Interface(0):
                        *Alt(0): 09 04 00 00 02 03 00 00 00
                                HID: 09 21 11 01 00 01 22 cb 00
                                EP(81): 07 05 81 03 40 00 08
                                EP(02): 07 05 02 03 40 00 08
searching in [/tmp/gadget-7U0Zg0]
Starting setup writer thread (2471) for EP00.
Starting setup reader thread (2470) for EP00.
[ 6143.140928] gadgetfs: suspended from state 2
[ 6143.644944] gadgetfs: connected
[80 06 00 03 00 00 82 00]
[80 06 00 03 00 [ 6143.659819] gadgetfs: configuration #1
00 04 00]: 04 03 09 04
[00 09 01 00 00 00 00 00]
Opened EP81
Opened EP02
Starting writer thread (2476) for EP02.
[81 06 00 22 00 00 cb 00]
Starting reader thread (2475) for EP02.
Starting writer thread (2474) for EP81.
Starting reader thread (2473) for EP81.
[81 06 00 22 00 00 cb 00]: 
        05 01 15 00 09 04 a1 01 85 30 05 01 05 09 19 01 29 0a 15 00 25 01 75 01 95 0a 55 00 65 00 81 02
        05 09 19 0b 29 0e 15 00 25 01 75 01 95 04 81 02 75 01 95 02 81 03 0b 01 00 01 00 a1 00 0b 30 00
        01 00 0b 31 00 01 00 0b 32 00 01 00 0b 35 00 01 00 15 00 27 ff ff 00 00 75 10 95 04 81 02 c0 0b
        39 00 01 00 15 00 25 07 35 00 46 3b 01 65 14 75 04 95 01 81 02 05 09 19 0f 29 12 15 00 25 01 75
        01 95 04 81 02 75 08 95 34 81 03 06 00 ff 85 21 09 01 75 08 95 3f 81 03 85 81 09 02 75 08 95 3f
        81 03 85 01 09 03 75 08 95 3f 91 83 85 10 09 04 75 08 95 3f 91 83 85 80 09 05 75 08 95 3f 91 83
        85 82 09 06 75 08 95 3f 91 83 c0
[80 06 00 03 00 00 ff 00]
[80 06 00 03 00 00 04 00]: 04 03 09 04
[80 06 01 03 09 04 40 00]
[80 06 01 03 09 04 26 00]: 
        26 03 4e 00 69 00 6e 00 74 00 65 00 6e 00 64 00 6f 00 20 00 43 00 6f 00 2e 00 2c 00 20 00 4c 00
        74 00 64 00 2e 00
[80 06 02 03 09 04 40 00]
[80 06 02 03 09 04 1e 00]: 1e 03 50 00 72 00 6f 00 20 00 43 00 6f 00 6e 00 74 00 72 00 6f 00 6c 00 6c 00 65 00 72 00
[80 06 03 03 09 04 40 00]
[80 06 03 03 09 04 1a 00]: 1a 03 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 31 00
02[2]: 00 00
Transfer error (-1) on Device EP2
Incomplete Interrupt transfer on EP02
02[2]: 00 00
Transfer error (-1) on Device EP2
Incomplete Interrupt transfer on EP02
02[2]: 00 00
Transfer error (-1) on Device EP2
Incomplete Interrupt transfer on EP02
02[2]: 80 01
Transfer error (-1) on Device EP2
Incomplete Interrupt transfer on EP02

Still playing around trying to figure out what this actually indicates, but I have to assume it all comes back to the failure of the endpoints. Not super familiar with USB/Endpoints so any insight would be awesome.

WhileE commented 5 years ago

It's actually never getting past this conditional:

    Endpoint_SelectEndpoint(EP_OUT_ADDR);
    if (Endpoint_IsOUTReceived())
    {

Which again points to the OUT endpoint not working properly.

AterialDawn commented 5 years ago

It seems like it's a LUFA issue, as that code works perfectly fine on a 32u4. Unfortunately I don't have a 16u2 device to help you test with, so it seems you are on your own in that regard.

I'll leave this issue open in case I ever get a 16u2 to test with.

WhileE commented 5 years ago

Yeah, I've reached out hoping to get some insight on that side of things, with very little response. What's odd is that you're configuring the endpoints as interrupt transfers, but when I do a wireshark dump of the comms, it shows as URB_BULK(0x03)?

Wireshark PCAP

AterialDawn commented 5 years ago

Ah, looks like a controller firmware update changed the endpoints from Interrupt to Bulk. Unfortunately I can't really do anything now, since the only USB sniffing equipment I had was matlo's serialusb project, and that only works with Interrupt-type endpoints. I'll change the description to indicate that this project is no longer working, but if I ever get the BBB board i'll gladly work on fixing this.

Apologies for not being able to be of more use.

WhileE commented 5 years ago

If I get some time this weekend I will play around with it. This is the only thing I can find with some substance to it though, so hoping its the right rabbit hole. If I do resolve, I will update here