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

initial_sp

Hi!

Regarding the __initial_sp in the map, studied some articles on the web and even map file: used as STACK for arm_startup_nrf52840.o!

Ok, let us have an example (from map file):

_my_array 0x20002814 Data 125 xxxxx.o(.data) __initial_sp 0x20002891 Data 0 arm_startup_nrf52840.o(STACK)

Just some questions:

  1. How the STACK/ __initial_sp will be used by arm_startup_nrf52840 in real time?
  2. What happens if a function in the application, frequently in the real time do memset of _my_array with wrong size, for example 160 bytes (instead of 125)?

This will damage the top of the STACK used by arm_startup_nrf52840.o?

The consequences?

BR Mehrdad

  • Hi Mehrdad,

    there are no safety mechanisms when it comes to stack usage on the nRF5x series, i.e. its the developers responsibility to make sure that the stack does not grow outside its limits. So if you have many nested function calls that push large arrays to the stack then you have to make sure that you dont get a stack overflow. You also have to keep in mind that the SoftDevice and the application shares the call stack, see this Infocenter page for more information.

    Best regards

    Bjørn

  • Hi Björn!

    Right that: "there are no safety mechanisms when it comes to stack usage on the nRF5x series, i.e. its the developers responsibility to make sure that the stack does not grow outside its limits"!

    But my question was:

    What happens if the application by calling the "memset of an array" with wrong size corrupts the STACK header? Consequences?

    BR M

  • That depends if the array is a global variable or if its a local variable. If you call memset with an incorrect size on a global variable then you risk corrupting other global variables. If its a local variable, then you just have to avoid pushing large arrays/variables to the stack recursively. Otherwise, the stack will grow into the global variables.

Related