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

Application stack overflow during SoftDevice execution

Chip: nRF52832

SDK: 15.0.0

SoftDevice: S132 6.0.0

IDE: IAR EWARM 8.30

I have a peripheral-role application with __ICFEDIT_size_cstack__ = 0x800 (application call stack size set to 2048 bytes). What I'm seeing on occasion is very shortly after establishing a connection with a central device, the runtime stack overflows beyond the 0x800 byte bounds and starts overwriting static variables in my application. I have set memory breakpoints which hit when the stack overflows, and I can see my data has corrupted. I also can see the stack pointer register showing a value outside the stack bounds.

When the breakpoint hits, the function call stack in IAR simply says: [__checksum_value + 0xeee7], which from my understanding means that code execution is within the soft device and not within my application. Another intersting thing that I'm seeing when I look at the raw data that is being written to the stack includes values that appear to be RAM addresses within the space allocated to the soft device. For example, I see values such as 0x2000289C and 0x20000918 written repeatedly, and my __ICFEDIT_region_RAM_start__ (APP_RAM_BASE) is set to 0x20004048 meaning that any values between 0x20000000 and 0x20004048 are allocated for the soft device to use. I know that my APP_RAM_BASE is set correctly because if I set it lower then I get an error response to the call to sd_ble_enable in in nrf_sdh_ble_enable.

Am I correct that the soft device is writing data on the application runtime stack? And if so, why would this happen? I have used IAR's stack usage analysis features and know that my max call chain is less than 2048 bytes, so I can't figure out what could be causing this stack overflow.

Thanks.

Related