cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G491 USB Composite(HID & UAC) problem

yamamo2shun1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
yamamo2shun1
Associate II

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.

View solution in original post

4 REPLIES 4
yamamo2shun1
Associate II

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.

yamamo2shun1
Associate II

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.

yamamo2shun1
Associate II

My project is based on alambe94's I-CUBE-USBD-Composite.

yamamo2shun1
Associate II

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.