<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>i.MX Processors中的主题 CodeSourcery (lite) C-function printf</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/CodeSourcery-lite-C-function-printf/m-p/185585#M8658</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Saved FAQ from Freescale.com for information only:&lt;/P&gt;&lt;P&gt;Topic: Compiler, Software Development&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question.&amp;nbsp; CodeSourcery (lite) C-function printf does not work properly when newlib is used with floating point numbers for bare board.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Answer.&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;extern char _end; /* Defined by the linker */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;caddr_t _sbrk(int incr)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;static char *heap_end = &amp;amp;_end;&lt;/P&gt;&lt;P&gt;char *return_heap_end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (heap_end == 0) { heap_end = &amp;amp;_end; }&lt;/P&gt;&lt;P&gt;return_heap_end = heap_end;&lt;/P&gt;&lt;P&gt;if (heap_end + incr &amp;gt; stack_ptr())&lt;/P&gt;&lt;P&gt;{_write (1, "Heap and stack collision\n", 25); return((void *) -1); }&lt;/P&gt;&lt;P&gt;heap_end += incr;&lt;/P&gt;&lt;P&gt;return (caddr_t) return_heap_end;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also please pay attention on alignment of sections in linker file. An example may be found below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ENTRY(ResetHandler)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SECTIONS&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;. = 0x8200000;&lt;/P&gt;&lt;P&gt;.text :&lt;/P&gt;&lt;P&gt;{ *(.vectors);&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;*(.init);&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;*(.text);&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;.data : { . = ALIGN(4); *(.data) }&lt;/P&gt;&lt;P&gt;.bss :&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;_bss_start = .;&lt;/P&gt;&lt;P&gt;*(.bss)&lt;/P&gt;&lt;P&gt;_bss_end = .;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;_end = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;. = 0x8200000 + 512K ;&lt;/P&gt;&lt;P&gt;.stack :&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;STACK_ADR = . ;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Related Products:&lt;/P&gt;&lt;P&gt;&amp;nbsp;i.MX Applications Processors &amp;gt; i.MX51 Processors &amp;gt; i.MX512, i.MX513, i.MX514, i.MX515, i.MX516&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Nov 2011 20:40:20 GMT</pubDate>
    <dc:creator>admin</dc:creator>
    <dc:date>2011-11-10T20:40:20Z</dc:date>
    <item>
      <title>CodeSourcery (lite) C-function printf</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/CodeSourcery-lite-C-function-printf/m-p/185585#M8658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Saved FAQ from Freescale.com for information only:&lt;/P&gt;&lt;P&gt;Topic: Compiler, Software Development&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question.&amp;nbsp; CodeSourcery (lite) C-function printf does not work properly when newlib is used with floating point numbers for bare board.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Answer.&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;extern char _end; /* Defined by the linker */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;caddr_t _sbrk(int incr)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;static char *heap_end = &amp;amp;_end;&lt;/P&gt;&lt;P&gt;char *return_heap_end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (heap_end == 0) { heap_end = &amp;amp;_end; }&lt;/P&gt;&lt;P&gt;return_heap_end = heap_end;&lt;/P&gt;&lt;P&gt;if (heap_end + incr &amp;gt; stack_ptr())&lt;/P&gt;&lt;P&gt;{_write (1, "Heap and stack collision\n", 25); return((void *) -1); }&lt;/P&gt;&lt;P&gt;heap_end += incr;&lt;/P&gt;&lt;P&gt;return (caddr_t) return_heap_end;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also please pay attention on alignment of sections in linker file. An example may be found below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ENTRY(ResetHandler)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SECTIONS&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;. = 0x8200000;&lt;/P&gt;&lt;P&gt;.text :&lt;/P&gt;&lt;P&gt;{ *(.vectors);&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;*(.init);&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;*(.text);&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;.data : { . = ALIGN(4); *(.data) }&lt;/P&gt;&lt;P&gt;.bss :&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;_bss_start = .;&lt;/P&gt;&lt;P&gt;*(.bss)&lt;/P&gt;&lt;P&gt;_bss_end = .;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;_end = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;. = 0x8200000 + 512K ;&lt;/P&gt;&lt;P&gt;.stack :&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;. = ALIGN(4);&lt;/P&gt;&lt;P&gt;STACK_ADR = . ;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Related Products:&lt;/P&gt;&lt;P&gt;&amp;nbsp;i.MX Applications Processors &amp;gt; i.MX51 Processors &amp;gt; i.MX512, i.MX513, i.MX514, i.MX515, i.MX516&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 20:40:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/CodeSourcery-lite-C-function-printf/m-p/185585#M8658</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2011-11-10T20:40:20Z</dc:date>
    </item>
  </channel>
</rss>

