STMicroelectronics / STM32CubeG0

STM32Cube MCU Full Package for the STM32G0 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
165 stars 75 forks source link

HAL: Include content of stm32g0xx_hal_hcd.h only if USB peripheral available. #13

Closed str4t0m closed 3 years ago

str4t0m commented 3 years ago

Describe the bug The content of stm32g0xx_hal_hcd.h should be only included for devices where the USB peripheral is available.

How To Reproduce

  1. In my project I have HAL_HCD_MODULE_ENABLED in stm32g0xx_hal_conf.h
  2. Compile the project with a device that does not support USB(e.g. stm32g071xx).
  3. stm32g0xx_hal_hcd.h depends on defines in stm32g0XXxx.h that are only available if the device has an USB peripheral( e.g.: USB_DRD_TypeDef, USB_DRD_CfgTypeDef ...), resulting in an compile error.

Expectation File content is included only if the peripheral USB_DRD_FS is defined:

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32g0xx_ll_usb.h"

#if defined (USB_DRD_FS)

... The rest of the code  ...

#endif /* defined (USB_DRD_FS) */

#ifdef __cplusplus
}
#endif

Additional context I am currently trying to update the HAL for STM32G0 Series for Zephyr to Version 1.4.0. In Zephyr all HAL_PERIPHERALXX_ENABLED are defined in stm32g0xx_hal_conf.h, therefore all devices from the STM32G0 Series missing the USB peripheral can't compile when this include guard is missing.

ALABSTM commented 3 years ago

Hi @str4t0m,

Thank you for your contribution. Indeed, USB DRD-related definitions and declarations should be surrounded by pre-processor directives #if defined (USB_DRD_FS) and #endif. The directives should be added at lines 31 and 490 respectively (shown below).

The issue will be logged into our internal database. A fix will be made available in the frame of a future release.

With regards,

https://github.com/STMicroelectronics/STM32CubeG0/blob/c6cb8664ae0542c33f81046d735ee9492d5df0f3/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_hcd.h#L28-L32

https://github.com/STMicroelectronics/STM32CubeG0/blob/c6cb8664ae0542c33f81046d735ee9492d5df0f3/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_hcd.h#L489-L492

ALABSTM commented 3 years ago

ST Internal Reference: 99814