grantw

CodeSourcery (lite) C-function printf

Discussion created by grantw on Nov 10, 2011

Saved FAQ from Freescale.com for information only:

Topic: Compiler, Software Development

 

Question.  CodeSourcery (lite) C-function printf does not work properly when newlib is used with floating point numbers for bare board.

 

Answer.  C-function printf uses memory allocation (malloc) especially for floating point numbers. Therefore please double check function _sbrk in syscalls.c. The simplest implementation is provided below.

 

extern char _end; /* Defined by the linker */

 

caddr_t _sbrk(int incr)

{

static char *heap_end = &_end;

char *return_heap_end;

 

if (heap_end == 0) { heap_end = &_end; }

return_heap_end = heap_end;

if (heap_end + incr > stack_ptr())

{_write (1, "Heap and stack collision\n", 25); return((void *) -1); }

heap_end += incr;

return (caddr_t) return_heap_end;

}

 

Also please pay attention on alignment of sections in linker file. An example may be found below.

 

ENTRY(ResetHandler)

 

SECTIONS

{

. = 0x8200000;

.text :

{ *(.vectors);

. = ALIGN(4);

*(.init);

. = ALIGN(4);

*(.text);

. = ALIGN(4);

}

.data : { . = ALIGN(4); *(.data) }

.bss :

{

. = ALIGN(4);

_bss_start = .;

*(.bss)

_bss_end = .;

}

. = ALIGN(4);

_end = .;

 

. = 0x8200000 + 512K ;

.stack :

{

. = ALIGN(4);

STACK_ADR = . ;

}

}

 

Related Products:

 i.MX Applications Processors > i.MX51 Processors > i.MX512, i.MX513, i.MX514, i.MX515, i.MX516

Outcomes