Skip to content

Commit a84e919

Browse files
committed
chore(usb): avoid USBD_free and USBD_malloc usage
to avoid call of malloc in PCD_EP_ISR_Handler. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent a27e4a1 commit a84e919

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

cores/arduino/stm32/usb/cdc/usbd_cdc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
133133
* @{
134134
*/
135135

136+
/* Prevent dynamic allocation */
137+
USBD_CDC_HandleTypeDef _hcdc;
136138

137139
/* CDC interface class callbacks structure */
138140
USBD_ClassTypeDef USBD_CDC = {
@@ -476,7 +478,8 @@ static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
476478
UNUSED(cfgidx);
477479
USBD_CDC_HandleTypeDef *hcdc;
478480

479-
hcdc = (USBD_CDC_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
481+
// hcdc = (USBD_CDC_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
482+
hcdc = &_hcdc;
480483

481484
if (hcdc == NULL) {
482485
pdev->pClassDataCmsit[pdev->classId] = NULL;
@@ -592,7 +595,8 @@ static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
592595
/* DeInit physical Interface components */
593596
if (pdev->pClassDataCmsit[pdev->classId] != NULL) {
594597
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
595-
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
598+
/* No need to free as hhid is no more dynamically allocated */
599+
// (void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
596600
pdev->pClassDataCmsit[pdev->classId] = NULL;
597601
pdev->pClassData = NULL;
598602
}

cores/arduino/stm32/usb/hid/usbd_hid_composite.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
105105
* @{
106106
*/
107107

108+
/* Prevent dynamic allocation */
109+
USBD_HID_HandleTypeDef _hhid;
110+
108111
USBD_ClassTypeDef USBD_COMPOSITE_HID = {
109112
USBD_HID_Init,
110113
USBD_HID_DeInit,
@@ -523,7 +526,8 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev,
523526

524527
USBD_HID_HandleTypeDef *hhid;
525528

526-
hhid = (USBD_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_HID_HandleTypeDef));
529+
// hhid = (USBD_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_HID_HandleTypeDef));
530+
hhid = &_hhid;
527531

528532
if (hhid == NULL) {
529533
pdev->pClassDataCmsit[pdev->classId] = NULL;
@@ -589,7 +593,8 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
589593

590594
/* Free allocated memory */
591595
if (pdev->pClassDataCmsit[pdev->classId] != NULL) {
592-
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
596+
/* No need to free as hhid is no more dynamically allocated */
597+
// (void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
593598
pdev->pClassDataCmsit[pdev->classId] = NULL;
594599
}
595600

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy