<?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>S32 SDKのトピックS32DS for PA 2017.R1: failed to malloc() if called from FreeRTOS task context</title>
    <link>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755615#M360</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, NXP guys&lt;/P&gt;&lt;P&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/khumphri"&gt;khumphri&lt;/A&gt;‌&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/Mandar"&gt;Mandar&lt;/A&gt;Deactivated user&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/dhaval"&gt;dhaval&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/RHinnen"&gt;RHinnen&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/jimtrudeau"&gt;jimtrudeau&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/Martin"&gt;Martin&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/vladcentea"&gt;vladcentea&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/marc.paquette"&gt;marc.paquette&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/RChapman"&gt;RChapman&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in S32DS for PA 2017.R1 version, with EAR SDK 0.8.1.&lt;/P&gt;&lt;P&gt;if I create a FreeRTOS task by&amp;nbsp;xTaskCreate()/&lt;SPAN&gt;xTaskCreateStatic(),&lt;/SPAN&gt;, and call malloc() to allocate some memory in the task context, the malloc() return NULL.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;/* example code */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// create task&lt;/P&gt;&lt;P&gt;xTaskCreate(TaskFunc,&amp;nbsp;"Task",&amp;nbsp;1024, NULL,&amp;nbsp;10, NULL);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// task function&lt;/P&gt;&lt;P&gt;void&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;TaskFunc(void *pvParameters)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;void *p =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;malloc(16);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;if (p == NULL)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// malloc failed&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;}&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;for( ;; ) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vTaskDelay(1000); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;after some debugging, I firgured out that this is caused by the sbrk() implementation in S32DS/e200_ewl2/EWL_C/src/stdlib/alloc.c.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sbrk compare the heap pointer with the stack pointer,&amp;nbsp;but in FreeRTOS task, the stack is always located before heap.&lt;/P&gt;&lt;P&gt;I tried below methods:&lt;/P&gt;&lt;P&gt;1. use&amp;nbsp;&lt;SPAN&gt;xTaskCreate to create task, FreeRTOS internally using&amp;nbsp;pvPortMalloc() to allocate the stack.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;pvPortMalloc() allocate the stack memory in&amp;nbsp;ucHeap[] (in bss).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2. use malloc() to allocate task stack and pass into &lt;SPAN&gt;xTaskCreateStatic&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; the stack pointer (in heap) is before the "heap_end" when I called malloc() in task context.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. define stack on bss RAM region, and pass into&amp;nbsp;xTaskCreateStatic&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;bss is located before heap, that is the usual way we link program.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so sbrk failed at this compare and return -1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know FreeRTOS provide another alloc function &lt;SPAN&gt;pvPortMalloc&lt;/SPAN&gt;(),&amp;nbsp;but I have to use malloc() in some cases.&lt;/P&gt;&lt;P&gt;how can I fix it ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="QQ截图20171231012021.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/34070i995F16B671A44B62/image-size/large?v=v2&amp;amp;px=999" role="button" title="QQ截图20171231012021.png" alt="QQ截图20171231012021.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks , and best regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/WX&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 30 Dec 2017 17:37:59 GMT</pubDate>
    <dc:creator>wesleyxie</dc:creator>
    <dc:date>2017-12-30T17:37:59Z</dc:date>
    <item>
      <title>S32DS for PA 2017.R1: failed to malloc() if called from FreeRTOS task context</title>
      <link>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755615#M360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, NXP guys&lt;/P&gt;&lt;P&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/khumphri"&gt;khumphri&lt;/A&gt;‌&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/Mandar"&gt;Mandar&lt;/A&gt;Deactivated user&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/dhaval"&gt;dhaval&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/RHinnen"&gt;RHinnen&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/jimtrudeau"&gt;jimtrudeau&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/Martin"&gt;Martin&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/vladcentea"&gt;vladcentea&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/marc.paquette"&gt;marc.paquette&lt;/A&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/RChapman"&gt;RChapman&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in S32DS for PA 2017.R1 version, with EAR SDK 0.8.1.&lt;/P&gt;&lt;P&gt;if I create a FreeRTOS task by&amp;nbsp;xTaskCreate()/&lt;SPAN&gt;xTaskCreateStatic(),&lt;/SPAN&gt;, and call malloc() to allocate some memory in the task context, the malloc() return NULL.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;/* example code */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// create task&lt;/P&gt;&lt;P&gt;xTaskCreate(TaskFunc,&amp;nbsp;"Task",&amp;nbsp;1024, NULL,&amp;nbsp;10, NULL);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// task function&lt;/P&gt;&lt;P&gt;void&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;TaskFunc(void *pvParameters)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;void *p =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;malloc(16);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;if (p == NULL)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// malloc failed&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;}&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp; &amp;nbsp;for( ;; ) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vTaskDelay(1000); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;after some debugging, I firgured out that this is caused by the sbrk() implementation in S32DS/e200_ewl2/EWL_C/src/stdlib/alloc.c.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sbrk compare the heap pointer with the stack pointer,&amp;nbsp;but in FreeRTOS task, the stack is always located before heap.&lt;/P&gt;&lt;P&gt;I tried below methods:&lt;/P&gt;&lt;P&gt;1. use&amp;nbsp;&lt;SPAN&gt;xTaskCreate to create task, FreeRTOS internally using&amp;nbsp;pvPortMalloc() to allocate the stack.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;pvPortMalloc() allocate the stack memory in&amp;nbsp;ucHeap[] (in bss).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2. use malloc() to allocate task stack and pass into &lt;SPAN&gt;xTaskCreateStatic&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; the stack pointer (in heap) is before the "heap_end" when I called malloc() in task context.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. define stack on bss RAM region, and pass into&amp;nbsp;xTaskCreateStatic&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;bss is located before heap, that is the usual way we link program.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so sbrk failed at this compare and return -1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know FreeRTOS provide another alloc function &lt;SPAN&gt;pvPortMalloc&lt;/SPAN&gt;(),&amp;nbsp;but I have to use malloc() in some cases.&lt;/P&gt;&lt;P&gt;how can I fix it ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="QQ截图20171231012021.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/34070i995F16B671A44B62/image-size/large?v=v2&amp;amp;px=999" role="button" title="QQ截图20171231012021.png" alt="QQ截图20171231012021.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks , and best regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/WX&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Dec 2017 17:37:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755615#M360</guid>
      <dc:creator>wesleyxie</dc:creator>
      <dc:date>2017-12-30T17:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: S32DS for PA 2017.R1: failed to malloc() if called from FreeRTOS task context</title>
      <link>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755616#M361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can enable user heap allocation by setting to 1 this config define in FreeRTOS.h file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#ifndef configAPPLICATION_ALLOCATED_HEAP&lt;BR /&gt; #define configAPPLICATION_ALLOCATED_HEAP 0&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are more details -&amp;nbsp;&lt;A class="link-titled" href="https://www.freertos.org/a00110.html#configAPPLICATION_ALLOCATED_HEAP" title="https://www.freertos.org/a00110.html#configAPPLICATION_ALLOCATED_HEAP"&gt;FreeRTOS - The Free RTOS configuration constants and configuration options - FREE Open Source RTOS for small real time …&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway -&amp;nbsp; usage standard malloc inside FreeRTOS tasks is not good idea - you can find more info here -&amp;nbsp;&lt;A class="link-titled" href="https://www.freertos.org/a00111.html" title="https://www.freertos.org/a00111.html"&gt;FreeRTOS - Memory management options for the FreeRTOS small footprint, professional grade, real time kernel (scheduler)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jiri&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jan 2018 11:28:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755616#M361</guid>
      <dc:creator>jiri_kral</dc:creator>
      <dc:date>2018-01-02T11:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: S32DS for PA 2017.R1: failed to malloc() if called from FreeRTOS task context</title>
      <link>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755617#M362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I find out similar question on Kinetis community -&amp;nbsp;&lt;A href="https://community.nxp.com/thread/358984"&gt;https://community.nxp.com/thread/358984&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jiri&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jan 2018 11:33:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755617#M362</guid>
      <dc:creator>jiri_kral</dc:creator>
      <dc:date>2018-01-02T11:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: S32DS for PA 2017.R1: failed to malloc() if called from FreeRTOS task context</title>
      <link>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755618#M363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Jiri&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks, implement a own sbrk(remove the stack pointer checking) to replace the one in EWL libc fixed my issue.&lt;/P&gt;&lt;P&gt;but does NXP have plan to fix it in Beta SDK version ? anyway it is a bug in EWL lib I think.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/WX&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Jan 2018 13:34:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-SDK/S32DS-for-PA-2017-R1-failed-to-malloc-if-called-from-FreeRTOS/m-p/755618#M363</guid>
      <dc:creator>wesleyxie</dc:creator>
      <dc:date>2018-01-20T13:34:54Z</dc:date>
    </item>
  </channel>
</rss>

