Skip to content

Commit

Permalink
chore(usb): avoid USBD_free and USBD_malloc usage
Browse files Browse the repository at this point in the history
to avoid call of malloc in PCD_EP_ISR_Handler.

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed May 31, 2023
1 parent a27e4a1 commit a84e919
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cores/arduino/stm32/usb/cdc/usbd_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
* @{
*/

/* Prevent dynamic allocation */
USBD_CDC_HandleTypeDef _hcdc;

/* CDC interface class callbacks structure */
USBD_ClassTypeDef USBD_CDC = {
Expand Down Expand Up @@ -476,7 +478,8 @@ static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
UNUSED(cfgidx);
USBD_CDC_HandleTypeDef *hcdc;

hcdc = (USBD_CDC_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
// hcdc = (USBD_CDC_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
hcdc = &_hcdc;

if (hcdc == NULL) {
pdev->pClassDataCmsit[pdev->classId] = NULL;
Expand Down Expand Up @@ -592,7 +595,8 @@ static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
/* DeInit physical Interface components */
if (pdev->pClassDataCmsit[pdev->classId] != NULL) {
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
/* No need to free as hhid is no more dynamically allocated */
// (void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
pdev->pClassDataCmsit[pdev->classId] = NULL;
pdev->pClassData = NULL;
}
Expand Down
9 changes: 7 additions & 2 deletions cores/arduino/stm32/usb/hid/usbd_hid_composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
* @{
*/

/* Prevent dynamic allocation */
USBD_HID_HandleTypeDef _hhid;

USBD_ClassTypeDef USBD_COMPOSITE_HID = {
USBD_HID_Init,
USBD_HID_DeInit,
Expand Down Expand Up @@ -523,7 +526,8 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev,

USBD_HID_HandleTypeDef *hhid;

hhid = (USBD_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_HID_HandleTypeDef));
// hhid = (USBD_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_HID_HandleTypeDef));
hhid = &_hhid;

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

/* Free allocated memory */
if (pdev->pClassDataCmsit[pdev->classId] != NULL) {
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
/* No need to free as hhid is no more dynamically allocated */
// (void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
pdev->pClassDataCmsit[pdev->classId] = NULL;
}

Expand Down

0 comments on commit a84e919

Please sign in to comment.