EmbeddedRelated.com
Forums

How to obtain and save the return address inside an interrupt?

Started by "aag...@ieee.org [msp430]" January 18, 2015
I am using MSP430F2618 and the IAR Workbench (version 6.20).

From time to time I get a watchdog reset. I think I can use the watchdog as a timer, then have an interrupt when it times out. Inside the interrupt I would like to find the return address and maybe even save it in flash. If I could do this, I could find out where the problem is.

Would you have suggestions as to how to find out the return address? I know I have to look at the Stack Pointer and may be at some registers to have the full 20 bit return address. But I do not know what exactly I need to look for. ( Unfortunately, I do not know how to program in assembly.)

Thank you for your suggestions.

Beginning Microcontrollers with the MSP430

The simplest way is to make sure that you are using the watchdog in
watchdog mode, not timer mode, then use the RESET_VECTOR to trap the
interrupt. This might be complicated in C, since it involves trapping
the _startup routine at the RESET_VECTOR. By the time this routine has
executed and control is passed to your program the data in the stack, SP
and WDTIFG is no longer valid. Perhaps the best way might be to
configure a breakpoint to trigger when the RESET_VECTOR is accessed. You
can then examine the stack, check the value of SP and check the IFG1
register to see if the reset was triggered by the WDT.

Al

On 18/01/2015 10:42 PM, a...@ieee.org [msp430] wrote:
> I am using MSP430F2618 and the IAR Workbench (version 6.20).
> From time to time I get a watchdog reset. I think I can use the
> watchdog as a timer, then have an interrupt when it times out. Inside
> the interrupt I would like to find the return address and maybe even
> save it in flash. If I could do this, I could find out where the
> problem is.
> Would you have suggestions as to how to find out the return address? I
> know I have to look at the Stack Pointer and may be at some registers
> to have the full 20 bit return address. But I do not know what exactly
> I need to look for. ( Unfortunately, I do not know how to program in
> assembly.)
> Thank you for your suggestions.
Another way to do this (examine the stack, check the value of SP and check ... ) in IAR -- you should do:
- menu: Project->Options->Debugger-> uncheck box
- hit Download and Debug
- in the Disassembly window set a breakpoint on the green line (under __program_start symbol)
- hit Go and set the conditions for reset
- the debugger will stop the MSP at the very first instruction after reset and you can then examine whatever you consider to help you
Hope this helps
Hi
as far as I know the return address is pushed into stack. So if you pop it and save in a register or memory you have done ! Don't forget to push it again!!!!.
Ciao
Mauro
To: m...
From: m...
Date: Sun, 18 Jan 2015 04:12:19 -0800
Subject: [msp430] How to obtain and save the return address inside an interrupt?

I am using MSP430F2618 and the IAR Workbench (version 6.20).

From time to time I get a watchdog reset. I think I can use the watchdog as a timer, then have an interrupt when it times out. Inside the interrupt I would like to find the return address and maybe even save it in flash. If I could do this, I could find out where the problem is.

Would you have suggestions as to how to find out the return address? I know I have to look at the Stack Pointer and may be at some registers to have the full 20 bit return address. But I do not know what exactly I need to look for. ( Unfortunately, I do not know how to program in assembly.)

Thank you for your suggestions.
"Mauro Zanin m...@hotmail.com [msp430]" :

> Hi
> as far as I know the return address is pushed into stack. So if you pop
> it and save in a register or memory you have done ! Don't forget to push
> it again!!!!.
Well, but it is not esy to do this in C. But it should be simple to add a
small assembly routine just for the watchdog interrupt (using some examples).
I do not know IAR Workbench, I am using Crossworks. In similar cases I put a
breakpoint at the reset vector and then examine the "execution trace" and the
"call stack" windows. Execution trace is a feature of the MSP430-EEM, maybe
IAR also implemented this.

M.


Posted by: Matthias Weingart




Thank you for all the suggestions.

I have tried the suggestions of using a break point at the reset vector. Unfortunately, the problem has not occurred while using the debugger.

When my device is off the debugger and running on its own, then I do get a watchdog reset from time to time.

What I want to try next is to use the watchdog in timer mode, create an interrupt and inside the interrupt save the Stack Pointer. Once I understand how to read the stack, I can use the IAR intrinsic function:

__get_SP_register() to get the Stack Pointer and then I will save it in flash.

I will report back if I make this work.

Thank you.
What do you think your strategy will achieve? You are getting a Watchdog
failure occasionally, or you assume that you are. You are not getting a
timer issue, and the function of the WDT is totally different in timer
mode to watchdog mode, so you will only trap this if you are using
watchdog mode. What makes you think this is a WDT failure? I presume
that you are examining the WDTIFG flag in IFG1 at power on, rather than
just making an assumption.

In Practice the only way I think you are going to be able to do this is
to intercept the RESET_VECTOR, which means changing the start up
function your compiler produces, literally at the first instruction, so
you should add either as breakpoint here or a loop in place to indicate
the fail and preserve the critical data.

Al
On 21/01/2015 12:50 PM, a...@ieee.org [msp430] wrote:
> Thank you for all the suggestions.
>
> I have tried the suggestions of using a break point at the reset
> vector. Unfortunately, the problem has not occurred while using the
> debugger.
>
> When my device is off the debugger and running on its own, then I do
> get a watchdog reset from time to time.
>
> What I want to try next is to use the watchdog in timer mode, create
> an interrupt and inside the interrupt save the Stack Pointer. Once I
> understand how to read the stack, I can use the IAR intrinsic function:
>
> __get_SP_register() to get the Stack Pointer and then I will save it
> in flash.
>
> I will report back if I make this work.
>
> Thank you.
>