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

Used 25% of memory, but the program restarts due to insufficient memory

At the very beginning of the program in the main function, my stack pointer is 0x20026390, although I expected it to be in the 0x20040000 area.

In this case, static memory is used 26% - 35072 bytes.
Those. my static memory should be in the memory area 0x20020000 - 0x20028900, it turns out that I have already crossed the memory boundary by the stack pointer

The question arises, what could this be related to? I did not change the memory configuration in any way, i.e. sram0_ns is used with a size of 128 KB

Kind regards,

Yuri

Parents
  • Using the example \ ncs \ nrf \ samples \ nrf9160 \ at_client.
    I wrote a code that will break if there is enough memory for buffers.

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    
    #include <zephyr.h>
    #include <stdio.h>
    #include <drivers/uart.h>
    #include <string.h>
    
    void test_function();
    
    static uint8_t trash[8000];
    
    /**@brief Recoverable BSD library error. */
    void bsd_recoverable_error_handler(uint32_t err)
    {
    	printk("bsdlib recoverable error: %u\n", err);
    }
    
    void test_function()
    {
    	uint8_t tras2h[40000];
    	for (int i = 0; i < sizeof(tras2h); ++i) {
    		tras2h[i] = i;
    		if (i == sizeof(tras2h) - 1)
    		{
    			__BKPT(0);  // After stopping at this point, you can see that the data in trash [8000] has corrupted
    		}
    	}
    }
    
    void main(void)
    {
    	printk("The AT host sample started %d\n", *trash);
    	test_function();
    }
    

    It turns out that there is no error anywhere, and the problem is that the stack pointer does not point to the end of memory. Unfortunately, I haven't found any settings to fix this.

    Then, as a solution, you will have to use more static variables in the code instead of variables in the stack

Reply
  • Using the example \ ncs \ nrf \ samples \ nrf9160 \ at_client.
    I wrote a code that will break if there is enough memory for buffers.

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    
    #include <zephyr.h>
    #include <stdio.h>
    #include <drivers/uart.h>
    #include <string.h>
    
    void test_function();
    
    static uint8_t trash[8000];
    
    /**@brief Recoverable BSD library error. */
    void bsd_recoverable_error_handler(uint32_t err)
    {
    	printk("bsdlib recoverable error: %u\n", err);
    }
    
    void test_function()
    {
    	uint8_t tras2h[40000];
    	for (int i = 0; i < sizeof(tras2h); ++i) {
    		tras2h[i] = i;
    		if (i == sizeof(tras2h) - 1)
    		{
    			__BKPT(0);  // After stopping at this point, you can see that the data in trash [8000] has corrupted
    		}
    	}
    }
    
    void main(void)
    {
    	printk("The AT host sample started %d\n", *trash);
    	test_function();
    }
    

    It turns out that there is no error anywhere, and the problem is that the stack pointer does not point to the end of memory. Unfortunately, I haven't found any settings to fix this.

    Then, as a solution, you will have to use more static variables in the code instead of variables in the stack

Children
No Data
Related