Best Place to add external SRAM in MQX

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Best Place to add external SRAM in MQX

ソリューションへジャンプ
2,295件の閲覧回数
pmt
Contributor V

I am modifying a base BSP (K60F120 tower) for our custom board.  Our board has external SRAM hanging off the flexbus.  What is the proper place to initialize and add this SRAM into the PSP/BSP?

I can guess two options:

     - Linker does not target this external SRAM and it is only used as an MQX memory pool

     - Linker targets external SRAM and it needs to be initialized by the debugger (during debug), or by startup code before C-initialization is called.

For these two situations what are my target files for modification?  Boot.s, init_bsp.c, etc?

Thanks,

PMT

1 解決策
1,253件の閲覧回数
JerryFan
NXP Employee
NXP Employee

The only reqirement about the externl pool is that it must be added before used(malloc, free), so _bsp_card_enable() is a good option.

_mem_extend will add the extenal sram to the kernel default pool, as a free block, at the beginning of the free block list. So all the mem allocation on the kernel pool will select the external sram firstly.

Another option is _mem_create_pool() to create a new pool, then you can select which pool to malloc.

元の投稿で解決策を見る

0 件の賞賛
返信
6 返答(返信)
1,253件の閲覧回数
JerryFan
NXP Employee
NXP Employee

If you use the external SRAM as a MQX memory pool, then the linker has no need to know the infor about the external SRAM.

you can refer _bsp_flexbus_mram_setup in the mqx\source\bsp\twrk60f120m\init_hw.c for detail.

0 件の賞賛
返信
1,253件の閲覧回数
pmt
Contributor V

Thanks,

I modified code to configure the bus and set up the SRAM in '_bsp_flexbus_setup()'. 

Where is the best place to add to the memory pool?  I'm thinking in _bsp_card_enable() before _bsp_low_level_init().  Any suggestions?  Is the memory added with _mem_extend_pool()? 

Also, the pool I'm adding is 16-bit external memory vs the existing 32-bit internal memory.  Do I want the external memory at a higher address so the 32-bit memory is prioritized ahead of the 16-bit memory?

Thanks,

PMT

0 件の賞賛
返信
1,254件の閲覧回数
JerryFan
NXP Employee
NXP Employee

The only reqirement about the externl pool is that it must be added before used(malloc, free), so _bsp_card_enable() is a good option.

_mem_extend will add the extenal sram to the kernel default pool, as a free block, at the beginning of the free block list. So all the mem allocation on the kernel pool will select the external sram firstly.

Another option is _mem_create_pool() to create a new pool, then you can select which pool to malloc.

0 件の賞賛
返信
1,253件の閲覧回数
JerryFan
NXP Employee
NXP Employee

And demo for the _mem_extend and _mem_create_poo:

int32_t test1(void)

{

    pointer test_buf = NULL;

  

    if(MQX_OK != _mem_verify(BSP_EXTERNAL_MRAM_RAM_BASE,

                             (pointer)((uint_32)BSP_EXTERNAL_MRAM_RAM_BASE + BSP_EXTERNAL_MRAM_RAM_SIZE))){

      printf("The external sram failed to be verified.\n");

      return -1;

    }else{

      printf("The external sram verified.\n");

    }

  

   if(MQX_OK != _mem_extend(BSP_EXTERNAL_MRAM_RAM_BASE, (_mem_size)BSP_EXTERNAL_MRAM_RAM_SIZE)){

      printf("Failed to extend the external SRAM.\n");

      r;

    }else{

      printf("Added the external sram to default mem pool.\n");

    }

  

    if(NULL == (test_buf = _mem_alloc(EXTERNAL_SRAM_TEST_BUF_SZ))){

      printf("Failed to alloc buffer in the default pool after it being extended.\n");

      return -1;

    }else{

      printf("Buffer allocated its address is 0x%08x\n", (uint_32)test_buf);

}

 

    /* Access the buf here */

     _task_block();  //block here to easy the checking of the memory pool

    _mem_free(test_buf);

    return 0;

}

int32_t test2(void)

{

    pointer test_buf = NULL;

  

    if(MQX_OK != _mem_verify(BSP_EXTERNAL_MRAM_RAM_BASE,

                             (pointer)((uint_32)BSP_EXTERNAL_MRAM_RAM_BASE + BSP_EXTERNAL_MRAM_RAM_SIZE))){

      printf("The external sram failed to be verified.\n");

      return -1;

    }else{

      printf("The external sram verified.\n");

}

_mem_pool_id ext_sram_pool = NULL;

ext_sram_pool = _mem_create_pool(BSP_EXTERNAL_MRAM_RAM_BASE, (_mem_size)BSP_EXTERNAL_MRAM_RAM_SIZE);

    printf("Created a mem pool on the external sram, and the pool id is 0x%08x.\n", ext_sram_pool);

  

    if(NULL == (test_buf = _mem_alloc_from(ext_sram_pool, EXTERNAL_SRAM_TEST_BUF_SZ))){

      printf("Failed to alloc buffer from the new memory pool.\n");

      return -1;

    }else{

      printf("Buffer allocated and its address is 0x%08x\n", (uint_32)test_buf);

    }

  /* Access the buf here */

     _task_block();  //block here to easy the checking of the memory pool

_mem_free(test_buf);

return 0;

}

1,253件の閲覧回数
pmt
Contributor V

Good stuff.  Thanks Chongbin!

PMT

0 件の賞賛
返信
1,253件の閲覧回数
pmt
Contributor V

Chongbin / All,

I did run into some issues.  My default BSP defines MQX_USE_LWMEM_ALLOCATOR by default.  Some the of documentation in the Users Manual is still kind of light with the LWMEM components, but it looks like the light weight mem does not support "extend"ing non-contiguous memory blocks.  My goals is to have the core services malloc(), free(), etc be able to take from the appended memory block.  So this will not be able to be done with the lightweight mem components. 

So am I best undefining the LWMEM components, and using the standard memory components?  When I do this in the BSP I am running into other issues with unhandled interrupts, perhaps due to the initial tight memory footprint.  Any advice?

PMT

0 件の賞賛
返信