STM32 firmware for a remotely-controlled stepper motor demo with a mobile interface.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
f105-motor-demo_stm32/project/malloc_safe.c

40 lines
734 B

#include "com/debug.h"
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
static void reset_when_done(void)
{
for (uint32_t i = 0; i < 20000; i++) {
if (com_tx_done(debug_iface)) break;
}
NVIC_SystemReset();
}
void *malloc_safe_do(size_t size, const char* file, uint32_t line)
{
void *mem = malloc(size);
if (mem == NULL) {
// malloc failed
error("Malloc failed in file %s on line %"PRIu32, file, line);
reset_when_done();
}
return mem;
}
void *calloc_safe_do(size_t nmemb, size_t size, const char* file, uint32_t line)
{
void *mem = calloc(size, nmemb);
if (mem == NULL) {
// malloc failed
error("Malloc failed in file %s on line %"PRIu32, file, line);
reset_when_done();
}
return mem;
}