cancel
Showing results for 
Search instead for 
Did you mean: 

WICED Smart Bluetooth

ZhaohuaS_76
Employee

Wiced-Smart-SDK: 2.1.1

I add some code in hello_sensor_timeout for testing cfa_mm_MemFreeBytes and cfa_mm_Alloc,  but I found the return value of cfa_mm_MemFreeBytes can't change after calling cfa_mm_Alloc.

void hello_sensor_timeout(UINT32 arg)
{
   UINT8* tmp; 

    ble_trace1("hello_sensor_timeout:%d\n", hello_sensor_timer_count);


    tmp = cfa_mm_Alloc(32);
    ble_trace3("E: Free bytes = 0x%08X, 0x%08X, 0x%08X\n", cfa_mm_MemFreeBytes(), &tmp, tmp);
 
    switch(arg)
    {
        case BLEPROFILE_GENERIC_APP_TIMER:
        {
            hello_sensor_timer_count++;
        }
        break;
    }
}

0 Likes
1 Solution
JaWa_2142591
New Contributor II

There are few different buffer sizes of the pools which are used for stack, apps and os. They are allocated while system is up. When someone needs buffer, it calls cfa_mm_alloc() to get one from memory management. cfa_mm_Free() is needed to return the buffer after use.

2073x doesn't support heap. Check the link for details.

Undefined reference to standard library functions

View solution in original post

0 Likes
5 Replies
JaWa_2142591
New Contributor II

Let me borrow the picture from JT's article to explain.

In 2073x it allocates some buffers in stack area for stack running (yellow area in the picture).

Calling cfa_mm_Alloc() is to get buffer from pre-allocated buffers in this area.

And calling cfa_mm_MemFreeBytes() in the application is to get remaining available RAM size from user application area (green area in the picture).

pastedImage_0.png

In your test code, you are adding cfa_mm_Alloc() to get buffers in the timer routine without free them. So the pre-defined buffers will get run out and system will crash after some time.

ZhaohuaS_76
Employee

Hi Janusw,

I only use it to test the reture value of cfa_mm_MemFreeBytes() whether is credible.

0 Likes
JaWa_2142591
New Contributor II

Sorry that I would like to clarify what I said about Calling cfa_mm_Alloc() is to get buffer from pre-allocated buffers in yellow area. Actually it should be in the green area, when I checked the patch/app address and the buffer pointer returned from cfa_mm_Alloc(). It's not in the yellow area.


The buffer obtained by calling cfa_mm_Alloc() is to get one from buffer pool which is initialized when memory init. When you call cfa_mm_MemFreeBytes() in application, it's already well allocated. So obtaining buffer won't affect remaining memory size.

0 Likes
ZhaohuaS_76
Employee

Hi Janusw,

What size is the buffer pool for the cfa_mm_Alloc()? Why initialized it when memory init? Mostly malloc memory use the heap, the heap can use the remain all RAM except stack.

0 Likes
JaWa_2142591
New Contributor II

There are few different buffer sizes of the pools which are used for stack, apps and os. They are allocated while system is up. When someone needs buffer, it calls cfa_mm_alloc() to get one from memory management. cfa_mm_Free() is needed to return the buffer after use.

2073x doesn't support heap. Check the link for details.

Undefined reference to standard library functions

View solution in original post

0 Likes