USB CDC: Move memory allocation from config to cdc
This commit is contained in:
parent
a6869ae8d4
commit
e8219dc09a
|
@ -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 =
|
||||
{
|
||||
|
@ -514,7 +519,13 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
|
|||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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****/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue