cancel
Showing results for 
Search instead for 
Did you mean: 

usb host

1Ashena M
Associate
Posted on February 26, 2017 at 07:10

Hi Everyone,

I'm trying to read from the USB keyboard with a custom board STM32F205RCT6 MCU.

I am using USB FS host (host only) with HAL library.but it just works with some keyboards!

Other keyboards are detected by host but can not read data.

Can any one help me?

My Code:

int main(void) {  /* STM32F4xx HAL library initialization:  - Configure the Flash prefetch, instruction and Data caches  - Configure the Systick to generate an interrupt each 1 msec  - Set NVIC Group Priority to 4  - Global MSP (MCU Support Package) initialization  */  HAL_Init();    /* Configure the system clock to 120 MHz */  SystemClock_Config();  /* Init Host Library */  USBH_Init(&hUSBHost, USBH_UserProcess, 0);    /* Add Supported Class */  USBH_RegisterClass(&hUSBHost, USBH_HID_CLASS);    /* Start Host Process */  USBH_Start(&hUSBHost);    /* Run Application (Blocking mode) */  while (1)  {  /* USB Host Background task */  USBH_Process(&hUSBHost);     if(USBH_HID_GetDeviceType(&hUSBHost) == HID_KEYBOARD)  {   hid_demo.keyboard_state = HID_KEYBOARD_IDLE;   hid_demo.state = HID_DEMO_KEYBOARD; //HID_KeyboardMenuProcess();  HID_KEYBD_Info_TypeDef *k_pinfo;  char c; k_pinfo = USBH_HID_GetKeybdInfo(&hUSBHost);  if(k_pinfo != NULL) {  c = USBH_HID_GetASCIICode(k_pinfo);  char str[5]; sprintf(str,'%c',c); HAL_UART_Transmit(&huart2,k_pinfo->keys,6,10000);  }  } }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Result (only

detected Not read data

)

USB Device Attached PID: 1h VID: 258ah Address (#1) assigned. Manufacturer : SINO WEALTH Product : USB KEYBOARD Serial Number : N/A Enumeration done. This device has only 1 configuration. Default configuration set. Switching to Interface (#0) Class : 3h SubClass : 1h Protocol : 1h KeyBoard device found! HID class started.�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

#usb-host #usb-hid #usb-stm32f205

Note: this post was migrated and contained many threaded conversations, some content may be missing.
45 REPLIES 45
Posted on May 11, 2018 at 09:10

Some time ago I applied the patch suggested by

pavel_a

and the stack worked fine but I had tried it with mice and keyboards.

Now I need to send report to my custom device but I'm having some problems described in the following new forum question:

https://community.st.com/0D50X00009XkX09SAF

Did you have similar issues?

Posted on May 11, 2018 at 16:31

Hi Luca,

I had to delay my project, sorry, have not tried yet. But in case I return to it, would like to know a solution.

Also would like to hear back from ST - any estimation when fixes to the USB library can be available, even as prevew?

-- pa

Posted on May 14, 2018 at 14:15

Yes, also USB library previews or patchs could be useful for me.

Thanks

Amel NASRI
ST Employee
Posted on May 21, 2018 at 16:00

Hello,

I would like to share with you a patch containing some improvements to deal with some buggy HID devices during enumeration phase. This patch will be deployed in a new version of the USB host library once validated.

If you can test it at your end using your failing devices, this will be helpful for us to validate the patch.

1-

STM32Cube_FW_F4_V1.0\Middlewares\ST\STM32_USB_Host_Library\Class\HID\Src\usbh_hid.c

: replace the implementation of USBH_HID_Process by the following:

static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
{
 USBH_StatusTypeDef status = USBH_OK;
 HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
 
 switch (HID_Handle->state)
 {
 case HID_INIT:
 HID_Handle->Init(phost); 
 case HID_IDLE:
 status = USBH_HID_GetReport (phost, 0x01U, 0U, HID_Handle->pData, (uint8_t)HID_Handle->length);
 if (status == USBH_OK)
 {
 fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length); 
 HID_Handle->state = HID_SYNC;
 }
 else if (status == USBH_BUSY)
 {
 HID_Handle->state = HID_IDLE;
 status = USBH_OK;
 }
 else if (status == USBH_NOT_SUPPORTED)
 {
 HID_Handle->state = HID_SYNC;
 status = USBH_OK;
 }
 else
 {
 HID_Handle->state = HID_ERROR;
 status = USBH_FAIL;
 }
#if (USBH_USE_OS == 1U)
 osMessagePut ( phost->os_event, USBH_URB_EVENT, 0U);
#endif
 break;
 
 case HID_SYNC:
...�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

2-

STM32Cube_FW_F4_V1.0\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_ctlreq.c

: replace the implementation ofUSBH_CtlReq by the following:

USBH_StatusTypeDef USBH_CtlReq (USBH_HandleTypeDef *phost, 
 uint8_t *buff,
 uint16_t length)
{
 USBH_StatusTypeDef status;
 status = USBH_BUSY;
 
 switch (phost->RequestState)
 {
 case CMD_SEND:
 /* Start a SETUP transfer */
 phost->Control.buff = buff; 
 phost->Control.length = length;
 phost->Control.state = CTRL_SETUP; 
 phost->RequestState = CMD_WAIT;
 status = USBH_BUSY;
#if (USBH_USE_OS == 1)
 osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
#endif 
 break;
 
 case CMD_WAIT:
 status = USBH_HandleControl(phost);
 if (status == USBH_OK) 
 {
 /* Commands successfully sent and Response Received */ 
 phost->RequestState = CMD_SEND;
 phost->Control.state =CTRL_IDLE; 
 status = USBH_OK; 
 }
 else if (status == USBH_NOT_SUPPORTED)
 {
 /* Commands successfully sent and Response Received */
 phost->RequestState = CMD_SEND;
 phost->Control.state = CTRL_IDLE;
 status = USBH_NOT_SUPPORTED;
 }
 else
 {
 if (status == USBH_FAIL)
 {
 /* Failure Mode */
 phost->RequestState = CMD_SEND;
 status = USBH_FAIL;
 }
 } 
 break;
 
 default:
 break; 
 }
 return status;
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Waiting for your feedback.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on May 21, 2018 at 18:23

Amel,

With this patch both keyboard and mouse work, my hack no longer  needed.

Thanks!

In USBH_HID_Process() line 9, I'd like to add possibility of error return from the class handler.Init (if the device does not have good report descriptors, or blacklisted, and so on):

 case HID_INIT:

  if (USBH_OK != HID_Handle->Init(phost))

  {

     phost->gState = HOST_ABORT_STATE; 

     break;

   }

(but still we have other unresolved problems with USB host. One is, immediately after unplugging keyboard or mouse, another (fake) attach event is received, and further real attachments are not detected).

- Pavel

Posted on May 22, 2018 at 10:37

Thanks

pavel_a

‌ for your feedback.

(but still we have other unresolved problems with USB host. One is, immediately after unplugging keyboard or mouse, another (fake) attach event is received, and further real attachments are not detected).

Are these problems described in separate discussion may be? If not, please do it in order to be able to follow the case efficiently?

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on May 22, 2018 at 23:05

Dear Amel,

These other issues are probably caused by our hardware (custom board). Sorry for the distraction.

No concrete facts yet.

Regards,

Pavel

Posted on June 15, 2018 at 13:53

Well I am trying to make this library work since march. The report function stop in the enumeration phase even with this last patch applied. Can someone help me?

Thanks

Kallil

Posted on June 15, 2018 at 15:13

Just to understand it better: have you the same problem in this my topic?

Posted on June 15, 2018 at 15:57

It's the same problem as your Typhoon mouse