2014-07-15 08:12 AM
I'm trying to understand how this function should be used on an F405 chip. The code that calls calloc is all generated from a simulink fuzzy controller model so I'm confident it's correct in terms of code.
The program seems to be ending up in the default handler as soon as it hits a calloc function. Do I need to sort out a heap for this or something? Not really sure how it works #calloc-stm32f42014-07-15 08:52 AM
Yes, you'd need to address the size of the heap, however your particular tool chain deals with it. RTM
2014-07-15 10:00 AM
I think I got past that issue, I added this into the arm-gcc-link.ld
/* heap section */ .co_heap (NOLOAD): { __cs3_heap_start = . ; . = ALIGN(8); *(.co_heap .co_heap.*) __cs3_heap_end = . ; } > ramThis into startup_stm324fxx.c#define HEAP_SIZE 0x00000200__attribute__ ((section(''.co_heap'')))unsigned long pulHeap[HEAP_SIZE];extern unsigned long __cs3_heap_start;extern unsigned long __cs3_heap_end;and this into my syscalls.c__attribute__ ((used))caddr_t _sbrk (int size){ extern char __cs3_heap_start; extern char __cs3_heap_end ; static char *current_heap_end = &__cs3_heap_start; char *previous_heap_end; previous_heap_end = current_heap_end; if (current_heap_end + size > &__cs3_heap_end ) { errno = ENOMEM; // don't forget to include <errno.h> return (caddr_t) -1; } current_heap_end += size; return (caddr_t) previous_heap_end;}Now my code ends up in the default handler later on when assigning a value to one of the matlab generated structures. Is there a way I can determine how much memory it's all using from within GDB?2014-07-15 10:51 AM
Can you not gauge the size and number of allocations the code might be expecting to use?
512 bytes won't go far if you have a 1024 array of 64-bit doubles You could instrument calloc(), or a proxy, and quantify what's going on. Is the machine generated code not looking for NULL returns from calloc()/malloc() ? You could supply a Hard Fault handler, or other handlers, to more specifically identify the cause of the errors/faults.