USB hid-keyboard example ""USB HID device is not ready"

Hello. I have been playing with the HID keyboard example (./samples/subsys/usb/hid-keyboard) and it's not running correctly. Code was compiled for the nRF7002-DK board (-b nrf7002dk/nrf5340/cpuapp). Here is the output from the terminal:

*** Booting Zephyr OS build v4.0.0-1487-g595d81a941c5 ***
[00:00:00.253,509] <inf> main: HID keyboard sample is initialized
[00:00:10.770,782] <inf> main: USB HID device is not ready
[00:00:10.996,856] <inf> main: USB HID device is not ready

The two "USB HID device is not ready" appear when the user button is pressed.

I have tried other boards, computers, etc, and get the same results. Results are also the same forwarding the USB device to WSL with USBIPD.

Has anyone else run this example recently?

Any ideas?

Thank you!

Parents
  • Hello,

    You can try to run "nrfjprog --recover" once. I built the hid-keyboard for the nrf5340 and it seems to work here, though you likely need to plug in and out the USB cable once, and also make sure that your USB cable have data lines.

    I notice you are using vanilla zephyr directly (not nRF Connect SDK). In that case you may need to rely on zephyr community support if you don't want to switch to nRF Connect SDK (until we have caught up).

    Kenneth

  • Kenneth, thanks for the tips. I did try to recompile with nRF Connect SDK, at least I think I did. I also ran the ""nrfjprog --recover" command and there was no change. 

    Below is the complete "from scratch" build process. Can you please do a sanity check on this? Thank you.

    stuart@SRUBIN-H43JDY3:~$ west init -m github.com/.../sdk-nrf.git  ~/ncs-workspace
    === Initializing in /home/stuart/ncs-workspace
    --- Cloning manifest repository from github.com/.../sdk-nrf.git
    Cloning into '/home/stuart/ncs-workspace/.west/manifest-tmp'...
    remote: Enumerating objects: 280378, done.
    remote: Counting objects: 100% (1020/1020), done.
    remote: Compressing objects: 100% (703/703), done.
    remote: Total 280378 (delta 472), reused 608 (delta 283), pack-reused 279358 (from 1)
    Receiving objects: 100% (280378/280378), 164.48 MiB | 60.69 MiB/s, done.
    Resolving deltas: 100% (209490/209490), done.
    --- setting manifest.path to nrf
    === Initialized. Now run "west update" inside /home/stuart/ncs-workspace.
    stuart@SRUBIN-H43JDY3:~$ cd ncs-workspace/
    stuart@SRUBIN-H43JDY3:~/ncs-workspace$ west update
    === updating zephyr (zephyr):
    --- zephyr: initializing
    Initialized empty Git repository in /home/stuart/ncs-workspace/zephyr/.git/
    --- zephyr: fetching, need revision a7fe5f7c4aab18312bd7f61afef55647e38f3db6
    remote: Enumerating objects: 1163241, done.
    remote: Counting objects: 100% (3182/3182), done.
    remote: Compressing objects: 100% (1137/1137), done.
    remote: Total 1163241 (delta 2041), reused 3000 (delta 2008), pack-reused 1160059 (from 1)
    Receiving objects: 100% (1163241/1163241), 622.13 MiB | 33.13 MiB/s, done.
    Resolving deltas: 100% (877727/877727), done.
     * [new branch]              backport-1453-to-v3.4.99-ncs1-branch -> refs/west/backport-1453-to-v3.4.99-ncs1-branch
    <SNIP>
    <SNIP>
    <SNIP>
    <SNIP>
     * [new tag]         old-structure     -> old-structure
    HEAD is now at 47f34dd Update version to 0.9.0
    stuart@SRUBIN-H43JDY3:~/ncs-workspace$
    stuart@SRUBIN-H43JDY3:~/ncs-workspace$ west zephyr-export
    Zephyr (/home/stuart/ncs-workspace/zephyr/share/zephyr-package/cmake)
    has been added to the user package registry in:
    ~/.cmake/packages/Zephyr

    ZephyrUnittest (/home/stuart/ncs-workspace/zephyr/share/zephyrunittest-package/cmake)
    has been added to the user package registry in:
    ~/.cmake/packages/ZephyrUnittest

    stuart@SRUBIN-H43JDY3:~/ncs-workspace$ cd zephyr/
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$ west build --pristine -b nrf7002dk/nrf5340/cpuapp samples/subsys/usb/hid-keyboard
    -- west build: generating a build system
    Loading Zephyr module(s) (Zephyr base): sysbuild_default
    -- Found Python3: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: /home/stuart/.cache/zephyr
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf7002dk, qualifiers: nrf5340/cpuapp
    Parsing /home/stuart/ncs-workspace/zephyr/share/sysbuild/Kconfig
    Loaded configuration '/home/stuart/ncs-workspace/zephyr/build/_sysbuild/empty.conf'
    Merged configuration '/home/stuart/ncs-workspace/zephyr/build/_sysbuild/empty.conf'
    Configuration saved to '/home/stuart/ncs-workspace/zephyr/build/zephyr/.config'
    Kconfig header saved to '/home/stuart/ncs-workspace/zephyr/build/_sysbuild/autoconf.h'
    --
       **********************************
       * Running CMake for hid-keyboard *
       **********************************

    Loading Zephyr default modules (Zephyr base).
    -- Application: /home/stuart/ncs-workspace/zephyr/samples/subsys/usb/hid-keyboard
    -- CMake version: 3.22.1
    -- Found Python3: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: /home/stuart/.cache/zephyr
    -- Zephyr version: 3.7.99 (/home/stuart/ncs-workspace/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf7002dk, qualifiers: nrf5340/cpuapp
    -- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
    -- Found host-tools: zephyr 0.17.0 (/home/stuart/zephyr-sdk-0.17.0)
    -- Found toolchain: zephyr 0.17.0 (/home/stuart/zephyr-sdk-0.17.0)
    -- Found Dtc: /usr/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
    -- Found BOARD.dts: /home/stuart/ncs-workspace/zephyr/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: /home/stuart/ncs-workspace/zephyr/samples/subsys/usb/hid-keyboard/app.overlay
    -- Generated zephyr.dts: /home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/include/generated/zephyr/devicetree_generated.h
    -- Including generated dts.cmake file: /home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/dts.cmake

    warning: Experimental symbol UDC_DRIVER is enabled.


    warning: Experimental symbol USB_DEVICE_STACK_NEXT is enabled.

    Parsing /home/stuart/ncs-workspace/zephyr/samples/subsys/usb/hid-keyboard/Kconfig
    Loaded configuration '/home/stuart/ncs-workspace/zephyr/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_defconfig'
    Merged configuration '/home/stuart/ncs-workspace/zephyr/samples/subsys/usb/hid-keyboard/prj.conf'
    Merged configuration '/home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/.config.sysbuild'
    Configuration saved to '/home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/.config'
    Kconfig header saved to '/home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/include/generated/zephyr/autoconf.h'
    -- Found GnuLd: /home/stuart/zephyr-sdk-0.17.0/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/stuart/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    -- Setting build type to 'MinSizeRel' as none was specified.
    -- Using ccache: /usr/bin/ccache
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/stuart/ncs-workspace/zephyr/build/hid-keyboard
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/stuart/ncs-workspace/zephyr/build
    -- west build: building application
    [5/10] Performing build step for 'hid-keyboard'
    [1/188] Preparing syscall dependency handling

    [6/188] Generating include/generated/zephyr/version.h
    -- Zephyr version: 3.7.99 (/home/stuart/ncs-workspace/zephyr), build: v3.7.99-ncs2-rc1-7-ga7fe5f7c4aab
    [188/188] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       65792 B         1 MB      6.27%
                 RAM:       16256 B       448 KB      3.54%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from /home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/zephyr.elf for board: nrf7002dk
    [10/10] Generating ../merged.hex
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$ west flash
    -- west flash: rebuilding
    [0/5] Performing build step for 'hid-keyboard'
    ninja: no work to do.
    [4/5] cd /home/stuart/ncs-workspace/zephyr/build/_sysbuild && /usr/bin/cmake -E true
    -- west flash: using runner nrfjprog
    -- runners.nrfjprog: reset after flashing requested
    Using board 1050715681
    -- runners.nrfjprog: Flashing file: /home/stuart/ncs-workspace/zephyr/build/merged.hex
    [ #################### ]   3.726s | Erase file - Done erasing
    [ #################### ]   0.605s | Program file - Done programming
    [ #################### ]   0.458s | Verify file - Done verifying
    Applying pin reset.
    -- runners.nrfjprog: Board with serial number 1050715681 flashed successfully.
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$


    FROM TERMINAL

    *** Booting nRF Connect SDK v2.9.99-b957011b12c4 ***
    *** Using Zephyr OS v3.7.99-a7fe5f7c4aab ***
    [00:00:00.340,576] <inf> main: HID keyboard sample is initialized
    [00:00:35.924,774] <inf> main: USB HID device is not ready
    [00:00:36.201,080] <inf> main: USB HID device is not ready


    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$ nrfjprog --recover
    Recovering device. This operation might take 30s.
    Erasing user code and UICR flash areas.
    Writing image to disable ap protect.
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$ west flash
    -- west flash: rebuilding
    [0/5] Performing build step for 'hid-keyboard'
    ninja: no work to do.
    [4/5] cd /home/stuart/ncs-workspace/zephyr/build/_sysbuild && /usr/bin/cmake -E true
    -- west flash: using runner nrfjprog
    -- runners.nrfjprog: reset after flashing requested
    Using board 1050715681
    -- runners.nrfjprog: Flashing file: /home/stuart/ncs-workspace/zephyr/build/merged.hex
    [ #################### ]   3.366s | Erase file - Done erasing
    [ #################### ]   0.639s | Program file - Done programming
    [ #################### ]   0.457s | Verify file - Done verifying
    Applying pin reset.
    -- runners.nrfjprog: Board with serial number 1050715681 flashed successfully.
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$

Reply
  • Kenneth, thanks for the tips. I did try to recompile with nRF Connect SDK, at least I think I did. I also ran the ""nrfjprog --recover" command and there was no change. 

    Below is the complete "from scratch" build process. Can you please do a sanity check on this? Thank you.

    stuart@SRUBIN-H43JDY3:~$ west init -m github.com/.../sdk-nrf.git  ~/ncs-workspace
    === Initializing in /home/stuart/ncs-workspace
    --- Cloning manifest repository from github.com/.../sdk-nrf.git
    Cloning into '/home/stuart/ncs-workspace/.west/manifest-tmp'...
    remote: Enumerating objects: 280378, done.
    remote: Counting objects: 100% (1020/1020), done.
    remote: Compressing objects: 100% (703/703), done.
    remote: Total 280378 (delta 472), reused 608 (delta 283), pack-reused 279358 (from 1)
    Receiving objects: 100% (280378/280378), 164.48 MiB | 60.69 MiB/s, done.
    Resolving deltas: 100% (209490/209490), done.
    --- setting manifest.path to nrf
    === Initialized. Now run "west update" inside /home/stuart/ncs-workspace.
    stuart@SRUBIN-H43JDY3:~$ cd ncs-workspace/
    stuart@SRUBIN-H43JDY3:~/ncs-workspace$ west update
    === updating zephyr (zephyr):
    --- zephyr: initializing
    Initialized empty Git repository in /home/stuart/ncs-workspace/zephyr/.git/
    --- zephyr: fetching, need revision a7fe5f7c4aab18312bd7f61afef55647e38f3db6
    remote: Enumerating objects: 1163241, done.
    remote: Counting objects: 100% (3182/3182), done.
    remote: Compressing objects: 100% (1137/1137), done.
    remote: Total 1163241 (delta 2041), reused 3000 (delta 2008), pack-reused 1160059 (from 1)
    Receiving objects: 100% (1163241/1163241), 622.13 MiB | 33.13 MiB/s, done.
    Resolving deltas: 100% (877727/877727), done.
     * [new branch]              backport-1453-to-v3.4.99-ncs1-branch -> refs/west/backport-1453-to-v3.4.99-ncs1-branch
    <SNIP>
    <SNIP>
    <SNIP>
    <SNIP>
     * [new tag]         old-structure     -> old-structure
    HEAD is now at 47f34dd Update version to 0.9.0
    stuart@SRUBIN-H43JDY3:~/ncs-workspace$
    stuart@SRUBIN-H43JDY3:~/ncs-workspace$ west zephyr-export
    Zephyr (/home/stuart/ncs-workspace/zephyr/share/zephyr-package/cmake)
    has been added to the user package registry in:
    ~/.cmake/packages/Zephyr

    ZephyrUnittest (/home/stuart/ncs-workspace/zephyr/share/zephyrunittest-package/cmake)
    has been added to the user package registry in:
    ~/.cmake/packages/ZephyrUnittest

    stuart@SRUBIN-H43JDY3:~/ncs-workspace$ cd zephyr/
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$ west build --pristine -b nrf7002dk/nrf5340/cpuapp samples/subsys/usb/hid-keyboard
    -- west build: generating a build system
    Loading Zephyr module(s) (Zephyr base): sysbuild_default
    -- Found Python3: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: /home/stuart/.cache/zephyr
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf7002dk, qualifiers: nrf5340/cpuapp
    Parsing /home/stuart/ncs-workspace/zephyr/share/sysbuild/Kconfig
    Loaded configuration '/home/stuart/ncs-workspace/zephyr/build/_sysbuild/empty.conf'
    Merged configuration '/home/stuart/ncs-workspace/zephyr/build/_sysbuild/empty.conf'
    Configuration saved to '/home/stuart/ncs-workspace/zephyr/build/zephyr/.config'
    Kconfig header saved to '/home/stuart/ncs-workspace/zephyr/build/_sysbuild/autoconf.h'
    --
       **********************************
       * Running CMake for hid-keyboard *
       **********************************

    Loading Zephyr default modules (Zephyr base).
    -- Application: /home/stuart/ncs-workspace/zephyr/samples/subsys/usb/hid-keyboard
    -- CMake version: 3.22.1
    -- Found Python3: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: /home/stuart/.cache/zephyr
    -- Zephyr version: 3.7.99 (/home/stuart/ncs-workspace/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf7002dk, qualifiers: nrf5340/cpuapp
    -- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
    -- Found host-tools: zephyr 0.17.0 (/home/stuart/zephyr-sdk-0.17.0)
    -- Found toolchain: zephyr 0.17.0 (/home/stuart/zephyr-sdk-0.17.0)
    -- Found Dtc: /usr/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
    -- Found BOARD.dts: /home/stuart/ncs-workspace/zephyr/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: /home/stuart/ncs-workspace/zephyr/samples/subsys/usb/hid-keyboard/app.overlay
    -- Generated zephyr.dts: /home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/include/generated/zephyr/devicetree_generated.h
    -- Including generated dts.cmake file: /home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/dts.cmake

    warning: Experimental symbol UDC_DRIVER is enabled.


    warning: Experimental symbol USB_DEVICE_STACK_NEXT is enabled.

    Parsing /home/stuart/ncs-workspace/zephyr/samples/subsys/usb/hid-keyboard/Kconfig
    Loaded configuration '/home/stuart/ncs-workspace/zephyr/boards/nordic/nrf7002dk/nrf7002dk_nrf5340_cpuapp_defconfig'
    Merged configuration '/home/stuart/ncs-workspace/zephyr/samples/subsys/usb/hid-keyboard/prj.conf'
    Merged configuration '/home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/.config.sysbuild'
    Configuration saved to '/home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/.config'
    Kconfig header saved to '/home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/include/generated/zephyr/autoconf.h'
    -- Found GnuLd: /home/stuart/zephyr-sdk-0.17.0/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/stuart/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    -- Setting build type to 'MinSizeRel' as none was specified.
    -- Using ccache: /usr/bin/ccache
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/stuart/ncs-workspace/zephyr/build/hid-keyboard
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/stuart/ncs-workspace/zephyr/build
    -- west build: building application
    [5/10] Performing build step for 'hid-keyboard'
    [1/188] Preparing syscall dependency handling

    [6/188] Generating include/generated/zephyr/version.h
    -- Zephyr version: 3.7.99 (/home/stuart/ncs-workspace/zephyr), build: v3.7.99-ncs2-rc1-7-ga7fe5f7c4aab
    [188/188] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       65792 B         1 MB      6.27%
                 RAM:       16256 B       448 KB      3.54%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from /home/stuart/ncs-workspace/zephyr/build/hid-keyboard/zephyr/zephyr.elf for board: nrf7002dk
    [10/10] Generating ../merged.hex
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$ west flash
    -- west flash: rebuilding
    [0/5] Performing build step for 'hid-keyboard'
    ninja: no work to do.
    [4/5] cd /home/stuart/ncs-workspace/zephyr/build/_sysbuild && /usr/bin/cmake -E true
    -- west flash: using runner nrfjprog
    -- runners.nrfjprog: reset after flashing requested
    Using board 1050715681
    -- runners.nrfjprog: Flashing file: /home/stuart/ncs-workspace/zephyr/build/merged.hex
    [ #################### ]   3.726s | Erase file - Done erasing
    [ #################### ]   0.605s | Program file - Done programming
    [ #################### ]   0.458s | Verify file - Done verifying
    Applying pin reset.
    -- runners.nrfjprog: Board with serial number 1050715681 flashed successfully.
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$


    FROM TERMINAL

    *** Booting nRF Connect SDK v2.9.99-b957011b12c4 ***
    *** Using Zephyr OS v3.7.99-a7fe5f7c4aab ***
    [00:00:00.340,576] <inf> main: HID keyboard sample is initialized
    [00:00:35.924,774] <inf> main: USB HID device is not ready
    [00:00:36.201,080] <inf> main: USB HID device is not ready


    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$ nrfjprog --recover
    Recovering device. This operation might take 30s.
    Erasing user code and UICR flash areas.
    Writing image to disable ap protect.
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$ west flash
    -- west flash: rebuilding
    [0/5] Performing build step for 'hid-keyboard'
    ninja: no work to do.
    [4/5] cd /home/stuart/ncs-workspace/zephyr/build/_sysbuild && /usr/bin/cmake -E true
    -- west flash: using runner nrfjprog
    -- runners.nrfjprog: reset after flashing requested
    Using board 1050715681
    -- runners.nrfjprog: Flashing file: /home/stuart/ncs-workspace/zephyr/build/merged.hex
    [ #################### ]   3.366s | Erase file - Done erasing
    [ #################### ]   0.639s | Program file - Done programming
    [ #################### ]   0.457s | Verify file - Done verifying
    Applying pin reset.
    -- runners.nrfjprog: Board with serial number 1050715681 flashed successfully.
    stuart@SRUBIN-H43JDY3:~/ncs-workspace/zephyr$

Children
Related