USB CDC: Move memory allocation from config to cdc

This commit is contained in:
Daniel Fekete 2017-05-09 11:25:31 +02:00
parent a6869ae8d4
commit e8219dc09a
5 changed files with 20 additions and 80 deletions

View File

@ -131,6 +131,11 @@ static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length);
static uint32_t staticMemory[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];
static uint8_t staticMemoryUsed = 0;
/* USB Standard Device Descriptor */
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
{
@ -513,9 +518,15 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
USBD_EP_TYPE_INTR,
CDC_CMD_PACKET_SIZE);
pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));
if (staticMemoryUsed == 0) {
pdev->pClassData = &staticMemory;
staticMemoryUsed = 1;
} else {
// On the rare ocasion when you want to use CDC on both FS and HS USB
pdev->pClassData = malloc(sizeof(USBD_CDC_HandleTypeDef));
}
if(pdev->pClassData == NULL)
{
ret = 1;
@ -582,7 +593,13 @@ static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
if(pdev->pClassData != NULL)
{
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
USBD_free(pdev->pClassData);
if (pdev->pClassData != &staticMemory) {
free(pdev->pClassData);
} else {
staticMemoryUsed = 0;
}
pdev->pClassData = NULL;
}

View File

@ -39,7 +39,6 @@
#include "usbd_def.h"
#include "usbd_core.h"
#include "usbd_cdc.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
@ -466,27 +465,6 @@ void USBD_LL_Delay (uint32_t Delay)
HAL_Delay(Delay);
}
/**
* @brief static single allocation.
* @param size: size of allocated memory
* @retval None
*/
void *USBD_static_malloc(uint32_t size)
{
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */
return mem;
}
/**
* @brief Dummy memory free
* @param *p pointer to allocated memory address
* @retval None
*/
void USBD_static_free(void *p)
{
}
/**
* @brief Software Device Connection
* @param hpcd: PCD handle

View File

@ -38,7 +38,6 @@
#include "usbd_def.h"
#include "usbd_core.h"
#include "usbd_cdc.h"
PCD_HandleTypeDef hpcd_USB_OTG_FS;
void Error_Handler(void);
@ -536,22 +535,6 @@ void USBD_LL_Delay (uint32_t Delay)
}
void *USBD_static_malloc(uint32_t size)
{
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */
return mem;
}
/**
* @brief Dummy memory free
* @param *p pointer to allocated memory address
* @retval None
*/
void USBD_static_free(void *p)
{
}
#endif
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -48,7 +48,6 @@
#include "usbd_def.h"
#include "usbd_core.h"
#include "usbd_cdc.h"
PCD_HandleTypeDef hpcd_USB_OTG_FS;
void Error_Handler(void);
@ -768,22 +767,6 @@ void USBD_LL_Delay (uint32_t Delay)
HAL_Delay(Delay);
}
void *USBD_static_malloc(uint32_t size)
{
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */
return mem;
}
/**
* @brief Dummy memory free
* @param *p pointer to allocated memory address
* @retval None
*/
void USBD_static_free(void *p)
{
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#endif

View File

@ -38,7 +38,6 @@
#include "usbd_def.h"
#include "usbd_core.h"
#include "usbd_cdc.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
@ -475,26 +474,6 @@ void USBD_LL_Delay (uint32_t Delay)
HAL_Delay(Delay);
}
/**
* @brief static single allocation.
* @param size: size of allocated memory
* @retval None
*/
void *USBD_static_malloc(uint32_t size)
{
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */
return mem;
}
/**
* @brief Dummy memory free
* @param *p pointer to allocated memory address
* @retval None
*/
void USBD_static_free(void *p)
{
}
/* USER CODE BEGIN 5 */
/**