I am trying to increase the heap memory available to me in my application, for which purpose I got a TWR-MEM.
For places where I want to use a different memory pool (the one from the TWR-MEM) I used the _mem_create_pool() with the External MRAM Base and Size as arguments.
_mem_pool_id _MRAM_pool_id;
void mram_create_pool()
{
_MRAM_pool_id = _mem_create_pool(BSP_EXTERNAL_MRAM_RAM_BASE, BSP_EXTERNAL_MRAM_RAM_SIZE);
if(_MRAM_pool_id == NULL)
{
_task_block();
}
}
I then use the function as shown below for mallocs on the External SRAM
pointer mram_alloc(int mem_size)
{
return _mem_alloc_from(_MRAM_pool_id, mem_size);
}
The code I am using was something I got off the forum. (and thank you to the one who posted this)
The problem I am facing is that everytime I called the mram_alloc I end up with the hard-fault which is triggered by the _lwmem_alloc_internal() funciton in lwm_alli.c.
I feel I am doing something fundamentally wrong here. If anyone has any pointers I would appreciate it.
Thanks
Hi Akshaya,
I started with the mqx/examples/hello project and have attached the modified code.
I use the TWR-MCF52259 and the TWR-K60N612 kits with the TWR-MEM card that has MRAM.
I was able to create a second memory pool in the MRAM. I then write to a block of MRAM and then read it back.
I did have to update the CW10.2 *.mem file to allow the debugger to have access to the MRAM space.
With the MCF52259 I had to also update the MQX to disable the watchdog in the twrmcf52259.h
#define BSP_WATCHDOG_DISABLED 2 //DES was 0...set to 2 to disable core watchdog
Lastly I did slow down the K60 flexbus timing by adding wait states in the init_hw.c of the twrk60n512 folder.
FB_CSCR_WS(6) | //<-- new value
//DES FB_CSCR_WS(2) | <-- old value
Hope this helps.
Regards,
David
Hi David,
The code you shared works fine. My use case however is different. I have got multiple tasks running for one. What I notice is that whether I create my memory pool before the tasks are created or if I create the memory pool for a particular task, the data at that memory pool is blank when control goes to another task.
The moment a memory pool is created there is a linked-list of available memory in that pool that is created along with a tag that indicates that the pool is valid. The moment I move into the say the first task (given that I create the memory pool outside) however the contents of that memory pool are now blank (all zeroes) and so all mallocs then fail as a result since the memory is deemed to be invalid. Any pointers ?
Regards,
Akshaya
Hi Akshaya,
Can you simplify your app and post the file?
Regards,
David
Hi David,
I tried using the code you shared (FYI the IDE I m using is Keil MDK). There doesn't seem to be any problem right until the point wherer the malloced memory is either writted or read. A hard_fault is triggered and program crashes. Any pointers ?
I wanted to know if the MQX_USE_LWMEM_ALLOCATOR macro is set to 0 or 1 in your setup.
Also do any switch settings need to be modified on the TWR-MEM. The only TWR-MEM specific changes I have done till now (in MQX) is to uncomment
#define BSP_EXTERNAL_MRAM_RAM_SIZE ((uint_32)__EXTERNAL_MRAM_RAM_SIZE)
in twrk60n512.h and rebuild my libs.
Also is there any need to do a _mem_extend anywhere to extend the existing memory pool.