This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to set stack size in NRF5340

Hi,
 
We are writing an application for nrf5340 similar to rpmsg sample with zephyr.
We see that the application encounters stack overflow issue when flashed on target.
We tried to increase the stack using CONFIG_MPSL_SIGNAL_STACK_SIZE in prj.conf to a value as high as 8kB. We also tried increasing CONFIG_MAIN_STACK_SIZE.
However, we were still encountering stack overflow error. However, avoiding a variable of around 400bytes in main() seemed to solve the issue. So, the above setting does not seem to help.
So, can you let me know how can the stack size be altered for app core applications on nrf5340? Also what is the default stack size?
 
Regards,
Divya
  • Hi Simon,

    In the default settings with hci_rpmsg(), CONFIG_MINIMAL_LIBC_MALLOC was enabled but CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE was set to 0. Hence, definition of malloc was to return NULL always. So, i increased CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE to a convinienet value needed. After that, malloc started to return non-NULL address. 
    Following is definition of malloc from malloc.c, if that helps:

    SYS_MEM_POOL_DEFINE(z_malloc_mem_pool, NULL, 16,
                CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE, 1, 4, POOL_SECTION);
     
    void *malloc(size_t size)
    {
        void *ret;
     
        ret = sys_mem_pool_alloc(&z_malloc_mem_pool, size);
        if (ret == NULL) {
            errno = ENOMEM;
        }
     
        return ret;
    }

    Regards,

    Divya 

  • Hi Divya

    What exact value did you set the CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE to be? This size value must be compatible with a sys_mem_pool definition with nmax of 1 and minsz of 16.

    Best regards,

    Simon

  • Hi Simon,

    I tried to set it to a value of 2048 and allocate through malloc() for a size lesser than this.

    nmax of 1 and minsz of 16.

    I sense i might have misinterpreted the config. Say i need a heap of 32kB, what needs to be done?

    Regards,

    Divya

  • Hi Divya

    The minimum size of CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE is 16 while the number of blocks is 1. The configuration for k_malloc seems to be the same. It appears that in order to get a 32kB heap, the CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE must be set to 32kB, assuming that the block can be split in any way. You should also double-check that CONFIG_MINIMAL_LIBC=y;

    Best regards,

    Simon

Related