This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with stack variables in functions relocated to RAM at runtime?

Dear All,

I have the following function relocated to RAM and running from RAM:

u32 ReadOTPData(u8 FMI_OTPAddress) {
  u32 OTP_Data = 0x0;

  *(vu16 *)(FMI_BANK_1) = 0x98;                        // issue "read OTP" command
  OTP_Data = (*(vu32*)(FMI_BANK_1 + FMI_OTPAddress)); // read OTP data
  *(vu16 *)(FMI_BANK_1) = 0xFF;                       // issue "read FLASH" command

  return OTP_Data;
}

This function is called from the following code, which runs from FLASH bank 1:

void GetMACfromOTP(void) {
        u32 x[2];
        u8 *p = (u8 *)x;

        tsk_lock();
        x[0] = ReadOTPData(OTP_MAC0_LOCATION);
        x[1] = ReadOTPData(OTP_MAC1_LOCATION);
        tsk_unlock();

        memcpy(own_hw_adr, p, 6);
        return;
}

When I run my program it fails somewhere close to the end of the ReadOTPData() function (the first time it is called) and lands at the PAbtHandler stub. If I change the declaration of OTP_Data to be static (or global), then the program runs as I expect.

One really weird effect, that worries me a lot, is that if I put a breakpoint on the closing brace of ReadOTPData(), then the program runs correctly in all cases, even when OTP_Data is on the stack.

So I am not sure whether this is a silicon issue, a compiler problem, or something else altogether. Anyone seen anything like this before? In case it is relevant, I am using the Realview C++ compiler, and I am runnning this code in an RTL task.

Regards,

Christopher Hicks
==

Parents Reply Children