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
  • Hey Divya, 
    Sorry for the late reply, we're a bit under-staffed during the summer vacations.

    I've forwarded your questions to the developers.

    What stack is overflowing?

    I'm going on vacation for a week, but I'll assign your case to another Tech Supporter.

    BR,

    Håkon Holdhus

  • Hi Håkon Holdhus,

    We were able to figure out this. Changing CONFIG_MAIN_STACK_SIZE and reloading the project helped. 

    However, I am facing malloc() issue. malloc() would return NULL. On setting 

    CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE, malloc() started to return non-NULL values. However, accessing this memory is creating data access violation error on nrf5340. Any help on this will be helpful.
    Regards,
    Divya
  • 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
  • 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
Related