Failed to allocate memory after integrating algorithm library。

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at https://www.dialog-semiconductor.com/support . We’ll be fixing bugs / optimising the searching and tagging over the coming days.
9 posts / 0 new
Last post
xuguodong
Offline
Last seen: 3 months 4 weeks ago
Joined: 2020-06-04 13:34
Failed to allocate memory after integrating algorithm library。

Hi Dialog,

Failed to allocate memory after integrating algorithm library。

Our algorithm only need total ram 9kBytes(data 1.5k   bss   7.5k).

After setting the following two parameters, the issue still exists: Malloc fail.

  1. Set the configTOTAL_HEAP_SIZE from 11200 to 25*1024.
  2. When OS_TASK_CREATE, set stack from 756  to 1024*22.

I attached my analysis, pls help me check more.

Thanks.

Device: 
PM_Dialog
Offline
Last seen: 2 months 2 weeks ago
Staff
Joined: 2018-02-08 11:03
Hi xuguodong,

Hi xuguodong,

The vApplicationMallocFailedHook() is a hook to the FreeRTOS. This hoot notifies the application when there is not enough continuous heap available for the attempted memory allocation. I would recommend increasing the size of the FreeRTOS heap (configTOTAL_HEAP_SIZE in custom_config_XXXX.h file) to the max number the code compiles.

Thanks, PM_Dialog

xuguodong
Offline
Last seen: 3 months 4 weeks ago
Joined: 2020-06-04 13:34
Hi Dialog,

Hi Dialog,

what is the max size of the FreeRTOS heap (configTOTAL_HEAP_SIZE)?

what is the max size of task stack size ?

Thanks.

PM_Dialog
Offline
Last seen: 2 months 2 weeks ago
Staff
Joined: 2018-02-08 11:03
Hi xuguodong,

Hi xuguodong,

You could use heap size as big as you want. If  the system is running out of RAM, the linker will issue an error. Please refer to https://freertos.org/ for more information on FreeRTOS.

Thanks, PM_Dialog

xuguodong
Offline
Last seen: 3 months 4 weeks ago
Joined: 2020-06-04 13:34
Hi Dialog,

Hi Dialog,

Set  task stack size to >1024*10, error: Failed to allocate memory will occur.

Thanks.

PM_Dialog
Offline
Last seen: 2 months 2 weeks ago
Staff
Joined: 2018-02-08 11:03
Hi xuguodong,

Hi xuguodong,

Can you please attach a screenshot? What is the configTOTAL_HEAP_SIZE that you are using?

Thanks, PM_Dialog

xuguodong
Offline
Last seen: 3 months 4 weeks ago
Joined: 2020-06-04 13:34
As follow, if task stack > 10

As follow, if task stack > 10*1024, memory failed to allocate.

/*************************************************************************************************\
 * Memory specific config
 */
#define dg_configQSPI_CACHED_OPTIMAL_RETRAM_0_SIZE_AE   ( 64 * 1024)
#define dg_configQSPI_CACHED_RAM_SIZE_AE                ( 32 * 1024)
#define dg_configQSPI_CACHED_RETRAM_0_SIZE_AE           ( 96 * 1024)

#define dg_configQSPI_CACHED_RAM_SIZE           ( 56 * 1024)
#define dg_configQSPI_CACHED_RETRAM_0_SIZE      ( 72 * 1024)
#define dg_configQSPI_CODE_SIZE                 ( 256 * 1024)

 

        OS_TASK_CREATE("PXP Reporter",                  /* The text name assigned to the task, for
                                                           debug only; not used by the kernel. */
                       pxp_reporter_task,               /* The function that implements the task. */
                       NULL,                            /* The parameter passed to the task. */
#if (dg_configDISABLE_BACKGROUND_FLASH_OPS == 1)
                       512,                             /* The number of bytes to allocate to the
                                                           stack of the task. */
#else
#if     ZSENS_FUSION_ALGO
                       1024*10,                             /* The number of bytes to allocate to the
                                                           stack of the task. */
#else
                       756,
#endif
#endif

xuguodong
Offline
Last seen: 3 months 4 weeks ago
Joined: 2020-06-04 13:34
/****************************

/*************************************************************************************************\
 * Memory specific config
 */
#define dg_configQSPI_CACHED_OPTIMAL_RETRAM_0_SIZE_AE   ( 64 * 1024)
#define dg_configQSPI_CACHED_RAM_SIZE_AE                ( 32 * 1024)
#define dg_configQSPI_CACHED_RETRAM_0_SIZE_AE           ( 96 * 1024)

#define dg_configQSPI_CACHED_RAM_SIZE           ( 56 * 1024)
#define dg_configQSPI_CACHED_RETRAM_0_SIZE      ( 72 * 1024)
#define dg_configQSPI_CODE_SIZE                 ( 256 * 1024)
/*************************************************************************************************\
 * FreeRTOS specific config
 */
#define OS_FREERTOS                              /* Define this to use FreeRTOS */
#if (dg_configUSE_SOC)
        #if defined(DEBUG_SOC)
                #define configTOTAL_HEAP_SIZE                    12300   /* This is the FreeRTOS Total Heap Size */
        #else
//                #define configTOTAL_HEAP_SIZE                    11200   /* This is the FreeRTOS Total Heap Size */
                #define configTOTAL_HEAP_SIZE                    20*1024   /* This is the FreeRTOS Total Heap Size */
        #endif
#else
        #define configTOTAL_HEAP_SIZE                    11000   /* This is the FreeRTOS Total Heap Size */
#endif

PM_Dialog
Offline
Last seen: 2 months 2 weeks ago
Staff
Joined: 2018-02-08 11:03
Hi xuguodong,

Hi xuguodong,

Does the system still run out of heap?

Thanks, PM_Dialog