Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumeration in FULL SPEED not working #5

Open
st0ne opened this issue Dec 17, 2021 · 22 comments
Open

Enumeration in FULL SPEED not working #5

st0ne opened this issue Dec 17, 2021 · 22 comments

Comments

@st0ne
Copy link

st0ne commented Dec 17, 2021

in usbd_core.c line 178

/* Get Device Configuration Descriptor */
  if (pdev->dev_speed == USBD_SPEED_HIGH)

here is a decision between HIGH SPEED and FULL SPEED but pdev->dev_speed is never set so it will be 0 and used as USBD_SPEED_HIGH. Therefore wrong descriptor settings will be used and enumeration is not working.

Fix could be to set dev_speed with #if (USBD_USE_HS == 1) somewhere before.

@alambe94
Copy link
Owner

The core(hardware) speed is set with USBD_LL_SetSpeed() from PCD reset callback in usbs_conf.c
which is decided by hpcd->Init.speed configured in cube

USBD_Init() set the stack speed in usb_device.c

@st0ne
Copy link
Author

st0ne commented Dec 17, 2021

ok, but where is set dev_speed then? i cannot see it.
If i debug the code it goes stright into highspeed configuration but "speed" for USBD_LL_SetSpeed is set with USBD_SPEED_FULL

if i set pdev->dev_speed manually to FULL SPEED then it works

@alambe94
Copy link
Owner

usb.c or usb_otg.c which automatically generated by cube. In this we have function name MX_USB_XXXXXXX_PCD_Init
in this we set
XXXXXXX.Init.speed = PCD_SPEED_HIGH Or PCD_SPEED_FULL

which will decide pdev->dev_speed USBD_SPEED_HIGH or USBD_SPEED_FULL
in PCD reset callback

@st0ne
Copy link
Author

st0ne commented Dec 17, 2021

void MX_USB_PCD_Init(void)
{

  /* USER CODE BEGIN USB_Init 0 */

  /* USER CODE END USB_Init 0 */

  /* USER CODE BEGIN USB_Init 1 */

  /* USER CODE END USB_Init 1 */
  hpcd_USB_FS.Instance = USB;
  hpcd_USB_FS.Init.dev_endpoints = 8;
  hpcd_USB_FS.Init.speed = PCD_SPEED_FULL;
  hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  hpcd_USB_FS.Init.Sof_enable = ENABLE;
  hpcd_USB_FS.Init.low_power_enable = DISABLE;
  hpcd_USB_FS.Init.lpm_enable = ENABLE;
  hpcd_USB_FS.Init.battery_charging_enable = DISABLE;
  if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USB_Init 2 */

  /* USER CODE END USB_Init 2 */

}

this is how it is set on my cpu. looks good. but for some reason somewhere it switches to highspeed.
i have also the problem that USB Device Tree Viewer in windows shows:

  ========================== Summary =========================

Vendor ID : 0x0483 (STMicroelectronics)
Product ID : 0x52A4
USB Version : 2.00 -> wrong, Device is Full-Speed only
Port maximum Speed : High-Speed
Device maximum Speed : Full-Speed
Device Connection Speed : Full-Speed
Self powered : yes
Demanded Current : 100 mA
Used Endpoints : 7

dont know where to change that and i have problems with audio devices. they are not activated from windows. maybe it has something to do with the version?

@alambe94
Copy link
Owner

put breakpoint in HAL_PCD_ResetCallback()
single step and see what value USBD_LL_SetSpeed() this function gets

@st0ne
Copy link
Author

st0ne commented Dec 17, 2021

ok i found the "version". Its bcdUSB in USBD_DeviceDesc.
I changed it to 0x00, 0x01 and now the Version Error is gone but Audio Enumeration is not working anyways, so this has to be something different

@st0ne
Copy link
Author

st0ne commented Dec 17, 2021

put breakpoint in HAL_PCD_ResetCallback()
single step and see what value USBD_LL_SetSpeed() this function gets

it is definitive USBD_FULL_SPEED

but if i do not set it manually again before

if (USBD_RegisterClass(&hUsbDevice, &USBD_COMPOSITE) != USBD_OK)

then it will be 0 again.

@alambe94
Copy link
Owner

have you enabled only audio or other classes as well
because audio is not working with other classes except HID
I have mentioned this bin doto

@st0ne
Copy link
Author

st0ne commented Dec 17, 2021

aaah, i enabled it with 2 CDC Ports. So why this is not working together?

@alambe94
Copy link
Owner

I don't know
still figuring out. even tried putting cdc in the last

@st0ne
Copy link
Author

st0ne commented Dec 17, 2021

image

This is how it looks in windows. Maybe it is useful to open another issue here for this?

@alambe94
Copy link
Owner

audio plus other class, descriptors captured with wire shark looks good but enumeration fails

@alambe94
Copy link
Owner

image

This is how it looks in windows. Maybe it is useful to open another issue here for this?

yes same issue, I don't know what is going on.
need to try on ubuntu

@st0ne
Copy link
Author

st0ne commented Dec 17, 2021

are there audio controls implemented? mute, volume and so on?

@alambe94
Copy link
Owner

have not tried all features but the microphone implementation says it supports audio control
the speaker only support mute control

@st0ne
Copy link
Author

st0ne commented Dec 18, 2021

in Ubuntu it is detected as 2xACM device and for audio as STM32 Composite SPDIF and STM32 Analog Output
But no microphone is detected...
I will try if audio output is working

@st0ne
Copy link
Author

st0ne commented Dec 18, 2021

its strange. I added code to play back samples on I2S and now only microphone shows up in ubuntu and no speaker anymore...

@alambe94
Copy link
Owner

are you using audacity?

@st0ne
Copy link
Author

st0ne commented Dec 18, 2021

image
directly in sound settings, but i can try audacity

@alambe94
Copy link
Owner

are you able to enumerate in full speed mode?
or you still have to manually in FS mode

@st0ne
Copy link
Author

st0ne commented Dec 18, 2021

i have to set it manually. i have to look through the code where it is reseted

@alambe94
Copy link
Owner

reset function will be called when you plug the USB, then it will set the speed accordingly.
You are saying that after this it is getting reset to high speed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants