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

  • You're welcome. As a follow up for SES users (don't have Keil)

     // GET_SP() in compiler_abstraction.h; __get_MSP() in cmsis_gcc.h
     NRF_LOG_INFO("nRF52832 SP 0x%08X, MSP 0x%08X, ", GET_SP(), __get_MSP());
    and   
     NRF_LOG_INFO("nRF52832 SP 0x%08X, LR 0x%08X, PC 0x%08X, ", get_sp(), get_lr(), __get_PSP());
    
    assuming:
    static inline uint32_t get_sp(void)
    {
        register uint32_t spRegister __ASM("sp");
        return spRegister;
    }
    
    static inline uint32_t get_lr(void)
    {
        register uint32_t lrRegister __ASM("lr");
        return lrRegister;
    }

    Produces from main.c:

    <info> app: nRF52832 SP 0x2000FFE0, MSP 0x2000FFE0,

    and from a called function in the latter case:

    <info> app: nRF52832 SP 0x2000FFA8, LR 0x00031631, PC 0x00000000,

Related