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

Get call stack problem

Hi,master:

   platform:nrf52840

   IDE:keil compiler version 5

  tool chain: armcc

     There are multiple calls to a function in the product. I suspect that there is a problem with this function in some cases. When a condition is met in this function, I add a log. The log information includes who is calling this function at this time. I want to use lr to analyze, but in this environment, I wrote some assembly code and couldn't get lr, because the compilation failed:

static uint32_t lr_val = 0;
void func(void)
{
	asm 
	{
	   LDR  R0, =0x200044d4  //0x200044d4 is the address of lr_val 
       STR  R14, [R0,#0]
	}
	
	if (condition == true)
	{
	    flash_log("lr_val = %d", lr_val);
	}
	
	...
}

Is there any way to achieve who is calling this function when there is a problem?

Thanks

Parents
  • Hi,

    With Keil you can do something like this to get the LR,PC and SP:

    	unsigned int spReg, lrReg, pcReg;
        __asm
        {
            MOV spReg, __current_sp()
            MOV pcReg, __current_pc()
            MOV lrReg, __return_address()
        }
        NRF_LOG_INFO("SP = 0x%X\n",spReg);
        NRF_LOG_INFO("PC = 0x%X\n",pcReg);
        NRF_LOG_INFO("LR = 0x%X\n",lrReg);

    Another approach, is to add a extra context variable in the function call.

    Pseudo code:

    #DEFINE FOO_FUCNTION 0x4242
    
    func(var_1,var2,context)
    {
        NRF_LOG_INFO(func caller: %d,context)
    }
    
    
    foo
    {
         func(1,2,FOO_FUCNTION)
    
    }

  • Hi,

             Thank you very much for sharing. This is the answer I want. In addition, I would like to ask, is there any way to know the calling method of a function through code implementation in software? Similar to keil's call stack.

    Thanks.

  • You can try looking up where the function is located with arm-none-eabi-addr2line, and with the LR value and .axf file as input (.axf is generated when you compile the Keil project)

    arm-none-eabi-addr2line -e nrf52832_xxaa.axf 0x00001A61

    You will then get the name of the .c file and line-number.

    e.g. ..\..\..\..\..\..\components\libraries\queue\/nrf_queue.c:451

Reply
  • You can try looking up where the function is located with arm-none-eabi-addr2line, and with the LR value and .axf file as input (.axf is generated when you compile the Keil project)

    arm-none-eabi-addr2line -e nrf52832_xxaa.axf 0x00001A61

    You will then get the name of the .c file and line-number.

    e.g. ..\..\..\..\..\..\components\libraries\queue\/nrf_queue.c:451

Children
No Data
Related