Remove malloc

This commit is contained in:
jaseg 2020-12-21 16:47:44 +01:00
parent ddd40092f5
commit 5edb1cebfe
2 changed files with 25 additions and 27 deletions

View file

@ -2,6 +2,10 @@
#include "stm32f0xx_hal.h" #include "stm32f0xx_hal.h"
#include "usbd_def.h" #include "usbd_def.h"
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_hid.h"
#include <stdbool.h>
#include <assert.h>
PCD_HandleTypeDef hpcd_USB_FS; PCD_HandleTypeDef hpcd_USB_FS;
@ -574,3 +578,19 @@ void USBD_LL_Delay(uint32_t Delay /* ms */)
HAL_Delay(Delay); HAL_Delay(Delay);
} }
static USBD_HID_HandleTypeDef *static_hid_handle;
static bool static_hid_handle_allocated = false;
void *USBD_static_malloc(uint32_t size)
{
assert(!static_hid_handle_allocated);
static_hid_handle_allocated = true;
return static_hid_handle;
}
void USBD_static_free(void *p)
{
assert(static_hid_handle_allocated);
static_hid_handle_allocated = false;
}

View file

@ -23,35 +23,10 @@
/* #define for FS and HS identification */ /* #define for FS and HS identification */
#define DEVICE_FS 0 #define DEVICE_FS 0
/** #define USBD_malloc (void *)USBD_static_malloc
* @} #define USBD_free USBD_static_free
*/
/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros
* @brief Aliases.
* @{
*/
/* Memory management macros */
/** Alias for memory allocation. */
#define USBD_malloc malloc
//(uint32_t *)USBD_static_malloc
/** Alias for memory release. */
#define USBD_free free
/** Alias for memory set. */
#define USBD_memset /* Not used */
/** Alias for memory copy. */
#define USBD_memcpy /* Not used */
/** Alias for delay. */
#define USBD_Delay HAL_Delay #define USBD_Delay HAL_Delay
/* DEBUG macros */
#if (USBD_DEBUG_LEVEL > 0) #if (USBD_DEBUG_LEVEL > 0)
#define USBD_UsrLog(...) printf(__VA_ARGS__);\ #define USBD_UsrLog(...) printf(__VA_ARGS__);\
printf("\n"); printf("\n");
@ -76,6 +51,9 @@
#define USBD_DbgLog(...) #define USBD_DbgLog(...)
#endif #endif
void *USBD_static_malloc(uint32_t size);
void USBD_static_free(void *p);
/* Set unset defines */ /* Set unset defines */
#include "usbd_def.h" #include "usbd_def.h"