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

PCD Connect and Disconnect callbacks are not called anywhere in the code #51

Closed
fronders opened this issue Feb 3, 2022 · 4 comments
Closed
Assignees
Labels
hal HAL-LL driver-related issue or pull-request. question Further information is requested usb USB-related (host or device) issue or pull-request

Comments

@fronders
Copy link

fronders commented Feb 3, 2022

Describe the set-up

  • CubeMX v6.4.0 with CubeWB v1.13.1

Describe the bug
Generated code in usbd_conf.c contains HAL_PCD_ConnectCallback() and HAL_PCD_DisconnectCallback():

/**
  * @brief  ConnectCallback callback.
  * @param  hpcd: PCD handle
  * @retval None
  */
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef * hpcd)
{
  USBD_LL_DevConnected(hpcd->pData);
}

/**
  * @brief  Disconnect callback.
  * @param  hpcd: PCD handle
  * @retval None
  */
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef * hpcd)
{
  USBD_LL_DevDisconnected(hpcd->pData);
}

But these callbacks are not called anywhere in stm32wbxx_hal_pcd. This is same independent of selected USB Device Class. However other callbacks like HAL_PCD_ResumeCallback() are called and executed. Is this a bug, or what if the point of these functions then?

@ALABSTM ALABSTM self-assigned this Feb 7, 2022
@ALABSTM ALABSTM added usb USB-related (host or device) issue or pull-request hal HAL-LL driver-related issue or pull-request. labels Apr 12, 2022
@ALABSTM
Copy link
Contributor

ALABSTM commented Apr 12, 2022

Hi @fronders,

Would you mind double-checking this point please? Below code snippets show that both callbacks are defined in stm32wbxx_hal_pcd.c since version 1.13.0 of the STM32CubeWB firmware.

With regards,

hpcd->ConnectCallback = HAL_PCD_ConnectCallback;
hpcd->DisconnectCallback = HAL_PCD_DisconnectCallback;

__weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hpcd);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_PCD_ConnectCallback could be implemented in the user file
*/
}

__weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hpcd);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_PCD_DisconnectCallback could be implemented in the user file
*/
}

@ALABSTM ALABSTM added the needs clarification Needs clarification from user label Apr 12, 2022
@ALABSTM ALABSTM moved this from To do to In progress in stm32cube-mcu-fw-dashboard Apr 12, 2022
@fronders
Copy link
Author

fronders commented Apr 12, 2022

Hello @ALABSTM!

Yes, these functions are assigned to ConnectCallback and DisconnectCallback pointer of hpcd. The problem is that neither the functions HAL_PCD_ConnectCallback() & HAL_PCD_DisconnectCallback() themselves, nor those function pointers you mentioned never get called anywhere from code.

In contrast HAL_PCD_ResumeCallback() and hpcd->ResumeCallback does get executed in HAL_PCD_IRQHandler() as seen below:

#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
hpcd->ResumeCallback(hpcd);
#else
HAL_PCD_ResumeCallback(hpcd);
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */

So my question is still the same - what is the point of these functions then?

Regards

@ALABSTM ALABSTM removed the needs clarification Needs clarification from user label Apr 12, 2022
@ALABSTM
Copy link
Contributor

ALABSTM commented Apr 25, 2022

Hi @fronders,

Actually, both callbacks you pointed out are redefined at application level, as you can see from the code snippet below.

The fact is that, in the case of the STM32WB microcontrollers, the USB peripheral does not support the V-Bus sensing. This requires rather using ADC or GPIO. In both cases, these callbacks could, for instance, be called by the corresponding ADCx_IRQHandler() or EXTIx_IRQHandler() that should be defined in the stm32wbxx_it.c file.

I hope this answers your question.

With regards,

#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
#else
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{
/* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */
/* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */
USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData);
/* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */
/* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */
}
/**
* @brief Disconnect callback.
* @param hpcd: PCD handle
* @retval None
*/
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
#else
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{
/* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */
/* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */
USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData);
/* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */
/* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */
}

@ALABSTM ALABSTM added the question Further information is requested label Apr 25, 2022
@fronders
Copy link
Author

fronders commented Apr 25, 2022

Yeah, I saw they are redefined at application level - that's exactly what my initial post mentions. But still these callbacks never get called anywhere.

The fact is that, in the case of the STM32WB microcontrollers, the USB peripheral does not support the V-Bus sensing. This requires rather using ADC or GPIO. In both cases, these callbacks could, for instance, be called by the corresponding ADCx_IRQHandler() or EXTIx_IRQHandler() that should be defined in the stm32wbxx_it.c file.

Thanks, that is what I was looking for. Would've been nice if it would have been mentioned somewhere in the sources.
Is there a point in generating the callbacks in the application code if they are never used? This is what gets users confused

stm32cube-mcu-fw-dashboard automation moved this from In progress to Done Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hal HAL-LL driver-related issue or pull-request. question Further information is requested usb USB-related (host or device) issue or pull-request
Projects
Development

No branches or pull requests

2 participants