2023-07-05 02:26 PM - edited 2023-07-05 07:27 PM
I have recently developed a USB Compoite (HID Keyborad & Audio Speaker) device using the STM32G491.
I have been able to have it recognized as a Composite Device in the Windows 11 Device Manager, and I have been able to input keys and play PC sound from a codec (Analog Devices ADAU1761) via SAI.
However, there is one problem. I can't get any input from the PC side even if I call USBD_HID_SendReport by pressing a key while the PC is playing sound.
The audio processing is done by calling HAL_SAI_Transmit in AUDIO_PeriodicTC_FS in usbd_audio_if.c as follows.
static int8_t AUDIO_PeriodicTC_FS(uint8_t *pbuf, uint32_t size, uint8_t cmd)
{
/* USER CODE BEGIN 5 */
UNUSED(cmd);
//SEGGER_RTT_printf(0, "size = %d\n", size);
HAL_SAI_Transmit(&hsai_BlockB1, pbuf, size / 2, 0x0000FFFF);
return (USBD_OK);
/* USER CODE END 5 */
}
USBD_HID_SendReport is sent when a keystroke is detected in the while loop in the main function. The source code is available at here.
The Descriptor for the device is as in the attached txt. The version of IDE used is STM32CubeIDE v1.12.1.
Please let me know if you notice anything or have any advice.
Solved! Go to Solution.
2023-07-24 04:15 PM
I gave up on implementing a Composite Device in this way, but by using TinyUSB, I succeeded in implementing a Composite Device for HID and UAC.
Please refer to this repository if you are interested.
2023-07-06 03:12 AM
I found out why the HID is not working when the UAC process is running.
In the USBD_HID_SendReport function, hhid->state was assigned values other than HID_IDLE(0) and HID_BUSY(1). This occurred because pClassData in USBD_HandleTypeDef was not prepared separately for HID and UAC when the code was changed to support Composite.
By fixing the above, keystrokes responded even during UAC processing, but now multiple modifier keys were being hit in succession.
2023-07-07 06:21 PM
I have not yet found the cause and solution.
However, I assume that USB_EPStartXfer is being called from both USBD_LL_Transmit and USBD_LL_PrepareReceive, so that the data copied to PMA is being rewritten unintentionally.
2023-07-07 11:51 PM - edited 2023-07-08 12:04 AM
My project is based on alambe94's I-CUBE-USBD-Composite.
2023-07-24 04:15 PM
I gave up on implementing a Composite Device in this way, but by using TinyUSB, I succeeded in implementing a Composite Device for HID and UAC.
Please refer to this repository if you are interested.