Forum: ARM programming with GCC/GNU tools _sbrk error , how to solve for STM32F4 ?

Author: magnetron (Guest)
Posted on:

Rate this post
0 useful
not useful
I am trying to compile a C program for STM32F4 microcontroller
with yagarto

I have run into following error
c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib\libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.18.0/newlib/libc/reent/sbrkr.c:60: undefined reference to `_sbrk'

I have been told to implement this sbrk by myself
however first I decided to ask in the forum if somebody
faced this error before ?

now my question

did anybody face this error before ?
how did you solve it ?
or could you solve it ?


Author: Oliver (Guest)
Posted on:

Rate this post
0 useful
not useful
google finds 33.600 entries for "undefined _sbrk"

No, you are not the first one who did not read the documentation and 
checked for a solution using google...

You should read the newlib documentation, to understand the reason and 
possible solution.

After carefully reading this you might look ath this:


Author: magnetron (Guest)
Posted on:

Rate this post
0 useful
not useful
hello forum,

I tried to copy a syscall.c from the
newlib documents --> http://sourceware.org/newlib/

          caddr_t sbrk(int incr) {
            extern char _end;    /* Defined by the linker */
            static char *heap_end;
            char *prev_heap_end;

            if (heap_end == 0) {
              heap_end = &_end;
            prev_heap_end = heap_end;
            if (heap_end + incr > stack_ptr) {
              write (1, "Heap and stack collision\n", 25);
              abort ();

            heap_end += incr;
            return (caddr_t) prev_heap_end;

my question
what does the micro do when abort() is called ?
does the micro stop running or does the program crash ?

I dont want my micro board fry - its 50.- US$
once my another program crashed and my micro fried indeed


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.