_mem_alloc_system failing with LWMEM_POOL_INVALID

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

_mem_alloc_system failing with LWMEM_POOL_INVALID

Jump to solution
1,359 Views
chrishemingway
Contributor I

Hi

I am running MQX on the Vybrid Tower board (target twrvg65gs10_a5) from internal SRAM using IAR as the compiler.

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.

I am unsure why this is, as the system pool should surely be valid?

From reading the docs, it appears these are aliased to using lwmem functions instead, so do I need to call _lwmem_set_default_pool() ?

Steps I have taken:

  • Tried using _lwmem_set_default_pool() beforehand with the pool_id returned by _mem_get_system_pool_id(), this makes no difference.
  • Used _mem_alloc_system instead of _mem_alloc. No difference.
  • Tried to disable LWMEM by setting MQX_USE_LWMEM_ALLOCATOR to 0 in user_config.h and recompiling. No difference.
  • Traced through  _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:
    • _BSP_sram_pool  = _mem_get_system_pool_id()
  • Traced through mem_alloc(). _lwmem_alloc_internal throws the error as mem_pool_ptr->VALID != LWMEM_POOL_VALID. But why should the pool be invalid?
  • In kernel_data while tracing through _lwmem_alloc_system, kernel_data.LWMEM_POOLS.SIZE shows as 0 in the debugger, is this normal?

Currently MQX_USED_UNCACHED_MEM is set to 1 (default) and MQX_USE_LWMEM_ALLOCATOR is set to 0.

Apologies if this is in the manual somewhere, but I can't quite see it.

Message was edited by: Christopher Hemingway added- Trace through mem_alloc

0 Kudos
Reply
1 Solution
611 Views
chrishemingway
Contributor I

Fixed

Turns out enabling lightweight memory through:

#define MQX_USE_LWMEM_ALLOCATOR  1

in user_config.h

Was needed so that _lwmem_init_internal() was called correctly.

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().

Changing the value to 1 and recompiling fixed the errors, and memory now allocates fine.

View solution in original post

0 Kudos
Reply
1 Reply
612 Views
chrishemingway
Contributor I

Fixed

Turns out enabling lightweight memory through:

#define MQX_USE_LWMEM_ALLOCATOR  1

in user_config.h

Was needed so that _lwmem_init_internal() was called correctly.

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().

Changing the value to 1 and recompiling fixed the errors, and memory now allocates fine.

0 Kudos
Reply