This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430F6734A: IAR C: How to get value of Program Counter that will be returned after ISR

Part Number: MSP430F6734A

Tool/software: TI C/C++ Compiler

Hi,

We are using IAR 7.12 C for one of our project that use MSP430F6734A has 96 KB flash memory.

And IAR C compiler configured for large code model.

For diagnostic purpose, inside the interrupt routine I need to store the address of the code that will be executed after the ISR.

That value (Program Counter just before the ISR) automatically pushed by MSP430 to somewhere before jumping to ISR routine and poped automatically after the ISR routine.

I need that 32 bit value in my C variable, how can I obtain it?

uint32_t PROGRAM_COUNTER_WAS;

void func1(void)
{
	..
}

void func2(void)
{
	..
}

void main(void)
{
	...
	__enable_interrupt();
	
	while(true)
	{
		func1();
		func2();
		..
	}
}

#pragma vector =  PORT1_VECTOR /* 0xFFDE Port 1 */
__interrupt void PORT1_ISR(void)
{
	...
	PROGRAM_COUNTER_WAS = ?? // here I need to store the address of the code that will be executed after the ISR
}

#pragma vector = RTC_VECTOR
__interrupt void RTC_ISR(void)
{
	...	
	PROGRAM_COUNTER_WAS = ?? // here I need to store the address of the code that will be executed after the ISR
}

#pragma vector =  AUX_VECTOR	/* 0xFFE6 AUX Supply */
__interrupt void AUX_ISR(void)
{
	...
	PROGRAM_COUNTER_WAS = ?? // here I need to store the address of the code that will be executed after the ISR
}

  • Hi,

    it is possible to retrieve the value of the PC from the stack pointer using the intrinsic function __get_SP_register(). The 20bit PC is split in 16 bit and 4 bit. The upper most 4 bits are encoded into the SR bits of the SP. Please see chapter 6.2 of the UG.

    There is a caveat to this method. Depending on the interrupt function and how much registers are pushed to the stack there will be an offset when retrieving the PC. That means you need to check, how many registers are saved to the stack every time you change code or change compiler options.

    Please also check this thread: https://e2e.ti.com/search?q=__get_SP_register&category=forum&date=&customdaterange=0&startdate=&enddate=

    Best regards,

    Andre

  • Hi,

    do you have further questions regarding this topic? If not, please select "Resolved" for the post that solved your issue so this thread can be closed out. If you have a different question please select "Ask a related question" or " Ask a new question".
    Thanks a lot!

    Best regards,
    Andre
  • Hi,

    I suppose that you were able to move on with your application as you didn't reply anymore, so I'll close this post.
    Please feel free to comment again if you look for further assistance regarding this topic, it will re-open the thread. If you have a different question, please select "Ask a related question" or " Ask a new question".

    Best regards,
    Andre
  • Hi Andre,

    Sorry for my late reply.

    __get_SP_register() helps to get address of current stack location.

    But each interrupt routine has unique finger print in terms of stack structure when it is jumped depends on how many bytes are pushed by compiler.

    So current stack pointer doesn't help too much unless I check disassembly and manually locate PC value that is stored.

    Also that location can be changed by compiler later, I don't know. More reliable way would be perfect.

    Or

  • Hi,

    unfortunately there is no easy way for it. As described and as you already mentioned it, it depends on your final code and final compiler options.

    Andre

**Attention** This is a public forum