[arm-gnu] Cortex-M3 and Floating Point Problems
Mark Mulrooney
mmulrooney at teledyne.com
Thu Jun 21 19:40:09 UTC 2012
I have manually implemented the underlying _sbrk function. I've pasted the code below just in case I've made some silly mistake but as far as I know it seems to be working.
/**
********************************************************************************************************
* @fn _sbrk(int incr)
* @brief Increase program data space. Malloc and similar functions depend on this
* @param incr: The amount of space to grab
* @return Returns the address to the allocated space on success
* @return Returns -1 on failure
********************************************************************************************************
*/
caddr_t _sbrk(int incr)
{
unsigned char *prev_heap;
static unsigned char *heap = NULL;
/* If the heap var is NULL, set it to the start of the heap */
if(heap == NULL)
{
heap = (unsigned char *)&_heap_start;
}
/* Save the current heap location */
prev_heap = heap;
/* Make sure the stack and the heap don't collide */
if((heap + incr) > (unsigned char*) &_sstack)
{
return (caddr_t) -1;
}
/* Increase by the increment amount and return the address */
heap += incr;
return (caddr_t) prev_heap;
}
________________________________________
From: Krzysztof Wesołowski [krzysztof.wesolowski at rainlabs.pl]
Sent: Thursday, June 21, 2012 3:32 PM
To: Carlos O'Donell
Cc: Mark Mulrooney; arm-gnu at codesourcery.com
Subject: Re: [arm-gnu] Cortex-M3 and Floating Point Problems
> * And lastly... the CodeBench printf has a bug.
>
One more possible reason is that AFAIR printf with %f uses malloc for
memory allocation, and often malloc or underlying sbrk are not
prepared (by user) to work on MCUs (in many example projects I have
seen there was no such support and compiler reports undefined
reference, and then, sometimes not functional code is added just to
stop errors ;)).
Regards,
Krzysztof Wesołowski,
More information about the arm-gnu
mailing list