MQX memory alloc issue

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

MQX memory alloc issue

613 Views
daweiyou
NXP Employee
NXP Employee

Hi:

you know there are two memory management way in mqx, LWMEM or normal MEM,

below code could run correctly on LWMEM, and will fail to alloc memory under MEM(define different function call in small_ram_config.h)

PLS try and suggest.

I debug the code, and could find the issue, issue occurs in step3, while alloc bigger memory after address_at, the previous memory's pointer to next block has not updated;

and I test on MQX4.0.2, 4.1, 4.2, all have this issue.

// _mem_alloc_at will cause a malloc error, this routine will test it

void test_error_alloc_at()

{

    void * tm;

  //int tm;

    volatile unsigned int address_at;

    int test;

    void * test_pointer;

    // get first data, it should be less than 0x2000 0010

    tm = malloc(256);

    printf("step1: %x\r\n", tm);

    // alloc_at the address

    address_at=(unsigned int)tm+256+256;

    test_pointer = _mem_alloc_at(256, (void*)address_at);

    printf("step2: %x, address_at=%x\r\n", test_pointer, address_at);

    // get a large data, it will be got after address_at

    tm = malloc(256);

    printf("step3: %x\r\n", tm);

    // get a small data, it will be got before address_at

    tm = malloc(128);

    printf("step4: %x\r\n", tm);

    // get a large data, it will be failure with MQX_CORRUPT_STORAGE_POOL_FREE_LIST

    tm = malloc(256);

    printf("step5: %x\r\n", tm);  

   

    tm = malloc(0xe000);

    printf("step6: %x\r\n", tm);  

   

        tm = malloc(0x100);

    printf("step7: %x\r\n", tm); 

}

0 Kudos
1 Reply

265 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Dawei

I copied your code in hello world project,  and Enabled MQX_USE_MEM, I didn't see the error.

I tested this code in TWR-K70F120M board.

pastedImage_0.png

Regards

Daniel

0 Kudos