1
\$\begingroup\$

I'm trying to drive USB host as MSC and HID on STM32F4, I have one STM32F407 Discovery board and one custom design PCB based on STM32F407.

I'm using Keil compiler and ST std periph library, and for USB using STM32_USB-Host-Device_Lib_V2.1.0 (and V2.2.0). For MSC part after some tries it worked and know I can read and write data on USB flash. But for HID it doesn't work correctly. I've tested many projects on both boards with many HID devices (mouse, kbd, barcode scanner, ...), in all cases the board detects device attachment and its speed, but it doesn't proceed more. Actually it remains in HOST_CTRL_XFER state and doesn't complete the enumeration phase (I found this in debug mode, the MCU works but it loops in some functions).

As the ST document says it's an intermediate stage that should be passed:

ST Doc

But for me it doesn't pass successfully.

Edited:

I think I have problem with descriptor configuration for HID device, I don't know how I can edit the descriptor to pass successfully from enumeration phase.

\$\endgroup\$
6
  • \$\begingroup\$ Have you sniffed the handshake on PC side? The OS driver can halt the device if it doesn't respond accordingly to the OS driver. \$\endgroup\$ Aug 7, 2017 at 7:20
  • 1
    \$\begingroup\$ @MarkoBuršič I don't have PC side, I have a MCU board as USB host for USB flash and HID device. \$\endgroup\$
    – electro
    Aug 7, 2017 at 7:31
  • \$\begingroup\$ I needed to make some modifications to st library to make it work in the file usbh_hid.c for example. Dont know if they are correct, but it works for me at least. Code comes here: switch (HID_Handle->state) <br> { <br> case HID_INIT: <br> HID_Handle->Init(phost); <br> HID_Handle->state = HID_SYNC; /* modification / <br> break; / modification */ <br> case HID_IDLE: <br> \$\endgroup\$
    – MathiasE
    Aug 17, 2017 at 14:18
  • 3
    \$\begingroup\$ I'm voting to close this question as off-topic because it fails to provide code to demonstrate the problem or state the issue with sufficient accuracy for help to meaningfully be provided. Likely your best approach would be to find a fully working HID host example and learn from that - look to things like Discovery board examples, 3rd part examples, etc. \$\endgroup\$ Aug 19, 2017 at 20:33
  • \$\begingroup\$ @staringlizard, Thanks, but I can't understand your code and modifications, my library doesn't have file named "usbh_hid.c". Also my problem is before reaching that stage and it's in enumeration stage. \$\endgroup\$
    – electro
    Aug 28, 2017 at 13:22

1 Answer 1

2
\$\begingroup\$

I'm hopeful that my answer is useful after about 3 years! This is because of your PCB design, not the code. Most of the microcontrollers, same as STM32F407, only have one USB port that can be configured as the Host or Device. But in the evaluation boards, the Discovery board for example, there are both the Host and Device physical ports. These ports share the D+ and the D- pins of the microcontroller. Based on USB standard, in the full-speed device mode, there is a 1.5k pull-up resistor connected to the D+ pin. If you need to use the system in the Host mode, you will be sure that this pull-up resistor is disabled. Each USB device (keyboard, mouse, etc) internally includes this resistor. Using this resistor the Host can detect the type of the connected USB device and the exact plug-in time. After plug-in detection, the host will start the enumeration procedure. Otherwise, the host can not detect the correct moment of device insertion and will run enumeration miss alined. In this situation, the enumeration procedure always reports some sort of errors same as USBH_busy.

You can find more details about USB wiring at the following link: https://www.beyondlogic.org/usbnutshell/usb2.shtml

Regards

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.