STM32CubeL0
STM32CubeL0 copied to clipboard
Make maximum number of USB endpoints configurable to reduce memory footprint
The STM32L082 USB peripheral support up to 8 configurable USB endpoints.
However, depending on the application one might only need a few of them.
For example, for a CDC class application, only 3 endpoints are used in
addition to endpoint 0 (bidirectional endpoint):
- CDC IN endpoint (USB IN): USB device (MCU) -> USB host (PC)
- CDC OUT endpoint (USB OUT): USB host (PC) -> USB device (MCU)
- CDC CMD endpoint (USB IN): CDC commands
But, since USB device library is used on various chipsets, it provides
memory structure for up to 16 (!) bidirectional USB endpoints, which is
not even possible on the STM32L082. So all these extra memory structures
are wasted RAM.
This commit makes the allocation of these endpoint memory structure
configurable. Since the USB device library *depends on* the HAL, the HAL
is modified such that a user can define 'HAL_PCD_NUM_ENDPOINTS_IN' and
'HAL_PCD_NUM_ENDPOINTS_OUT' to one's needs in stm32l0xx_hal_conf.h. For
CDC class device one can define these as follows:
#define HAL_PCD_NUM_ENDPOINTS_IN 3U
#define HAL_PCD_NUM_ENDPOINTS_OUT 2U
If those settings need to be propagated through to the ST USB Device
libray, one must define the following object-like macro's in the
application's usbd_conf.h to link the HAL configuration with the USB
device library:
#define USBD_MAX_NUM_ENDPOINT_IN (HAL_PCD_NUM_ENDPOINTS_IN)
#define USBD_MAX_NUM_ENDPOINT_OUT (HAL_PCD_NUM_ENDPOINTS_OUT)
IMPORTANT INFORMATION
Contributor License Agreement (CLA)
- The Pull Request feature will be considered by STMicroelectronics after the signature of a Contributor License Agreement (CLA) by the submitter.
- If you did not sign such agreement, please follow the steps mentioned in the CONTRIBUTING.md file.
Hi @jelledevleeschouwer,
Thank you for your interesting proposal. It will be submitted to our development teams. I will get back to you with their feedback.
With regards,
ST Internal Reference: 123857
Hi @jelledevleeschouwer,
Your proposal has been logged internally. Our development team will further analyze it. I will keep you updated.
With regards,
Hi @jelledevleeschouwer
Unfortunately, our development teams could not reproduce the issue you reported as could be source of overflow.
Effort to protect all access to Ep IN and OUT table is considerable
Hence, they consider there is no issue to fix. Please allow me to close this thread in this case. Thank you for your comprehension.
With regards, Rania