STM32CubeF1 icon indicating copy to clipboard operation
STM32CubeF1 copied to clipboard

USB keyboard. LED control

Open alekseibutiaev opened this issue 1 year ago • 6 comments

Custom board and with MCU STM32F10[5-7] the function USBH_HID_SetReport does not works correctly.

How To Reproduce

  1. Indicate the global behavior of your application project. works with USB keyboard write led status but does not changed.. but changed after press some keys

  2. The modules that you suspect to be the cause of the problem (Driver, BSP, MW ...). module MW

  3. The use case that generates the problem.

  4. How we can reproduce the problem. write status of led by function USBH_HID_SetReport

Additional context i have solution

butiaev@butiaev-HP-Notebook:~/STM32Cube/STM32CubeF1$ git diff master
diff --git a/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c b/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c
index be9b308..2f7c360 100644
--- a/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c
+++ b/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c
@@ -457,19 +457,17 @@ static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
 #endif
         }
       }
-      else
+      /* IN Endpoint Stalled */
+      else if (USBH_LL_GetURBState(phost, HID_Handle->InPipe) == USBH_URB_STALL)
       {
-        /* IN Endpoint Stalled */
-        if (USBH_LL_GetURBState(phost, HID_Handle->InPipe) == USBH_URB_STALL)
-        {
-          /* Issue Clear Feature on interrupt IN endpoint */
-          if (USBH_ClrFeature(phost, HID_Handle->ep_addr) == USBH_OK)
-          {
+        /* Issue Clear Feature on interrupt IN endpoint */
+        if (USBH_ClrFeature(phost, HID_Handle->ep_addr) == USBH_OK) {
             /* Change state to issue next IN token */
             HID_Handle->state = HID_GET_DATA;
           }
         }
-      }
+      else if(phost->RequestState == CMD_WAIT)
+        USBH_CtlReq(phost, 0, 0);
       break;
 
     default:
butiaev@butiaev-HP-Notebook:~/STM32Cube/STM32CubeF1$

My project is firmfare https://github.com/alekseibutiaev/experience/tree/master/zxkeyboard & hardware https://github.com/alekseibutiaev/electronics/tree/master/ZX_Keyboard

alekseibutiaev avatar May 20 '23 06:05 alekseibutiaev

Hello @alekseibutiaev,

Thank you for this report. We will get back to you as soon as we analyze it further. This may take some time. Thank you for your comprehension.

With regards,

TOUNSTM avatar May 24 '23 10:05 TOUNSTM

Hi @alekseibutiaev,

Thank you for this proposal. May I ask where is defined the CMD_WAIT macro you used in your code snippet above? Thanks.

In the meanwhile, please note that STM32CubeF1 firmware still integrates version 3.3.3 of the USB Host library, while version 3.5.1 has been published here since a couple of months. Would you mind giving it a try a see if the issue still persists?

The newer version is backward compatible and you can easily integrate it into your application manually. Please keep us informed.

With regards,

ALABSTM avatar Jul 12 '23 16:07 ALABSTM

i found it in this file https://github.com/STMicroelectronics/STM32CubeF1/tree/master/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h:378

alekseibutiaev avatar Jul 13 '23 14:07 alekseibutiaev

just only try version 3.5.1 --- same problem, same solution

alekseibutiaev avatar Jul 13 '23 15:07 alekseibutiaev

Hi @alekseibutiaev,

Thank you for your reply. Your report will be forwarded to our development teams for further analysis.

To summarize:

  • The issue you are pointing out is related to the USBH_HID_SetReport() function.
  • However, the fix you are proposing is to be implemented in the USBH_HID_Process() function and more precisely in the lines of code below:

https://github.com/STMicroelectronics/STM32CubeF1/blob/bdec2f6b0658b5725b41c96cb1f066c362acc4d0/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c#L460-L473

  • The fix you are proposing is the following:
-      else
-       {
        /* IN Endpoint Stalled */
-        if (USBH_LL_GetURBState(phost, HID_Handle->InPipe) == USBH_URB_STALL)
+      else if (USBH_LL_GetURBState(phost, HID_Handle->InPipe) == USBH_URB_STALL)
        {
          /* Issue Clear Feature on interrupt IN endpoint */
          if (USBH_ClrFeature(phost, HID_Handle->ep_addr) == USBH_OK)
          {
             /* Change state to issue next IN token */
             HID_Handle->state = HID_GET_DATA;
           }
         }
-      }
+      else if (phost->RequestState == CMD_WAIT)
+      {
+        USBH_CtlReq(phost, 0, 0);
+      }
       break;

With regards,

ALABSTM avatar Aug 02 '23 14:08 ALABSTM

ST Internal Reference: 158663

ALABSTM avatar Aug 02 '23 14:08 ALABSTM