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
Parents
  • Hi Divya

    Did you solve it by changing CONFIG_MAIN_STACK_SIZE of hci_rpmsg or some other config?

    As for the malloc() errors, what values are you seeing? Are you able to get any information from the malloc return value?

    Best regards,

    Simon

  • Hi Simon,

    Yes, CONFIG_MAIN_STACK_SIZE of hci_rpmsg was changed.

    The return value of malloc is not NULL. However, trying to access this location provides the following console log:

    [00:00:00.021,179] <err> os: ***** MPU FAULT *****
    [00:00:00.021,209] <err> os:   Data Access Violation
    [00:00:00.021,209] <err> os:   MMFAR Address: 0x2327
    [00:00:00.021,209] <err> os: r0/a1:  0x00000000  r1/a2:  0xe000ed00  r2/a3:  0x2000332c
    [00:00:00.021,209] <err> os: r3/a4:  0x00000001 r12/ip:  0x20077c00 r14/lr:  0x0000248f
    [00:00:00.021,209] <err> os:  xpsr:  0x01000000
    [00:00:00.021,209] <err> os: Faulting instruction address (r15/pc): 0x000004b0
    [00:00:00.021,240] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00:00:00.021,240] <err> os: Current thread: 0x20000a94 (unknown)
    [00:00:00.081,420] <err> fatal_error: Resetting system
    Regards,
    Divya
Reply
  • Hi Simon,

    Yes, CONFIG_MAIN_STACK_SIZE of hci_rpmsg was changed.

    The return value of malloc is not NULL. However, trying to access this location provides the following console log:

    [00:00:00.021,179] <err> os: ***** MPU FAULT *****
    [00:00:00.021,209] <err> os:   Data Access Violation
    [00:00:00.021,209] <err> os:   MMFAR Address: 0x2327
    [00:00:00.021,209] <err> os: r0/a1:  0x00000000  r1/a2:  0xe000ed00  r2/a3:  0x2000332c
    [00:00:00.021,209] <err> os: r3/a4:  0x00000001 r12/ip:  0x20077c00 r14/lr:  0x0000248f
    [00:00:00.021,209] <err> os:  xpsr:  0x01000000
    [00:00:00.021,209] <err> os: Faulting instruction address (r15/pc): 0x000004b0
    [00:00:00.021,240] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00:00:00.021,240] <err> os: Current thread: 0x20000a94 (unknown)
    [00:00:00.081,420] <err> fatal_error: Resetting system
    Regards,
    Divya
Children
  • Hi again Divya

    0x2327 is not a RAM address. It seems like you're trying to write to flash or read from a flash protected area here.
    Best regards,

    Simon
  • 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 

Related