|
本帖最后由 miss-you 于 2021-6-19 00:52 编辑
NUCLEO-H723ZG -> Ux_Host_HID 这个例子中问题1:接无线鼠标会出现枚举不上的BUG,
分析:调试分析后原因锁定在app_usbx_host.c -> ux_host_event_callback这个函数里。调试中发现无线鼠标和键盘是复合设备(我手上不同品牌的一个无线键盘和一个无线鼠标发现都是复合设备, 猜测这类电子产品都是复合的键盘+鼠标设备),这类设备枚举时会
先向主机端发送枚举键盘设备, 之后再枚举鼠标设备。
这个函数中鼠标设备第一次向主机枚举键盘时会枚举成功, hid参数会被赋值,第二次枚举鼠标时会判断 hid是否为空, 此时hid不为空, 所以if中的程序没有得到执行,导致枚举不上无线鼠标。
解决方法: 将hid参数重新定义成数组, 并且在进入这个函数后轮询找到对应hid,(这个方法不适用于一个主机设备接多个鼠标设备,需要靠其他方法实现)。
问题2:无线鼠标能够正常枚举后,先插入鼠标开机或者 先开机,后插入鼠标, 鼠标接入后如果短时间内鼠标没有将第一条位置或按键信息上报,主机设备就一直接受不到消息。
暂时没有发现解决办法,目前一直追踪到了
ux_hcd_stm32_callback.c 下的
void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
这个函数, 发现urb_state 这个参数一直为0, 进一步发现不管有没有按下或移动鼠标调用这个函数的位置都在 stm32H7xx_hal_hcd.c的
static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
{
.......
else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_CHH) == USB_OTG_HCINT_CHH)
{
.......
__HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_CHH);
HAL_HCD_HC_NotifyURBChange_Callback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
}
}
正常按下的时候应该在这个位置。
static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
{
.......
else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_XFRC) == USB_OTG_HCINT_XFRC)
{
.....
else if (hhcd->hc[ch_num].ep_type == EP_TYPE_INTR)
{
.....
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->HC_NotifyURBChangeCallback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
#else
HAL_HCD_HC_NotifyURBChange_Callback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
}
.....
}
希望大家有能力的能够解决这个BUG;
- /**
- * @brief ux_host_event_callback
- * @param ULONG event
- This parameter can be one of the these values:
- 1 : UX_DEVICE_INSERTION
- 2 : UX_DEVICE_REMOVAL
- 3 : UX_HID_CLIENT_INSERTION
- 4 : UX_HID_CLIENT_REMOVAL
- UX_HOST_CLASS * Current_class
- VOID * Current_instance
- * @retval Status
- */
- UINT ux_host_event_callback(ULONG event, UX_HOST_CLASS *Current_class, VOID *Current_instance)
- {
- UINT status;
- UX_HOST_CLASS *hid_class;
- switch (event)
- {
- case UX_DEVICE_INSERTION:
- /* Get current Hid Class */
- status = ux_host_stack_class_get(_ux_system_host_class_hid_name, &hid_class);
- if (status == UX_SUCCESS)
- {
- if ((hid_class == Current_class) && (hid == NULL))
- {
- /* Get current Hid Instance */
- hid = Current_instance;
- /* Get the HID Client */
- hid_client = hid->ux_host_class_hid_client;
- if (hid->ux_host_class_hid_client->ux_host_class_hid_client_status != (ULONG)UX_HOST_CLASS_INSTANCE_LIVE)
- {
- ux_dev_info.Device_Type = Unknown_Device;
- }
- /* Check the HID_client if this is a HID mouse device. */
- if (ux_utility_memory_compare(hid_client->ux_host_class_hid_client_name,
- _ux_system_host_class_hid_client_mouse_name,
- ux_utility_string_length_get(_ux_system_host_class_hid_client_mouse_name)) == UX_SUCCESS)
- {
- /* update HID device Type */
- ux_dev_info.Device_Type = Mouse_Device;
- /* put a message queue to usbx_app_thread_entry */
- tx_queue_send(&ux_app_MsgQueue, &ux_dev_info, TX_NO_WAIT);
- }
- /* Check the HID_client if this is a HID keyboard device. */
- else if (ux_utility_memory_compare(hid_client->ux_host_class_hid_client_name,
- _ux_system_host_class_hid_client_keyboard_name,
- ux_utility_string_length_get(_ux_system_host_class_hid_client_keyboard_name)) == UX_SUCCESS)
- {
- /* update HID device Type */
- ux_dev_info.Device_Type = Keyboard_Device;
- /* put a message queue to usbx_app_thread_entry */
- tx_queue_send(&ux_app_MsgQueue, &ux_dev_info, TX_NO_WAIT);
- }
- else
- {
- ux_dev_info.Device_Type = Unknown_Device;
- ux_dev_info.Dev_state = Device_connected;
- tx_queue_send(&ux_app_MsgQueue, &ux_dev_info, TX_NO_WAIT);
- }
- }
- }
- else
- {
- /* No HID class found */
- USBH_ErrLog("NO HID Class found");
- hid = NULL;
- }
- break;
- case UX_DEVICE_REMOVAL:
- if (Current_instance == hid)
- {
- /* Free Instance */
- hid = NULL;
- USBH_UsrLog("USB Device Unplugged");
- ux_dev_info.Dev_state = No_Device;
- ux_dev_info.Device_Type = Unknown_Device;
- }
- break;
- case UX_HID_CLIENT_INSERTION:
- USBH_UsrLog("HID Client Plugged");
- ux_dev_info.Dev_state = Device_connected;
- break;
- case UX_HID_CLIENT_REMOVAL:
- USBH_UsrLog("HID Client Unplugged");
- ux_dev_info.Dev_state = Device_disconnected;
- ux_dev_info.Device_Type = Unknown_Device;
- tx_queue_send(&ux_app_MsgQueue, &ux_dev_info, TX_NO_WAIT);
- break;
- default:
- break;
- }
- return (UINT)UX_SUCCESS;
- }
复制代码
|
|