switchbrew / libnx

Library for Switch Homebrew

Home Page:https://switchbrew.github.io/libnx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

usbDsInitialize() hangs under HOS 4.1.0.

DarkMatterCore opened this issue · comments

This is an unpatched unit running latest AMS + 4.1.0 sysMMC.

Regardless of the homebrew application used, the console freezes whenever usbDsInitialize() is called. This is what it displays:

Hang picture

hang

The same issue can be reproduced if usbCommsInitialize() is used instead - it takes care of initializing usb:ds on its own, after all. We carried out a simple test using the following code (built with latest libnx release):

Test app
#include <stdio.h>
#include <switch.h>

int main(int argc, char* argv[])
{
    Result rc = 0;
    PadState pad = {0};
    
    u64 flag = ~(HidNpadButton_StickLLeft | HidNpadButton_StickLRight | HidNpadButton_StickLUp | \
                 HidNpadButton_StickLDown | HidNpadButton_StickRLeft | HidNpadButton_StickRRight | \
                 HidNpadButton_StickRUp | HidNpadButton_StickRDown);
    
    padConfigureInput(1, HidNpadStyleSet_NpadStandard);
    padInitializeDefault(&pad);
    
    consoleInit(NULL);
    
    printf("usbComms test.\n");
    
    rc = usbCommsInitialize();
    if (R_SUCCEEDED(rc))
    {
        printf("usbCommsInitialize succeeded.\n");
        usbCommsExit();
    } else {
        printf("usbCommsInitialize failed: 0x%X.\n", rc);
    }
    
    printf("Press any button to exit.");
    consoleUpdate(NULL);
    
    while(appletMainLoop())
    {
        padUpdate(&pad);
        if (padGetButtonsDown(&pad) & flag) break;
    }
    
    consoleExit(NULL);
    
    return 0;
}

What's interesting about these hangs is that we discovered everything works properly if the console is put to sleep during the hang and then immediately woken up. This workaround fixed the issue not only in the provided usbComms test application, but also in other homebrew applications that use usb:ds in one way or another.

If required, additional information could be provided. Thanks in advance.

Repro'd this with emummc 4.1.0. The BindDevice cmd used from usbDsInitialize is hanging. usbds works fine on other system-versions - so this is likely a system issue.

Re-inserting the usb cable also fixes the hang fwiw. Updating to a newer system-version (with emummc if wanted) would also resolve it.