<?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>topic _mem_alloc_system failing with LWMEM_POOL_INVALID in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/mem-alloc-system-failing-with-LWMEM-POOL-INVALID/m-p/240375#M6778</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am running MQX on the Vybrid Tower board (target twrvg65gs10_a5) from internal SRAM using IAR as the compiler.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On calling the functions _mem_alloc(size) or _mem_alloc_system(size) NULL is returned and the task error code is set to LWMEM_POOL_INVALID.&lt;/P&gt;&lt;P&gt;I am unsure why this is, as the system pool should surely be valid?&lt;/P&gt;&lt;P&gt;From reading the docs, it appears these are aliased to using lwmem functions instead, so do I need to call _lwmem_set_default_pool() ?&lt;/P&gt;&lt;P&gt;Steps I have taken:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Tried using _lwmem_set_default_pool() beforehand with the pool_id returned by _mem_get_system_pool_id(), this makes no difference.&lt;/LI&gt;&lt;LI&gt;Used _mem_alloc_system instead of _mem_alloc. No difference.&lt;/LI&gt;&lt;LI&gt;Tried to disable LWMEM by setting MQX_USE_LWMEM_ALLOCATOR to 0 in user_config.h and recompiling. No difference.&lt;/LI&gt;&lt;LI&gt;Traced through&amp;nbsp; _bsp_enable_card() in init_bsp.c to see if SRAM was being used. It appears to be as the following line executes in memory setup (line 130), hence I am farily sure user_config.h is set to use internal SRAM, though I am unsure about this:&lt;UL&gt;&lt;LI&gt;_BSP_sram_pool&amp;nbsp; = _mem_get_system_pool_id()&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Traced through mem_alloc(). _lwmem_alloc_internal throws the error as mem_pool_ptr-&amp;gt;VALID != LWMEM_POOL_VALID. But why should the pool be invalid?&lt;/LI&gt;&lt;LI&gt;In kernel_data while tracing through _lwmem_alloc_system, kernel_data.LWMEM_POOLS.SIZE shows as 0 in the debugger, is this normal?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Currently MQX_USED_UNCACHED_MEM is set to 1 (default) and MQX_USE_LWMEM_ALLOCATOR is set to 0.&lt;/P&gt;&lt;P&gt;Apologies if this is in the manual somewhere, but I can't quite see it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Christopher Hemingway added- Trace through mem_alloc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Jun 2013 10:32:31 GMT</pubDate>
    <dc:creator>chrishemingway</dc:creator>
    <dc:date>2013-06-26T10:32:31Z</dc:date>
    <item>
      <title>_mem_alloc_system failing with LWMEM_POOL_INVALID</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/mem-alloc-system-failing-with-LWMEM-POOL-INVALID/m-p/240375#M6778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am running MQX on the Vybrid Tower board (target twrvg65gs10_a5) from internal SRAM using IAR as the compiler.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On calling the functions _mem_alloc(size) or _mem_alloc_system(size) NULL is returned and the task error code is set to LWMEM_POOL_INVALID.&lt;/P&gt;&lt;P&gt;I am unsure why this is, as the system pool should surely be valid?&lt;/P&gt;&lt;P&gt;From reading the docs, it appears these are aliased to using lwmem functions instead, so do I need to call _lwmem_set_default_pool() ?&lt;/P&gt;&lt;P&gt;Steps I have taken:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Tried using _lwmem_set_default_pool() beforehand with the pool_id returned by _mem_get_system_pool_id(), this makes no difference.&lt;/LI&gt;&lt;LI&gt;Used _mem_alloc_system instead of _mem_alloc. No difference.&lt;/LI&gt;&lt;LI&gt;Tried to disable LWMEM by setting MQX_USE_LWMEM_ALLOCATOR to 0 in user_config.h and recompiling. No difference.&lt;/LI&gt;&lt;LI&gt;Traced through&amp;nbsp; _bsp_enable_card() in init_bsp.c to see if SRAM was being used. It appears to be as the following line executes in memory setup (line 130), hence I am farily sure user_config.h is set to use internal SRAM, though I am unsure about this:&lt;UL&gt;&lt;LI&gt;_BSP_sram_pool&amp;nbsp; = _mem_get_system_pool_id()&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Traced through mem_alloc(). _lwmem_alloc_internal throws the error as mem_pool_ptr-&amp;gt;VALID != LWMEM_POOL_VALID. But why should the pool be invalid?&lt;/LI&gt;&lt;LI&gt;In kernel_data while tracing through _lwmem_alloc_system, kernel_data.LWMEM_POOLS.SIZE shows as 0 in the debugger, is this normal?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Currently MQX_USED_UNCACHED_MEM is set to 1 (default) and MQX_USE_LWMEM_ALLOCATOR is set to 0.&lt;/P&gt;&lt;P&gt;Apologies if this is in the manual somewhere, but I can't quite see it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Christopher Hemingway added- Trace through mem_alloc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 10:32:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/mem-alloc-system-failing-with-LWMEM-POOL-INVALID/m-p/240375#M6778</guid>
      <dc:creator>chrishemingway</dc:creator>
      <dc:date>2013-06-26T10:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: _mem_alloc_system failing with LWMEM_POOL_INVALID</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/mem-alloc-system-failing-with-LWMEM-POOL-INVALID/m-p/240376#M6779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fixed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Turns out enabling lightweight memory through:&lt;/P&gt;&lt;P&gt;#define MQX_USE_LWMEM_ALLOCATOR&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;in user_config.h&lt;/P&gt;&lt;P&gt;Was needed so that _lwmem_init_internal() was called correctly.&lt;/P&gt;&lt;P&gt;I previously had LWMEM set to 0, but this appears to have not completely disabled it, and so _mem_init_internal() was being called by MQX at startup instead of _lwmem_init_internal(), although _mem_alloc() was being aliased by MQX to _lwmem_alloc().&lt;/P&gt;&lt;P&gt;Changing the value to 1 and recompiling fixed the errors, and memory now allocates fine.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 13:08:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/mem-alloc-system-failing-with-LWMEM-POOL-INVALID/m-p/240376#M6779</guid>
      <dc:creator>chrishemingway</dc:creator>
      <dc:date>2013-06-26T13:08:36Z</dc:date>
    </item>
  </channel>
</rss>

