Author Topic: How to read out the stack (A7) value?  (Read 7458 times)

Offline svl

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
How to read out the stack (A7) value?
« on: July 01, 2011, 01:43:38 PM »
Hi.

I am in progress of making a function that read out the information mention here:http://www.utasker.com/forum/index.php?topic=123.msg468#msg468

The idere are that in case of a "unexpected error" I have the best possible information when trying to locate the error.

My problem is that I have been trying to get the value fron the A7 but with no luck.
Code: [Select]
unsigned long tmp = *((uint32*)0x08F) //Get the value from the A7 register.
   tmp  = *(uint32*)(*(uint32*)A7);    //Get the first byte mention in the above link. This is the data that A7 is pointion to.
   tmp  = *(uint32*)((*(uint32*)A7)+1);
   tmp  = *(uint32*)((*(uint32*)A7)+2);
   tmp  = *(uint32*)((*(uint32*)A7)+3);


Hope you can help me?

Best regards
Steen Larsen

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: How to read out the stack (A7) value?
« Reply #1 on: July 01, 2011, 02:12:22 PM »
Hi Steen

When such an exception occurs the routine called with the be corresponding exception handler.
To locate the value in A7 (without using assembler code) you could try the following:

Code: [Select]
interupt_routine()  // routine with the necessary interrupt attributes definition
{
    unsigned long ulStack;   // put a variable on the stack which will also be used to hold values for later use
    unsigned long *ptrStack = &ulStack; // thsi now points to the location of ulStack, which will be one long word lower on the stack than the A7 when the interruopt entered

    ptrStack++;                // now the value of this pointer is ther same as the original SP (A7) value.

    ulStack = *ptrStack++; // this is now the value that is stored at the bottom of the exception stack
    ulStack = *ptrStack;    // and the value at the second location
}

I didn't actually test this but I would give it a try as a starting point. I am not sure about the line tmp = *((uint32*)0x08F) - I would expect this to read the value stored at address 0x8f in Flash.

Regards

Mark

Offline svl

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: How to read out the stack (A7) value?
« Reply #2 on: July 07, 2011, 01:42:18 PM »
Hi mark
Thnaks for your reply.

Your idere are great, but there must be something wrong. ;-)
I can see that the address in the A7 are changing as I step over the creation of the variabels. And the result in the
Code: [Select]
ulStack are not the same as when i enter the interupt function.

I will try a play araound with it after the sommer, to see if I can find the problem.

Regards Steen